I am trying to program an ATTINY13a to analogue read a photo resistor and write to flash a red LED in low light conditions and a white LED in high light conditions. I have the system working on an Arduino, with pins 13, 12, and A0 in place for 5, 6, and 2 on the Attiny13a.
Here is the code:
/*
Tower blink
This program sets up a blinking pattern to simulate that
of radio towers. By day, it will blink sunny white. By
Night, it will blink red.
*/
int wled = 5;
int rled = 6;
int sensor = 2;
int sensorLow = 40;
unsigned long previousMillis;
unsigned long previousMillis2;
long OnTimeWhite = 100;
long InterBlinkWhite = 80;
long OffTimeWhite = 1000;
long OnTimeRed = 1000;
long OffTimeRed = 1500;
void setup() {
pinMode (wled, OUTPUT);
pinMode (rled, OUTPUT);
pinMode (sensor, INPUT);
}
void loop()
{
unsigned long currentMillis = millis();
unsigned long timeDifference = (currentMillis - previousMillis);
{
if (analogRead (sensor) < sensorLow - 5) {
digitalWrite (wled, LOW);
if (timeDifference <= OnTimeRed) {
digitalWrite (rled, HIGH);
}
else if (timeDifference <= OnTimeRed + OffTimeRed) {
digitalWrite (rled, LOW);
}
else {
previousMillis = currentMillis;
}
}
else if (analogRead (sensor) > sensorLow + 5) {
digitalWrite (rled, LOW);
if (timeDifference <= OnTimeWhite) {
digitalWrite (wled, HIGH);
}
else if (timeDifference <= OnTimeWhite + InterBlinkWhite){
digitalWrite (wled, LOW);
}
else if (timeDifference <= 2*OnTimeWhite + InterBlinkWhite){
digitalWrite (wled, HIGH);
}
else if (timeDifference <= 2*OnTimeWhite + InterBlinkWhite +OffTimeWhite) {
digitalWrite (wled, LOW);
}
else {
previousMillis = currentMillis;
}
}
else {
digitalWrite (rled, LOW);
digitalWrite (wled, LOW);
}
}
}
Here is a screenshot of the circuit I built in TinkerCad:
Nothing is working, so I am wondering where to start fixing it.
Thanks!