Signal Bleed on an ATtiny 85?

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();
}

I have no idea why it is doing this. I have tried other ATtiny85 chips and tried switching the pins to every possible constellation. Nothing seems to solve the problem.

in the meantime I will be putting all the flicker LEDs on a separate ATtiny chip. As the flicker-effect needs a PWM pin I will be needing to use a couple more chips anyway.

I would still like to know if I am doing something wrong (or something i could be doing better), so please reply to this thread if you see a solution. Thanks.

tried switching the pins to every possible constellation.

There are 88 constellations in the sky:- http://en.wikipedia.org/wiki/Constellation :) Sorry couldn't resist.

I would still like to know if I am doing something wrong

I would say you are using delay(). You have an attempt at using the correct method regarding the millis() timer but you have to follow it through. You need to implement a state machine in each of those functions so that when it is time to move on to the next state you reset the "when is it time to do the next thing" system. The state variable is then advanced (incremented) and the LED turned on of off accordingly. While I am not a great fan of libraries and I would write this myself you can look at this:- http://arduino.cc/playground/Code/FiniteStateMachine

Grumpy_Mike: There are 88 constellations in the sky :-)

Thanks for the link, as far as the constellations go, this is reduced by the fact that Flicker/Fade only works on one of the 3 PWM pins. ;)

Anyway, I think I found the reason for this... well at least a solution. If I use two different ground pins on my arduino to separate the sets of LEDs it works as wanted. Which means when grounding all LEDs on the same ground pin, the signal is somehow "back-washing". At least that is how it looks as explained by a newbie. Any ideas as to if this is normal or if I am doing something wrong?

Thanks, Jason

No it is not normal and sorry but it actually makes no sense at all. It was probbly just a wiring error.