EDIT:
All I know for sure is that LED on pin 13 should be off (LOW) when the Arduino is powered up and
should then turn on (HIGH) when the button is pressed.
I have access to an Arduino UNO and I loaded this code in to it as written and LED 13 was lit all the time:
int pressed = 0;
void setup(){
pinMode(8, INPUT);
pinMode(13, OUTPUT);
}
void loop(){
pressed = digitalRead(8);
if (pressed){
digitalWrite(13, LOW);
}
else{
digitalWrite(13, HIGH);
}
}
There is problem I see, pin 8 should change states (go from HIGH to LOW when
the button is pressed), but I don't see on either of the schematics a 10k resistor directly from pin 8 to + (positive)?
The 10k resistor would pull pin 8 HIGH, then when the button is pressed, it would go to ground (LOW).
So I added the 10k resistor and it works OK.
Without the 10k, pin 8 just "floats" while the button connection is open and the ARDUINO doesn't
see any state (except an open pin).
Just my thoughts
propmaster2000
EDIT:
I had a chance to test this code as well:
#define button 8 //button is wired to this pin; see the pinoout
#define cree 9 //and this goes to the LED
int pressed = 0;
int bright = 255;
void setup()
{
pinMode(button, INPUT);
pinMode(button,INPUT_PULLUP);
analogWrite(cree, 0);
}
void loop()
{
pressed = digitalRead(button);
if(pressed == LOW)
{
bright = 255;
analogWrite(cree, bright);
delay(1000); ///this arbitrary delay keeps the LED at full power for a moment
for (bright = 255; bright > 0; bright --)
{
analogWrite(cree, bright);
delayMicroseconds(50); // this value changes how quick the fade is
}
pressed = HIGH;
}
}
and an LED on pin 9 is off when the ARDUINO is powered up.
When I push the button (momentarily), the LED lites for about a second then shuts off.
There does not seem to be any FADE effect.
EDIT again:
See my next posting
.