Noop here....
I am trying to write a sketch that can fade 2 LEDs when you press the button.
the fade rate can be changed by using scale & EEPROM.
I had 2 problems:
1- the LED connected to pin 10 doesn't seem to respond to the skech at all.
2- while the other LED seems to work fine at first, after pressing the button for 3 or 4 times, it doesn't fade down to 0 brightness, instead it just dim from max to 0 at instance
please help...
here is the sketch.
#include <EEPROM.h>
/*
برنامج بيخلى لمبتين يعملوا fade
بشرط الضغط على الزر
مع امكانيه تعديل معدل التردد و الخفاظ عليه عند فصل الكهرباء
*/
int light[2] = {10,5};
int button =2;
int fadeamout[2] = {5.5};
int brightness[2]={0,0};
int scale =1;
void setup() {
pinMode (light[0],OUTPUT);
pinMode (light[1],OUTPUT);
pinMode (button,INPUT);
Serial.begin(9600);
Serial.setTimeout(10);
int savedscale =EEPROM.read(0);
if (savedscale<20)
scale = savedscale;
}
void loop() {
int newscale =Serial.parseInt();
if (newscale > 0)
scale = newscale;
EEPROM.write(0,scale);
int buttonsatate = digitalRead(button);
for (int counter =0;counter<2;counter++){
if (buttonsatate == HIGH){
brightness[counter] = brightness[counter]+fadeamout[counter]*scale;
if(brightness[counter]==0 || brightness[counter]==255){
fadeamout[counter] = -fadeamout[counter];}
}
else analogWrite(light[counter], 0);
analogWrite(light[counter], brightness[counter]);
}
delay(30);
}