Dmitry Slepov
Published

Two-way Control with Web and Button

This is the simplest application enabling the control of a GPIO line through a hardware button control.

BeginnerProtip12 minutes920
Two-way Control with Web and Button

Things used in this project

Hardware components

Size 3 Linux Tibbo Project PCB (LTPP3)
Tibbo Technology Size 3 Linux Tibbo Project PCB (LTPP3)
×1
Tibbo Technology TBP3 enclosure
×1
Tibbo Technology Tibbit #10 (power supply)
×1
Tibbo Technology Tibbit #18 (power jack)
×1
Tibbo Technology Tibbit #00-3 (2 direct I/O lines with 5V and ground)*
×1
Tibbo Technology Tibbit #39_2 (large red LED)*
×1
Tibbo Technology Tibbit #38 (push button)
×1

Story

Read more

Schematics

Proposed Tibbit Configuration

Code

Code snippet #1

C/C++
...  
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);  
... 

Credits

Dmitry Slepov
7 projects • 3 followers
Managing Director
Contact

Comments

Please log in or sign up to comment.