Hi you all,
I would like to ask a question about Arduiono code that I wrote for the following task: "When the first LED brighten to full and stay at full, while the second LED brightness to full, while both are full, fade first one down to dark, and then the second LED."
This looks very simple to do, but unfortunately, it doesn't work for me... I've attached a code to this post, I think the code is make sense to me and I don't know, why it doesn't work...
Code is compiling and was upload to the board, but only LED1 lighted up and then lighted down, at first and that is it...
Besides, Serial monitor shows some weird signs, instead of integers as I expected, so this is also a problem...
I will really appreciate your hel, guys!
Btw, I'm also using ESP8266 for this code here.
int LED1 = 2; // LED GPIO Pin
int LED2 = 4; // LED GPIO Pin
int brightness1 = 0; // Brightness of the LED 1
int brightness2 = 0; // Brightness of the LED 2
int brightnessChange = 10; // Amount that the brightness will change
void setup() {
pinMode(LED1,OUTPUT); // set the LED pin to be an output
pinMode(LED2,OUTPUT); // set the LED pin to be an output
}
void loop() {
// set the value of the LED pin, which will set the LED brightness
analogWrite(LED1,brightness1);
analogWrite(LED2,brightness2);
Serial.println(brightness1);
// change the brightness for the next time through the loop
while (brightness1 < 1023){
brightness1=brightness1 + brightnessChange;
}
Serial.println(brightness1);
Serial.println(brightness2);
while(brightness1 >= brightness2){
brightness2=brightness2+brightnessChange;
}
if (brightness1 <= brightness2){
while (brightness1 >= 0){
brightness1= brightness1-brightnessChange;
}
if (brightness1 <= 0){
while (brightness2 >= 0){
brightness2= brightness2-brightnessChange;
}
}
}
// wait a little before doing this loop over.
delay(30);
}