Something really crazy is going on with my Arduino.
I have two computers: one is a laptop (running Vista SP1), the other a desktop (running Win7Pro SP1). I also have an Arduino Leonardo.
When I connect the Leonardo to the desktop and upload the following code, the code performs as it should: when the button is held down, the LED is lit; otherwise the LED is dark.
However, when I connect the Leonardo to the laptop, and load the exact same code, the LED remains lit constantly.
Both computers are running the same Arduino Software (Version 1.0.5-r2). Within the Arduino Software, the same Programmer (AVR ISP) is selected in both computers. In both computers, the Leonardo has the same driver (1.0.0.0 with a date of Jan 4 2013).
Here are the troubleshooting steps/scenarios I have tested:
Connecting the Leonardo to a different USB port on the laptop and reloading the code does not change the outcome. When the code is loaded, the LED remains lit.
If I connect the Leonardo to the desktop and upload the code, then disconnect the Leonardo and connect to the laptop, the code performs correctly.
If I connect the Leonardo to the laptop and upload the code, then disconnect the Leonardo and connect to the desktop, the code doesn't perform correctly (the LED remains lit).
While the obvious workaround is to load the code via the desktop and then plug the Leonardo into the laptop, it makes me wonder what other inconsistencies could arise with more complex Arduino code.
Does anyone have any suggestions as to what is going on, and how to fix the problem?
int Button1 = 5;
int GreenLED = 2;
void setup()
{
pinMode(GreenLED, OUTPUT);
pinMode(Button1, INPUT_PULLUP);
}
void loop()
{
if(digitalRead(Button1) == LOW)
{
digitalWrite(GreenLED, HIGH);
}
if(digitalRead(Button1) == HIGH)
{
digitalWrite(GreenLED, LOW);
}
}