LoginSignup
0
0

obnizでタクトスイッチ制御メモ

Last updated at Posted at 2023-10-14

Node.jsから制御してます。

抵抗なしでプルアップ

obnizのプルアップ機能を使います。

const Obniz = require('obniz');
const obniz = new Obniz('1234-5678'); //Obniz_ID

obniz.onconnect = async () => {
    obniz.io0.pull("5v"); //IO0をプルアップ
    obniz.io1.output(false); //IO1をGNDに
    
    obniz.io0.input(function(value){
        console.log("changed to " + value);
    });
}

抵抗入れるパターン

const Obniz = require('obniz');
const obniz = new Obniz('1234-5678'); //Obniz_ID
    
obniz.onconnect = async () => {
    obniz.io0.output('5v');
    obniz.io1.output(false);

    obniz.io2.input(function(value){
        console.log("changed to " + value);
        obniz.display.clear();
        obniz.display.print(value);
    });
}

プルアップダウン抵抗入れたパターン

const Obniz = require('obniz');
const obniz = new Obniz('1234-5678'); //Obniz_ID
    
obniz.onconnect = async () => {
    obniz.io0.output('5v');
    obniz.io1.output(false);
    
    obniz.io2.input(function(value){
        console.log("changed to " + value);
        obniz.display.clear();
        obniz.display.print(value);
    });
}

参考

  • タクトスイッチ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0