Demos
Demo: Push Button
Every second, the program will check if the user has pressed the push button. If the push button is pressed, it will turn the LED on.Code
var b = require('bonescript'); b.pinMode('P8_19', b.INPUT); b.pinMode('P8_13', b.OUTPUT); setInterval(check,100); function check(){ b.digitalRead('P8_19', checkButton); } function checkButton(x) { if(x.value == 1){ b.digitalWrite('P8_13', b.HIGH); } else{ b.digitalWrite('P8_13', b.LOW); } }
Build and execute instructions
- Connect the cathode side of the LED with a 470 ohm resistor in series, then to ground.
- Connect the anode side of the LED to 'P8_13.'
- Connect one side of the push-button to P'9_3' and the other to 'P8_19.'
- Run the example code. If the push button is pressed, it will turn the LED on.
See also
Topics
Related functions
Last updated by cortezjuanjr on Tue Jul 23 2013 13:37:29 GMT-0500 (CDT).