Hi there, I am new to Arduino and would like to tap some advice from you good folks more knowledgeable than me. I have been trying to get this to work for about a week of evenings now.
The purpose is to control and LED from a push button switch. The LED is going to light up a big Tabasco bottle I am setting into nice piece of cedar.
The light needs to have three functions: on, breath, off.
Here the code so far:
int counter = 0;
int brightness = 255;
int switchPin = 2;
int ledPin = 11;
void setup()
{
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
//Handle input
int switchVal = digitalRead(switchPin);
if(switchVal == HIGH)
{
delay(20);
counter ++;
//Reset count if over max mode number
if(counter == 4)
{
counter = 0;
}
}
else
//Change mode
switch (counter) {
case 1:
{
float val = (exp(sin(millis()/4000.0*PI)) - 0.36787944)*108.0;
analogWrite(ledPin, val);
}
case 2:
analogWrite(ledPin, brightness);
break;
case 3:
analogWrite(ledPin, LOW);
break;
}
}
Attached is a poor picture of it operating. It turns on, off, but the breath function does not work. Apologies and thank you ahead of time as I am new to this and programming.
Any help would be awesome.
Render
Moderator edit: Code tags