hello, im very very new to arduino so please be patient.
i just learned for loops so i thought of coding an led that brightens and dims by itself, im able to make it upto the max brightness but cant seem to get it down. i think this will be more achievable with a while loop but i want to see what a for loop can do. heres the code:
int j;
int wait=500;
int mypin=9;
int bright=255;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(mypin,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
for(j=1;j<=bright;j=j+1){
analogWrite(mypin,j);
delay(wait);
}
for(j=bright;j>=0;j=j-1){
analogWrite(mypin,j);
delay(wait);
}
}
changing wait to 50 is working thanks a lot. is it dependent on the fact that for 1/255 units, half a second is wayy too long? and the resistor is 330 ohms. thanks again!!