I have been playing with my Arduino for about a year now - and was having lots of fun and pretty good success. I had to stop for a few months, and now... the most BASIC sketch won't work.
This is supposed to be a BASIC 'LED follows the switch' routine - really simple.
LED is pin 13
Button is 'normally open' pin 7
Press the button and the LED goes off
Release the button and the LED goes off
Sketch compiles fine
The serial output shows the state of the switch in the Serial Monitor
But the LED just stays on - never goes off. What am I missing?
int BGLEDPin = 9; //Background LED driver circuit pin 9
int EyeLEDPin = 8; //Eye LED assigned to pin 8
int BtnPin = 7; //Button assigned to pin 7
int BtnState = 13; //Onboard LED
int varBtnPress; //Will be used to capture button state
int varBtnCnt = 0; //Button press counter (initialized to 0)
int EyeDelay; //A variable to establish the speed of eye fade
void setup() {
// Set up serial port
Serial.begin(9600);
// Set up pins
pinMode(BGLEDPin,OUTPUT); //Assigned pin for background set to output mode
pinMode(EyeLEDPin, OUTPUT); //Assigned pin for eye set to output
pinMode(BtnPin,INPUT_PULLUP); //Assigned pin for button set to input
pinMode(BtnState,OUTPUT); //Onboard LED
}
void loop() {
// put your main code here, to run repeatedly:
//Read the button state
varBtnPress = digitalRead(BtnPin);
Serial.println(varBtnPress);
if (varBtnPress = 1) {
digitalWrite (BtnState, HIGH); //Turn on the onboard LED
} else {
digitalWrite (BtnState, LOW); //Turn off the onboard LED
}
delay(500);
}