two led circuits independant

int sensorValue = 0; //make a variable where you can store incoming //analog values

// Constants const int Green = 5; const int Red = 3; const int Yellow = 4;

//Variables byte GreenState = 0; byte RedState = 0; byte YellowState = 0;

long PrevMillisGreen = 0; long PrevMillisRed = 0; long PrevMillisYellow = 0;

long GreenInterval = 900; long RedInterval = 200; long YellowInterval = 400; unsigned long CurrentMillis = millis();

void setup(){

// put your setup code here, to run once: pinMode(Green, OUTPUT); pinMode(Red, OUTPUT); pinMode(Yellow, OUTPUT);

pinMode(13, OUTPUT); pinMode(12, OUTPUT); //tell arduino what you'll be using these pins pinMode(11, OUTPUT); // for (output). pinMode(10, OUTPUT); pinMode(9, OUTPUT); pinMode(8, OUTPUT); pinMode(7, OUTPUT); pinMode(6, OUTPUT);

Serial.begin(9600); //initialize serial }

void loop() { //we put the code we want executed in a loop CurrentMillis = millis(); if (CurrentMillis - PrevMillisGreen > GreenInterval) { GreenState = !GreenState; digitalWrite(Green, GreenState); PrevMillisGreen = CurrentMillis; } if (CurrentMillis - PrevMillisRed > RedInterval) { RedState = !RedState; digitalWrite(Red, RedState); PrevMillisRed = CurrentMillis; } if (CurrentMillis - PrevMillisYellow > YellowInterval) { YellowState = !YellowState; digitalWrite(Yellow, YellowState); PrevMillisYellow = CurrentMillis; }

digitalWrite(13,HIGH); // lights the led sensorValue = analogRead(0); // reads pin 0 delay(sensorValue + 25); // sensorValue used for delay digitalWrite(13,LOW); //turns off the led delay(2); //delay before moving to next output pin //the + 25 keeps delay from reaching zero //code below is for remaining 4 LEDs

digitalWrite(12,HIGH); sensorValue = analogRead(0); delay(sensorValue + 25); digitalWrite(12, LOW); delay(2);

digitalWrite(11,HIGH); sensorValue = analogRead(0); delay(sensorValue + 25); digitalWrite(11,LOW); delay(2);

digitalWrite(10,HIGH); sensorValue = analogRead(0); delay(sensorValue + 25); digitalWrite(10,LOW); delay(2);

digitalWrite(9,HIGH); sensorValue = analogRead(0); delay(sensorValue + 25); digitalWrite(9,LOW); delay(2);

digitalWrite(8, HIGH); sensorValue = analogRead(0); delay(sensorValue + 25); digitalWrite(8, LOW); delay(2);

digitalWrite(7,HIGH); sensorValue = analogRead(0); delay(sensorValue + 25); digitalWrite(7,LOW); delay(2);

digitalWrite(6,HIGH); sensorValue = analogRead(0); delay(sensorValue + 25); digitalWrite(6,LOW); delay(2);


my above code is to make pins 6-13 chase in one direction from pin 13 down to pin 6 with speed control potentiometer added to control the rate of flow, but i have also tried to incorporate a seperate circuit to have three leds on pins 3 -5 flashing at different rates independant to the main circuit. problem i am having is when potentiometer is at full speed the independant three led's flash at dif times which is exactly what i want, but when i lower the speed on the pot the three leds change from there flashing rate and stay on permanent high until the main sequence reaches pin 6 then change state back to low until the main sequence comes down again to pin 6 and changes state back to high. as soon as i change the pot back to high, leds are normal. it seems to me that the pot is interferring with this seperate program somehow and after each twenty six main sequence runs, the program breifly stops for a second before starting again as if an internal counter has reached its maximum before starting the loop again? can anybody throw some light on it for me.

You need to use type "unsigned long" when you play around with millis() long PrevMillisGreen = 0; long PrevMillisRed = 0; long PrevMillisYellow = 0;

long GreenInterval = 900; long RedInterval = 200; long YellowInterval = 400;

When you turn your potentiometer up high, the loop takes too long to execute. (it has to wait untill it has been through all those delays before it has a chance to restart the loop to checkout your independent LEDS.

One of the most often used phrases here is "don't use delay". Search the forums for blink without delay. Robin2 has a sticky about using the technique.