I am very new to Arduino but I am learning all the time. (at this point, 4 days)
I took a look at the already put together programs in the programming environment,
then chose the one with Pulse Width Modulation for fading an LED. (it is in OPEN, BASICS, FADE.)
I wanted to make it my own so I made an adjustment where in the for() loop, the test/condition is determined by the analog input of a potentiometer .
my code looks like this :
const int ledPin = 9; // LED connected to digital pin 9-
const int pot = A0;
void setup() {
pinMode( ledPin,OUTPUT);
pinMode (pot,INPUT);
Serial.begin(9600);
}
void loop() {
int value = analogRead(pot);
// fade in from min to max in increments of 5 points:
for(int fadeValue = 0 ; fadeValue <= value; fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
// fade out from max to min in increments of 5 points:
for(int fadeValue = value ; fadeValue >= 0; fadeValue -= 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
Serial.println(value);
delay(1000);
}
It works, to a degree..
The problems are that the serial port will not print anything. The communications and also, instead of fading on and off, it goes something like this :
fade from 0 to high 3 times one right after another , then fade from high to 0 three times, and repeat,
instead of fading from off to on and back again.
here are some pictures of wiring.
I will keep working, If you can find whats wrong or give advice, THANK YOU.