Hey all,
I'm building a solar powered sign illuminator using a outdoor LED rope and naturally controlled by our loved arduino "mega".
what I want to add to the code is a chunk of stuff to make the indicator light flash faster and faster as the led rope time expires.
anyone know of some simple code to do this? my mind is void looping...
void setup()
{
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode (12, OUTPUT); // set the socket D12 as an output
pinMode (11, OUTPUT); // set the socket D11 as an output
pinMode (1, INPUT); // set the socket A1 as an input
pinMode (2, INPUT); // set the socket A2 as an input
pinMode (10, INPUT); // set the socket D10 as an input
}
int lifetime = 0;
int buffer = 30;
int led1State = LOW; // set the led rope off
int led2State = HIGH; // set the indicator led on
void loop() {
int ldr = analogRead(1);
int pot = analogRead(2);
Serial.print("LDR: "); Serial.println(ldr);
Serial.print("POT: "); Serial.println(pot);
if (ldr < pot) {
if (lifetime < buffer) {
lifetime += 15;
}
if (lifetime >= buffer) {
lifetime == buffer;
led1State = HIGH;
led2State = LOW;
digitalWrite(12, led1State);
digitalWrite(11, led2State);
}
} else {
if (lifetime > 0) {
lifetime--;
}
if (lifetime <= 0) {
lifetime = 0;
led1State = LOW;
led2State = HIGH;
digitalWrite(12, led1State);
digitalWrite(11, led2State);
}
}
Serial.print("Lifetime: "); Serial.println(lifetime);
Serial.print("LED Rope: "); Serial.println(led1State);
Serial.print("Indicator LED: "); Serial.println(led2State);
if (digitalRead(10) == HIGH) {
delay(5 * 60 * 1000); // 5 Minutes
} else {
delay(1000); // 1 second
}
}