-
1Step 1
Node.js Application
Add the following code to server.js:
server.js
... var button = gpio.init("S11A"); var wasButtonPressed = false; button.setDirection('input'); setInterval(function(){ // If button is just released... if(button.getValue() === 1 && wasButtonPressed === true){ wasButtonPressed = false; // ...reads the LED state... var ledState = led.getValue(); //...inverses it... if(ledState === 1){ ledState = 0 }else{ ledState = 1; } //...writes... led.setValue(ledState); //...and submits to the web app if connected if(clients !== undefined){ clients.emit('tps:state:changed', ledState); } }else if(button.getValue() === 0){ // If button is pressed wasButtonPressed = true; } },100); ...
To lean more clik here
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.