Beagle Board - beagleboard.org

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

Where to buy

See it in action


Last updated by jessica.lynne.callaway on Thu Dec 19 2013 22:12:17 GMT-0000 (UTC).
21544