hay guy's my name's Hector and i live in NSW,AUS
im new to arduino(as of yesterday) and have just started playing around with my breedborad and a hd44780 lcd and makeing a IR repeter:) was stoked coz if never touched any programeing or PIC's before and had it down in like 2 hours ,,,,
but here's the prob,im tryin to make a LED turn on for 1500ms then turn off with the press of a button witch i can do but i with to add a nother button to do the same thing IE
/*
- test 2 button's //pulldowned via G/r
*/
int switchPin1 = 2;
int switchPin2 = 3; // switch is connected to pin 2
int led1Pin = 13;
int val; // variable for reading the pin status
int val2; // variable for reading the delayed/debounced status
int buttonState1; // variable to hold the button state
int buttonState2;
int lightMode = 0; // Is the light on or off?
void setup() {
pinMode(switchPin1, INPUT); // Set the switch pin as input
pinMode(switchPin2, INPUT);
pinMode(led1Pin, OUTPUT);
Serial.begin(9600); // Set up serial communication at 9600bps
buttonState1 = digitalRead(switchPin1); // read the initial state
buttonState2 = digitalRead(switchPin2);
}
void loop(){
val = digitalRead(switchPin1); // read input value and store it in val
delay(10); // 10 milliseconds is a good amount of time
val2 = digitalRead(switchPin1); // read the input again to check for bounces
if (val == val2) { // make sure we got 2 consistant readings!
if (val != buttonState1) { // the button state has changed!
if (val == LOW) { // check if the button is pressed
if (lightMode == 0) { // is the light off?
lightMode = 1; // turn light on!
digitalWrite(led1Pin, HIGH);
delay(1500);
digitalWrite(led1Pin, LOW);
delay(100);
} else {
lightMode = 0; // turn light off!
// No need to do anything because the light is 'off' when it finishes with mode 1
val = digitalRead(switchPin2); // read input value and store it in val
delay(10); // 10 milliseconds is a good amount of time
val2 = digitalRead(switchPin2); // read the input again to check for bounces
if (val == val2) { // make sure we got 2 consistant readings!
if (val != buttonState2) { // the button state has changed!
if (val == LOW) { // check if the button is pressed
if (lightMode == 0) { // is the light off?
lightMode = 1; // turn light on!
digitalWrite(led1Pin, HIGH);
delay(1500);
digitalWrite(led1Pin, LOW);
delay(100);
} else {
lightMode = 0; // turn light off!
// No need to do anything because the light is 'off' when it finishes with mode 1
}
}
}
buttonState1 = val; // save the new state in our variable
buttonState2 = val;
}
}
}
}
}
}
but thats dose not work
not sure why maybe some one can help?????