int switchPin = 7;
int ledPin = 9;
int ledIntensity = 0;
int ledFade = 5;
boolean buttonState = false;
boolean currentButton = 0;
boolean lastButton = 0;
unsigned long currentMillis;
void setup() {
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
ledFade startMillis();
}
boolean debounce(boolean last)
{
boolean current = digitalRead(switchPin);
if (last != current)
{
delay (5);
current = digitalRead(switchPin);
}
return current;
}
void loop() {
currentButton = debounce(lastButton);
if (switchPin == true && buttonState == false) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
{
analogWrite(ledPin, ledIntensity);
}
ledIntensity = ledIntensity + ledFade;
if (ledIntensity == 0 || ledIntensity == 255)
{
ledFade = -ledFade;
}
delay(30);
if (switchPin == true && buttonState == true) {
digitalWrite(ledPin, LOW);
}
else {
digitalWrite(ledPin, HIGH);
}
return 0;
}
}
I'm not sure if I am any closer, at work at the moment. I would like to sit in front of my computer at home to actually test this. Again, I will change the delays, and sort some things around later this evening. Thank you for going through the trouble.