PLEASE EXPLAIN HOW THE DEVICE WORKS GIVEN TGE FOLLOWING CODE AND IMAGE #define led1 3 #define led2 5 #define led3 6 #define led4 9 #define led5 10 #define led6 11 #define bttn1 2 #define bttn2 13 int brigtness1=0; int brigtness2=0; int potValue1=0; int potValue2=0; int bttnState=0; void setup() { Serial.begin(9600); pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(led4, OUTPUT); pinMode(led5, OUTPUT); pinMode(led6, OUTPUT); pinMode(bttn1, INPUT); pinMode(bttn2, INPUT); Â Â digitalWrite(led1, LOW); digitalWrite(led2, LOW); digitalWrite(led3, LOW); digitalWrite(led4, LOW); digitalWrite(led5, LOW); digitalWrite(led6, LOW); } void loop() { int val = analogRead(1); potValue1 = map(val, 0, 1023, 0, 255); val = analogRead(0); potValue2 = map(val, 0, 1023, 0, 255); Â Â if(digitalRead(bttn1)==1){ bttnState=1; if(brigtness2!=0){ brigtness1=brigtness2; }else{ brigtness1=potValue1; } analogWrite(led1, brigtness1); analogWrite(led2, brigtness1); analogWrite(led3, brigtness1); digitalWrite(led4, LOW); digitalWrite(led5, LOW); digitalWrite(led6, LOW); } else if(digitalRead(bttn2)==1){ bttnState=2; if(brigtness1!=0){ brigtness2=brigtness1; }else{ brigtness2=potValue2; } digitalWrite(led1, LOW); digitalWrite(led2, LOW); digitalWrite(led3, LOW); analogWrite(led4, brigtness2); analogWrite(led5, brigtness2); analogWrite(led6, brigtness2); } Â Â val = analogRead(1); if(map(val, 0, 1023, 0, 255)!=potValue1 && bttnState==1){ brigtness1 = map(val, 0, 1023, 0, 255); analogWrite(led1, brigtness1); analogWrite(led2, brigtness1); analogWrite(led3, brigtness1); digitalWrite(led4, LOW); digitalWrite(led5, LOW); digitalWrite(led6, LOW); } val = analogRead(0); if(map(val, 0, 1023, 0, 255)!=potValue2 && bttnState==2){ brigtness2 = map(val, 0, 1023, 0, 255); Serial.println(brigtness2); digitalWrite(led1, LOW); digitalWrite(led2, LOW); digitalWrite(led3, LOW); analogWrite(led4, brigtness2); analogWrite(led5, brigtness2); analogWrite(led6, brigtness2); } Â Â Â Â }
PLEASE EXPLAIN HOW THE DEVICE WORKS GIVEN TGE FOLLOWING CODE AND IMAGE
#define led1 3
#define led2 5
#define led3 6
#define led4 9
#define led5 10
#define led6 11
#define bttn1 2
#define bttn2 13
int brigtness1=0;
int brigtness2=0;
int potValue1=0;
int potValue2=0;
int bttnState=0;
void setup()
{
Serial.begin(9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(bttn1, INPUT);
pinMode(bttn2, INPUT);
 Â
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
}
void loop()
{
int val = analogRead(1);
potValue1 = map(val, 0, 1023, 0, 255);
val = analogRead(0);
potValue2 = map(val, 0, 1023, 0, 255);
 Â
if(digitalRead(bttn1)==1){
bttnState=1;
if(brigtness2!=0){
brigtness1=brigtness2;
}else{
brigtness1=potValue1;
}
analogWrite(led1, brigtness1);
analogWrite(led2, brigtness1);
analogWrite(led3, brigtness1);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
}
else if(digitalRead(bttn2)==1){
bttnState=2;
if(brigtness1!=0){
brigtness2=brigtness1;
}else{
brigtness2=potValue2;
}
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
analogWrite(led4, brigtness2);
analogWrite(led5, brigtness2);
analogWrite(led6, brigtness2);
}
 Â
val = analogRead(1);
if(map(val, 0, 1023, 0, 255)!=potValue1 && bttnState==1){
brigtness1 = map(val, 0, 1023, 0, 255);
analogWrite(led1, brigtness1);
analogWrite(led2, brigtness1);
analogWrite(led3, brigtness1);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
}
val = analogRead(0);
if(map(val, 0, 1023, 0, 255)!=potValue2 && bttnState==2){
brigtness2 = map(val, 0, 1023, 0, 255);
Serial.println(brigtness2);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
analogWrite(led4, brigtness2);
analogWrite(led5, brigtness2);
analogWrite(led6, brigtness2);
}
 Â
 Â
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps