constint buttonPin = 2; // the number of the pushbutton pin
constint pause = 1000; // Set Delay time
// variables will change:
int buttonState = 0; // Variable for reading the pushbutton status
int ledPin = random(10); // Sets a Random LED as active
void setup() {
pinMode(ledPin, OUTPUT); // Initialize the LED pin as an output:
pinMode(buttonPin, INPUT); // Initialize the pushbutton pin as an input:
}
void loop(){
buttonState = digitalRead(buttonPin); // read the state of the pushbutton value:
if (buttonState == HIGH) { // check if the pushbutton is pressed.if it is, the buttonState is HIGH:
digitalWrite(ledPin, HIGH); // turn LED on:
}
else {
digitalWrite(ledPin, LOW); // turn LED off:
}
}
I asked in the Arduino forums but thought I would ask here too encase ^^