still getting strange behaviour. this is my test program. at the beginning, one OINK gets printed. if i push that button again. nothing happens. if i press the other button, OI gets printed once. then soon after it keeps printing. plz help!
//declare constants
#define BUTTON1 8
#define BUTTON2 12
#define POWER 7
#define LED 10
//declare variables
int LEDState = 0;
int LEDBrightness = 63;
int buttonState1 = LOW;
int buttonState2 = LOW;
int buttonValue1 = 0;
int buttonValue2 = 0;
void setup(){
//set pins
pinMode(BUTTON1, INPUT);
pinMode(BUTTON2, INPUT);
pinMode(LED, OUTPUT);
digitalWrite(POWER, HIGH);
Serial.begin(9600);
}
void loop(){
//read button pins
buttonValue1 = digitalRead(BUTTON1);
buttonValue2 = digitalRead(BUTTON2);
//handle button1 behaviour - turn LED off and on
if((buttonValue1 == HIGH) && (buttonState1 != buttonValue1)){
Serial.println("OINK");
if(LEDState == 0){
analogWrite(LED, LEDBrightness);
LEDState = 1;
}
if(LEDState == 1){
analogWrite(LED, 0);
LEDState = 0;
}
delay(20);
}
//handle button2 behaviour - increase brightness of LED
if((buttonValue2 == HIGH) && (buttonState2 != buttonValue2)){
Serial.println("OI!");
LEDBrightness += 63;
if (LEDBrightness > 255)
LEDBrightness = 63;
analogWrite(LED, LEDBrightness);
delay(20);
}
buttonState1 = buttonValue1;
buttonState2 = buttonValue2;
}