I am so happy because this is the first semi-complex project that I did all on my own! Hope you like it!
OK, what this does is fade the led on, wait half a second, fade the led on, wait half a sceond, restart, ect....
You turn the potentiometer to vary the fading speed. This is just another part in my upcoming project. I am also trying to improve this code, and I will replace it, or post it in a reply.
int ledPin = 11; // LED connected to digital pin 11
int potPin = 0;
int val;
void setup() {
}
void loop() {
{
val = analogRead(potPin);
val = map(val, 0, 1023, 1, 5);
}
delay(500);
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=val) {
analogWrite(ledPin, fadeValue);
delay(5);
}
delay(500);
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=val) {
analogWrite(ledPin, fadeValue);
delay(5);
}
}
For smoother fading you could make the potentiometer control the delay time while keeping the increment at 1 unit. N.B., I've reversed the map function so that this should (i think) work just like your version: