Below is the code I wrote:
int sensorPin = 0;
int ledPin1 = 1;
int ledPin2 = 2;
int ledPin3 = 3;
int ledPin4 = 4;
int ledPin5 = 5;
int ledPin6 = 6;
int ledPin7 = 7;
int ledPin8 = 8;
int ledPin9 = 9;
int ledPin10 = 10;
int ledPin11 = 11;
int ledPin12 = 12;
int sensorValue = 0;
void setup() {
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPin7, OUTPUT);
pinMode(ledPin8, OUTPUT);
pinMode(ledPin9, OUTPUT);
pinMode(ledPin10, OUTPUT);
pinMode(ledPin11, OUTPUT);
pinMode(ledPin12, OUTPUT);
}
void loop() {
int threshold1 = 1020;
if(analogRead(sensorPin) < threshold1){
digitalWrite(ledPin1, HIGH);}
else{ digitalWrite(ledPin1, LOW);}
int threshold2 = 938;
if(analogRead(sensorPin) < threshold2){
digitalWrite(ledPin2, HIGH);}
else{ digitalWrite(ledPin2, LOW);}
int threshold3 = 853;
if(analogRead(sensorPin) < threshold3){
digitalWrite(ledPin3, HIGH);}
else{ digitalWrite(ledPin3, LOW);}
int threshold4 = 768;
if(analogRead(sensorPin) < threshold4){
digitalWrite(ledPin4, HIGH);}
else{ digitalWrite(ledPin4, LOW);}
int threshold5 = 683;
if(analogRead(sensorPin) < threshold5){
digitalWrite(ledPin5, HIGH);}
else{ digitalWrite(ledPin5, LOW);}
int threshold6 = 598;
if(analogRead(sensorPin) < threshold6){
digitalWrite(ledPin6, HIGH);}
else{ digitalWrite(ledPin6, LOW);}
int threshold7 = 512;
if(analogRead(sensorPin) < threshold7){
digitalWrite(ledPin7, HIGH);}
else{ digitalWrite(ledPin7, LOW);}
int threshold8 = 427;
if(analogRead(sensorPin) < threshold8){
digitalWrite(ledPin8, HIGH);}
else{ digitalWrite(ledPin8, LOW);}
int threshold9 = 342;
if(analogRead(sensorPin) < threshold9){
digitalWrite(ledPin9, HIGH);}
else{ digitalWrite(ledPin9, LOW);}
int threshold10 = 257;
if(analogRead(sensorPin) < threshold10){
digitalWrite(ledPin10, HIGH);}
else{ digitalWrite(ledPin10, LOW);}
int threshold11 = 172;
if(analogRead(sensorPin) < threshold11){
digitalWrite(ledPin11, HIGH);}
else{ digitalWrite(ledPin11, LOW);}
int threshold12 = 87;
if(analogRead(sensorPin) < threshold12){
digitalWrite(ledPin12, HIGH);}
else{ digitalWrite(ledPin12, LOW);}
}
E-circuit of LEDs
Put revised model in, just fit! (the support piece last week is smaller for LED to embedded in, I redo them~)
Light it up!!
Light effect
Detail
No comments:
Post a Comment