// For: https://forum.arduino.cc/t/my-photoresistor-is-always-returning-1023/1029914
//
// Changes:
// Formatted the text
// Added comments
// Changed "Recieving" into "Receiving"
const int IR = 12; // output pin for "IR" led
const int red = 11; // output pin for "red" led
const int UV = 13; // output pin for "UV" led
const int input = A0; // LDR analog input
int cc = 0; // counter, increments every loop(), never resets
int cc2 = 1; // counter within counter within condition
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(IR, OUTPUT);
pinMode(UV, OUTPUT);
pinMode(red, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (cc % 3 == 0)
{
digitalWrite(IR, LOW);
digitalWrite(red, LOW);
digitalWrite(UV, LOW);
if (cc2 == 1)
{
digitalWrite(UV, HIGH);
Serial.println(analogRead(input));
cc2++;
}
else if (cc2 == 2)
{
digitalWrite(red, HIGH);
Serial.println(analogRead(input));
cc2++;
}
else if (cc2 == 3)
{
digitalWrite(IR, HIGH);
Serial.println(analogRead(input));
cc2 = 1;
}
}
else if (cc % 2 == 0)
{
if (analogRead(input) > 160)
{
Serial.println("Receiving....");
}
else
{
Serial.println("....");
}
}
delay(1000);
cc++;
}