Well, with my code, it's pretty much 30 seconds on the dot that it messes up. Then 30 seconds off, then 30 on again.
I ran the default blink sketch that comes with the arduino API, and it lasted for well over a minute, as well as I made it just stay on, and same thing, worked for over a minute without issues... I guess it is my code.
Either way, here is my code. I have a bit commented due to my testing with less pins.
/*
Programmer: Randy Phillips
Date: January 21st, 2010
Description:
Functions to cause blinks, sequences, and pulses
*/
int GlobalTime = 0;
int blinkLED = 2;
int sequenceLEDs[] = {8,9,10,11,12,13};
void setup()
{
/* for(int i = 2; i <= 8; i++)
{
pinMode(i, OUTPUT);
}
*/
// Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop()
{
updateTime();
ledBlink(13, 50, 50);
/*ledPulse(3, 1000, 1000, 100, 0, 35, 255);
ledBlink(4, 100, 50);
ledPulse(5, 1000, 1000, 100, 0, 35, 255);
ledPulse(6, 1000, 1000, 100, 0, 35, 255);
ledBlink(7, 1000, 1000);*/
// ledSequence(sequenceLEDs, 1000, 1000, 6);
}
/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
||||||||||||||||||||||||| Personal Functions Below |||||||||||||||||||||||||
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
void updateTime()
{
GlobalTime = millis();
}
void ledOn(int pinNumber)
{
digitalWrite(pinNumber, HIGH);
}
void ledOff(int pinNumber)
{
digitalWrite(pinNumber, LOW);
}
void ledBlink(int pinNumber, int offTime, int onTime)
{
/*
Blink:
pinNumber - Pin to blink on and off
offTime - Length of time in milliseconds to be off
onTime - Length of time in milliseconds to be on
*/
int elapsed = GlobalTime % (offTime + onTime);
if(elapsed <= offTime)
{
digitalWrite(pinNumber, LOW);
}else{
digitalWrite(pinNumber, HIGH);
}
}
void ledSequence(int pins[], int offTime, int sweepTime, int numberOfLEDs)
{
/*
Sequence:
pins - The pins you want to run in sequence, in the order want them to run
offTime - Length of time in milliseconds to be off
sweepTime - Length of time to go from first pin in sequence to last pin, not length of time for each individual pin
numberOfLEDs - The number of LEDs to be lit in the sequence
*/
int elapsed = GlobalTime % (offTime + sweepTime);
int currentPin = 0;
if(elapsed <= offTime)
{
for(int i = 0; i < numberOfLEDs; i++)
{
digitalWrite(pins[i], LOW);
}
}else{
int newElapsed = elapsed - offTime;
currentPin = map(newElapsed, 0, sweepTime, 0, numberOfLEDs);
for(int i = 0; i < numberOfLEDs; i++)
{
if(i == currentPin)
{
digitalWrite(pins[i], HIGH);
}else{
digitalWrite(pins[i], LOW);
}
}
}
}
void ledPulse(int pinNumber, int offTime, int fadeTime, int pulseTime, int minValue, int maxValue, int pulseValue)
{
/*
Sequence:
pins - The pins you want to run in sequence, in the order want them to run
offTime - Length of time in milliseconds to be off
sweepTime - Length of time to go from first pin in sequence to last pin, not length of time for each individual pin
numberOfLEDs - The number of LEDs to be lit in the sequence
*/
int elapsed = GlobalTime % (offTime + fadeTime + pulseTime);
if(elapsed <= offTime)
{
analogWrite(pinNumber, 0);
}else{
int newElapsed = elapsed - offTime;
if(newElapsed <= fadeTime)
{
int fadeValue = map(newElapsed, 0, fadeTime, minValue, maxValue);
analogWrite(pinNumber, fadeValue);
}else{
analogWrite(pinNumber, pulseValue);
}
}
}
And, if I did my math right, wouldn't a 200 ohm resistor make it 15mA per led? (180 total)