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); }       }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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);
}
  
  
}

 

KER
Swanky Sango
DIGITAL PWM-I
0O UNO
ARDUINO
POWER
ANALOG IN
...
Transcribed Image Text:KER Swanky Sango DIGITAL PWM-I 0O UNO ARDUINO POWER ANALOG IN ...
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Running Time of Application
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education