Hi,
I have a string of 2 wire LED fairy lights, there are 100 LED's all in parallel with 50% of them reverse polarity. I want to change the controller as the original sequencing is a bit fierce! These fairy lights originally were 5v USB powered. I've written some code which uses two digital to outputs to create a signal on one pin and inverse that signal to the second pin. This works ok with a few leds but the Arduino Nano obviously can't power up 100 led's. I thought maybe I could use a couple of mosfets but although I can get one polarity to light up the reverse polarity does not. I'd assumed that connecting the string of leds to the output's of the mosfets the same way that you'd connect the two wire string to the pins of the Arduino would work but it doesn't. Am I going to have to use an H bridge? I suspect I'm probably going to have to modify my code if I do. For what its worth, the original controller is pretty cool, two small sm chips, a few resistors and a IR detector for the remote control all this from a USB port with 100 very bright leds! I'm not entirely sure I know how to control an H bridge if I have to use one. The following code produces a soft alternating glow with random speed changes every five seconds and at some point I'd like to make time length for the changes random as well however it is the hardware that I'm having a problem with..at the moment. Any pointers or ideas would gratefully received.
const uint16_t sintable2[]={
1021,1046,1071,1096,1121,1146,1171,1196,
1220,1245,1269,1293,1317,1341,1365,1388,
1412,1435,1458,1480,1502,1524,1546,1567,
1588,1609,1629,1649,1669,1688,1707,1725,
1743,1760,1778,1794,1810,1826,1841,1856,
1870,1884,1897,1909,1921,1933,1944,1954,
1964,1974,1982,1990,1998,2005,2011,2017,
2022,2027,2031,2034,2037,2039,2041,2042,
2042,2042,2041,2039,2037,2034,2031,2027,
2022,2017,2011,2005,1998,1990,1982,1974,
1964,1954,1944,1933,1921,1909,1897,1884,
1870,1856,1841,1826,1810,1794,1778,1760,
1743,1725,1707,1688,1669,1649,1629,1609,
1588,1567,1546,1524,1502,1480,1458,1435,
1412,1388,1365,1341,1317,1293,1269,1245,
1220,1196,1171,1146,1121,1096,1071,1046,
1021,996,971,946,921,896,871,846,
822,797,773,749,725,701,677,654,
630,607,584,562,540,518,496,475,
454,433,413,393,373,354,335,317,
299,282,264,248,232,216,201,186,
172,158,145,133,121,109,98,88,
78,68,60,52,44,37,31,25,
20,15,11,8,5,3,1,0,
0,0,1,3,5,8,11,15,
20,25,31,37,44,52,60,68,
78,88,98,109,121,133,145,158,
172,186,201,216,232,248,264,282,
299,317,335,354,373,393,413,433,
454,475,496,518,540,562,584,607,
630,654,677,701,725,749,773,797,
822,846,871,896,921,946,971,996,
};
int idx;
unsigned long startMicros;
unsigned long currentMicros;
unsigned long rateMicros;
unsigned long rate;
unsigned long changetimer;
const unsigned long period = 2042; //sets the pwm frequency in microseconds, 2042 microseconds=490hz
const byte ledPin3 = 3;
const byte ledPin4 = 4;
unsigned long duty;
unsigned long startDuty;
void setup() {
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
digitalWrite(ledPin3,LOW);
digitalWrite(ledPin4,LOW);
}
void loop() {
currentMicros=micros();
if (currentMicros - changetimer>=5000000){rate=random(1000,3000);
changetimer=currentMicros;
rateMicros = currentMicros;}
if (currentMicros - rateMicros >= rate){rateMicros = currentMicros;
idx++;
if(idx>=255){idx=0;}
duty=sintable2[idx];}
if (currentMicros - startMicros >= period){digitalWrite(ledPin3,HIGH);
digitalWrite(ledPin4,LOW);
startDuty=currentMicros;
startMicros = currentMicros;}
if (currentMicros - startDuty >= duty ){digitalWrite(ledPin3,LOW);
digitalWrite(ledPin4,HIGH);
startDuty=currentMicros;}
}