Total Pageviews

Tuesday, 29 March 2011


The Arduino board switch that i conducted and programmed from my computer to the components used then processing through the circuit board and the period through the LED light. I have used the switch where u press and hold the switch in order to keep the LED remaining on.
#define LED 13 //the pin for the LED
#define BUTTON 7 //the input pin where the pushbutton is connected
int val = 0; //val will be used to store the state of the input pin
int old_val = 0; //this variable stores the previous value of "val"
int state = 0; //0 = LED off while 1 = LED on

void setup () {
pinMode (LED, OUTPUT); //tell Arduino LED is an object
pinMode (BUTTON, INPUT); //and BUTTON is an input
}

void loop() {
val = digitalRead(BUTTON); //read input value and store it

//check whether the input is HIGH (button pressed)
//and change the state
if (val == HIGH) {
  state = 1 - state;
}

if (state == 1) {
digitalWrite(LED, HIGH); //turn LED ON
} else {
digitalWrite(LED, LOW);
}
}

No comments:

Post a Comment