INTERACTIVE LED CIRCUIT
In this circuit demo, I only used 3 leds in my demo because I forgot to take away more leds. One problem I faced was that the yellow led did not light up after the potentiometer was rotated, then I considered that it might be a voltage problem, and modulated the power supply of the link board to 5v, and it was solved.
code:
<textarea>void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
//pushbutton
pinMode(13,INPUT);
digitalWrite(13,HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(13)==0){
//yellow
digitalWrite(11,HIGH);
digitalWrite(10,LOW);
digitalWrite(9,LOW);
delay(1000);
//red
digitalWrite(11,LOW);
digitalWrite(10,HIGH);
digitalWrite(9,LOW);
delay(1000);
//green
digitalWrite(11,LOW);
digitalWrite(10,LOW);
digitalWrite(9,HIGH);
delay(1000);
}
else{
if(analogRead(A1)<400){
digitalWrite(9,LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
}
if(analogRead(A1)>400&analogRead(A1)<600){
digitalWrite(9,LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
}
if(analogRead(A1)>600&analogRead(A1)<800){
digitalWrite(9,HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
}
if(analogRead(A1)>800&analogRead(A1)<1000){
digitalWrite(9,LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
}
if(analogRead(A1)>1000){
digitalWrite(9,LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
}
}
}</textarea>
Video:
My artwork idea is to make a battery model similar to the power display of a mobile phone. Red, yellow and green represent different power levels. The power can be changed through the potentiometer, and the button can display the effect of the battery being charged.

评论
发表评论