so hi im doing this project and I meet a little chalenge . this project has for purpose to :
-be able to make two push button one to increase the intensity of the led and the other to decrease the light intensity
-be able with a third push button turn on both of the light when i press one time and when press a second time he only turn off one light
so here what i have done so far the 2 push button to increase and decrease work well but the third button doesn't work when i push it doesn't anything
const int led1 =3;
const int led2 = 5;
const int Cdeled1=8;
const int Cdeled2=9;
const int CdePwmPlus=6;
const int CdePwmMoins=9;
const int ledcercle1=2;
// definir les variables
int Val1PWM=0;
int Val2PWM=0;
int Val3PWM=0;
int ValCdeled1=0;
int ValCdeled2=0;
int ValPwmPlus=0;
int ValPwmMoins=0;
int selectioneur=0;
int variable=0;
void setup()
{
// initialise
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(Cdeled1, INPUT);
pinMode(Cdeled2, INPUT);
pinMode(CdePwmPlus, INPUT);
pinMode(CdePwmMoins, INPUT);
pinMode(ledcercle1, INPUT);
analogWrite(led1, 0);
analogWrite(led2, 0);
Val1PWM=0;
Val2PWM=0;
Val3PWM=25;
ValCdeled1=0;
ValCdeled2=0;
Serial.begin(9600);
}
void loop()
{
// lire etat bouton ValPwmPLus
ValPwmPlus= digitalRead( CdePwmPlus);
if (ValPwmPlus==1)
{
Val1PWM=Val1PWM+10;
}
ValPwmMoins= digitalRead( CdePwmMoins);
if (ValPwmMoins==1)
{
Val1PWM=Val1PWM-10;
}
if (Val1PWM>250)
{
Val1PWM=Val1PWM-10;
}
if (Val1PWM<0)
{
Val1PWM=Val1PWM+10;
}
// lire etat bouton CdeLed1
ValCdeled1= digitalRead(Cdeled1);
if (ValCdeled1==1)
{
analogWrite(led1, Val1PWM); // allume cercle1 avec une certaine quantité de lumiere
analogWrite(led2, Val1PWM);
}
ValCdeled2= digitalRead(Cdeled2);
if (ValCdeled2==1)
{
analogWrite(led1, Val1PWM); // allume cercle1 avec une certaine quantité de lumiere
analogWrite(led2, Val1PWM); // Eteint cercle exterieur
}
delay(100);
selectioneur=digitalRead (ledcercle1);
if (selectioneur==1)
{
if (variable==0)
{
analogWrite(led1, Val1PWM);
analogWrite(led2, Val1PWM);
variable=1;
Serial.print(variable);
}
else
{
analogWrite(led1, Val1PWM);
analogWrite(led2, Val2PWM);
variable=0;
Serial.print(variable);
}
}
}