//UNO PWM pins are 3, 5, 6, 9, 10, 11
//MEGA PWM pins are 2 - 13, 44 - 46
const int redpin = 6;
const int greenpin = 5;
const int bluepin = 3;
void setup() {
pinMode(redpin, OUTPUT);
pinMode(greenpin, OUTPUT);
pinMode(bluepin, OUTPUT);
pinMode(A1, INPUT);
pinMode(12, OUTPUT);
Serial.begin(9600);
}
void loop() {
int photoresist = analogRead(A1);
//10000 lux and above= reading of 39 and lower
//1000 lux and above = reading of 169 to 39
//100 lux and lower = reading of 511 to 1015
//from wokwi docs -- "conditions" (can change these later)
//full daylight = 10000 lux ("good conditions")
//overcast day = 1000 lux ("medium conditions")
//stairway lighting = 100 lux (calling this "poor conditions")
Serial.println(photoresist);
if (photoresist < 169){ //perf - fully green
setColor(0,255,0);
}
else if (photoresist > 511){ // poor - fully red
setColor(255,0,0);
}
else{ // med - yellow
setColor(255,255,0);
}
}
//analogWrite can be 0 to 225 (0=low, 225 = high)
//a function to set the analog value of the PWM pins so we get a diff color
void setColor(int redval, int greenval, int blueval){
analogWrite(redpin, redval);
analogWrite(greenpin, greenval);
analogWrite(bluepin, blueval);
}