Last active
October 23, 2020 08:15
-
-
Save xinzhang-jessy/9fc073d53061d4bb5ae2d4b3a8b3cd98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Light Measurement Cup | |
Jessy(Xin Zhang) | |
Digital Future 6037-001 Creation & Computation | |
OCAD University | |
Created on 2020-10-19 | |
Based on: | |
LED Intensity Control Using LDR,By m_29,https://www.instructables.com/LED-Intensity-Control-Using-LDR/ | |
*/ | |
int ledPin1 = 2; | |
int ledPin2 = 3; | |
int ledPin3 = 4; | |
int ledPin4 = 5; | |
int ledPin5 = 6; | |
int sensorValue1 = 0; | |
int sensorValue2 = 0; | |
int sensorValue3 = 0; | |
int ledValue1 = 0; | |
int ledValue2 =0; | |
int ledValue3 = 0; | |
int ledValue4 =0; | |
int ledValue5 = 0; | |
bool on1=false; | |
bool on2=false; | |
void setup() | |
{ | |
pinMode(2, OUTPUT); | |
pinMode(3, OUTPUT); | |
pinMode(4, OUTPUT); | |
pinMode(5, OUTPUT); | |
pinMode(6, OUTPUT); | |
} | |
void loop() | |
{ | |
sensorValue1 = analogRead(A0); | |
sensorValue2 = analogRead(A1); | |
sensorValue3 = analogRead(A2); | |
Serial.println("sensor1: "); | |
Serial.println(sensorValue1); | |
Serial.println("sensor2: "); | |
Serial.println(sensorValue2); | |
Serial.println("sensor3: "); | |
Serial.println(sensorValue3); | |
delay(500); | |
on1 = false; | |
on2 = false; | |
ledValue1 = map(sensorValue1,0, 1000, 0,255); | |
ledValue2 = map(sensorValue2,0, 1000, 0,255); | |
ledValue3 = map(sensorValue3,0, 1000, 0,255); | |
if (sensorValue1<600){ | |
analogWrite(2, ledValue1); | |
on1 = true; | |
} | |
else{ | |
on2 = false; | |
analogWrite(2, LOW); | |
} | |
if (on1 && sensorValue2<700){ | |
on2 = true; | |
analogWrite(3, ledValue2); | |
analogWrite(4, ledValue2); | |
} else{ | |
on2 = false; | |
analogWrite(3, LOW); | |
analogWrite(4, LOW); | |
} | |
if(on1 && on2 && sensorValue3<700){ | |
analogWrite(5, ledValue3); | |
analogWrite(6, ledValue3); | |
} else{ | |
analogWrite(5,LOW); | |
analogWrite(6,LOW); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment