choiiot / lamp

lamp
0 stars 0 forks source link

lamp question #1

Open choiiot opened 3 years ago

choiiot commented 3 years ago

int sensor1 = A1;
int sensor2 = A2; int sensor3 = A3;
int sensor4 = A4; int sensor5 = A5;
int sensor6 = A6; int sensor7 = A7;
int sensor8 = A8; int sensor9 = A9;
int sensor10 = A10; int sensor11 = A11;
int sensor0 = A0; int LED = 2;
int LED1 = 3;
int LED2 = 4;
int RELAY = 5;
int LED14 = 14; int LED15 = 15; int LED16 = 16; int LED17 = 17; int LED18 = 18; int LED19 = 19; int LED20 = 20; int LED21 = 21; int LED22 = 22; int LED23 = 23; int LED24 = 24; int LED25 = 25;

void setup(){ Serial.begin(9600);
pinMode(LED, OUTPUT);
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED14,OUTPUT); pinMode(LED15,OUTPUT);
pinMode(LED16,OUTPUT); pinMode(LED17,OUTPUT); pinMode(LED18,OUTPUT); pinMode(LED19,OUTPUT); pinMode(LED20,OUTPUT); pinMode(LED21,OUTPUT); pinMode(LED22,OUTPUT); pinMode(LED23,OUTPUT); pinMode(LED24,OUTPUT); pinMode(LED25,OUTPUT);
pinMode(RELAY,OUTPUT); pinMode(A0,INPUT); pinMode(A1,INPUT); pinMode(A2,INPUT); pinMode(A3,INPUT); pinMode(A4,INPUT); pinMode(A5,INPUT); pinMode(A6,INPUT); pinMode(A7,INPUT); pinMode(A8,INPUT); pinMode(A9,INPUT); pinMode(A10,INPUT); pinMode(A11,INPUT);

}

void loop(){ Serial.println(analogRead(A0));
delay(10); Serial.println(analogRead(A1)); delay(10); Serial.println(analogRead(A2)); delay(10); Serial.println(analogRead(A3)); delay(10); Serial.println(analogRead(A4)); delay(10); Serial.println(analogRead(A5)); delay(10); Serial.println(analogRead(A6)); delay(10); Serial.println(analogRead(A7)); delay(10); Serial.println(analogRead(A8)); delay(10); Serial.println(analogRead(A9)); delay(10); Serial.println(analogRead(A10)); delay(10); Serial.println(analogRead(A11)); delay(10);

if(analogRead(A0) < 300){
digitalWrite(14,HIGH); delay(100);
} if(analogRead(A1) < 300){
digitalWrite(15,HIGH); delay(100);
} if(analogRead(A2) < 300){
digitalWrite(16,HIGH); delay(100);
} if(analogRead(A3) < 300){
digitalWrite(17,HIGH); delay(100);
} if(analogRead(A4) < 300){
digitalWrite(18,HIGH); delay(100);
} if(analogRead(A5) < 300){
digitalWrite(19,HIGH); delay(100);
} if(analogRead(A6) < 300){
digitalWrite(20,HIGH); delay(100);
} if(analogRead(A7) < 300){
digitalWrite(21,HIGH); delay(100);
} if(analogRead(A8) < 300){
digitalWrite(22,HIGH); delay(100);
} if(analogRead(A9) < 300){
digitalWrite(23,HIGH); delay(100);
} if(analogRead(A10) < 300){
digitalWrite(24,HIGH); delay(100);
} if(analogRead(A11) < 300){
digitalWrite(25,HIGH); delay(100);
}

else {
digitalWrite(2,LOW);
digitalWrite(3,LOW); digitalWrite(4,LOW); digitalWrite(5,LOW); digitalWrite(14,LOW); digitalWrite(15,LOW); digitalWrite(16,LOW); digitalWrite(17,LOW); digitalWrite(18,LOW); digitalWrite(19,LOW); digitalWrite(20,LOW); digitalWrite(21,LOW); digitalWrite(22,LOW); digitalWrite(23,LOW); digitalWrite(24,LOW); digitalWrite(25,LOW);

} }

choiiot commented 3 years ago

I want to make the above code to operate the lamp. The sensor is IR position control. When each sensor A0~A3 is detected, A0 = 14LED ON , A1 = 15LED ON. I want to turn on LED2 separately when all of A0~A3 are LED ON. Also, I want to turn on LED3 when all of A4~A7 are on, and turn on LED4 when A8-A11 is on. Lastly, I want to turn on RELAY 5 when all A0~A11 are ON, but I want to ask how to proceed with the code.