Hi all,
I am working on a fairly uncomplicated LED lighting project. I am using a version 3 Arduino Uno as an ISP to upload the code to an ATtiny85 (on a WinXP System with Arduino Software version22), so far so good. I have LEDs that are blinking (1 sec on, 1 sec off) and some that are double-blinking, and a set of LEDs that are "flickering" (brightness altered using random() ).
Well everything works fine until I started entering a couple delay() to the double-blink LEDs to set their timing against the blink LEDs the way I want to have it. after about the 4th or 5th delay() the flicker LEDs started blinking also (well flickering while they are on but blinking as well)... take one or two of the "delay(100); " away and they flicker again like they are suposed to. I have been looking at this code and starring at LEDs now for 15 hours straight so it is also quite possible that there is a mistake that I am just not seeing.
ATtiny85
Reset | o | VCC (+)
2 Blink LEDs (ledPin3) | | 2 Double-Blink LEDs (ledPin2)
2 Blink LEDs (ledPin4) | | 2 Flicker LEDs (ledPin1)
(-) GND |________| 1 (fadePin0) - Not currently in use
My code is a bit of a mess due to copying and pasting things in and out looking for a solution to the problem, but here it is... Thanks in advance for any suggestions.
int ledPin4 = 4;
int ledPin3 = 3;
int ledPin2 = 2;
int ledPin1 = 1;
int fadePin = 0;
unsigned long nextBlink, nextFade, nextBlink_Strobe;
int fadeBrightness = 0;
char ledState = LOW, ledState_Strobe = LOW, fadeDir = 100; // Standard 20 step
void setup()
{
pinMode(ledPin4, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin2, OUTPUT);
//pinMode(ledPin1, OUTPUT);
pinMode(fadePin, OUTPUT);
ledState = LOW;
nextBlink = millis();
nextFade = millis();
}
void blink_Nav(void)
{
unsigned long now;
now = millis();
if (now >= nextBlink) {
nextBlink = now + 1000; // Next change in one second
if (ledState == LOW) {
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
delay(400);
digitalWrite(ledPin2, HIGH);
delay(100); // wait for a bit
digitalWrite(ledPin2, LOW);
delay(50);
digitalWrite(ledPin2, HIGH);
delay(100); // wait for a bit
digitalWrite(ledPin2, LOW);
ledState = HIGH;
}
else {
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
delay(400);
digitalWrite(ledPin2, HIGH);
delay(100); // wait for a bit
digitalWrite(ledPin2, LOW);
delay(50);
digitalWrite(ledPin2, HIGH);
delay(100); // wait for a bit
digitalWrite(ledPin2, LOW);
ledState = LOW;
}
}
}
void flicker()
{ //Sets a random value of LED voltage in the range of 0V - 5V with PWM NOTE set to pin 1 doesnt work well with fade on pin 0??
analogWrite(ledPin1, random(100,255)); //limiting the range makes a good booster affect, otherwise 0, 255 is good flicker rate
delay(random(10,40)); //Limits the speed.
}
void loop()
{
blink_Nav();
//blink_Strobe();
//fade();
flicker();
}