Go Down

### Topic: Mini Stage Show x 20 (Read 8211 times)previous topic - next topic

#### marco_c

#15
##### Aug 15, 2012, 10:21 am
As long as you have more samples than you need in the table you can squeeze the time base.

A sine wave is very simple mathematically as y=h*sin(x). X varies from 0 to 360 degrees and then the wave repeats, so no need to work out any more. The h for the arduino is 255 as there is no need for a bigger number. The only real variable is the step in the degrees that you want to hold and with 5 degree difference between points we get a table of 72 data points. In 10 seconds that makes it 7.2 changes to the led in 1 second, easily done.

If you only want 5 seconds, then you just take every other value in the table or have more transitions per second.
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

#### Chagrin

#16
##### Aug 15, 2012, 04:46 pm
This version allows basic dimming/brightnessing(?) of any LED and in combination with any other LEDs (i.e. it allows crossfading). I have the dimming defined by a "dimrate" or how much to change the brightness every MILLISPERDIMSTEP millis. So, a dimrate of "10" means it increases brightness by 10 every 10 milliseconds. Not the most flexible method but y'know.

I checked memory usage and it is has 1752 bytes free with this size of a scene. Each scene command uses 6 bytes. Plenty of space left for a larger scene.

Code: [Select]
`#define LED1 3 // assign the first LED to pin 3#define LED2 5 // assign the second LED to pin 5, etc...#define LED3 6#define MAXPINNUMBER 6 // LED3 is the highest pin number -- number 6#define MILLISPERDIMSTEP 10 // LED dimming is recalculated every X millis// Group LED commands into a structure (struct)struct command {  byte pin;          // 0 to 255  unsigned int time; // 0 to 65535  byte brightness;   // 0 to 255  char dimrate;      // -127 to 128};// The stored state of each LED; holds state of dimming.struct state {  unsigned int time;  byte brightness;  byte dimrate;};// Create the scene which is an array of "command" structsstruct command scene[] = {  {LED1,0,255,0},  {LED2,0,255,0},  {LED3,0,255,0},  {LED1,1000,0,0},  {LED2,2000,0,0},  {LED3,3000,0,10},  {LED3,6000,255,-10},  {LED3,9000,0,1},  {LED3,12000,255,-1}};// Initialize the LED states to off. Note 0 to MAXPINNUMBER is (MAXPINNUMBER + 1) states.struct state ledState[MAXPINNUMBER + 1] = {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}};void setup(){}void loop(){  static unsigned long kickoff = 0;  static unsigned int sceneCtr = 0;  byte ledCtr = 0;  // wait for a button press here to kick off the scene if desired  // Check the scene to see if we have a new command  if (sceneCtr < sizeof(scene) / sizeof(command)) {    if (scene[sceneCtr].time <= millis() - kickoff) {      analogWrite(scene[sceneCtr].pin, scene[sceneCtr].brightness);      if (scene[sceneCtr].dimrate != 0) {        // It dims; we have to add this to our ledState array and keep track of it.        ledState[scene[sceneCtr].pin].time = scene[sceneCtr].time + MILLISPERDIMSTEP;        ledState[scene[sceneCtr].pin].brightness = scene[sceneCtr].brightness;        ledState[scene[sceneCtr].pin].dimrate = scene[sceneCtr].dimrate;               }      sceneCtr += 1;    }  }    // Here we process through all the LEDs in a dimming state  for (ledCtr = 0; ledCtr < MAXPINNUMBER + 1; ledCtr++) {    if (ledState[ledCtr].dimrate != 0) { // only LEDs with a dimming are messed with.      if (ledState[ledCtr].time <= millis() - kickoff) {        if (ledState[ledCtr].brightness + (char) ledState[ledCtr].dimrate >= 0 &&            ledState[ledCtr].brightness + (char) ledState[ledCtr].dimrate <= 255) {          ledState[ledCtr].brightness += (char) ledState[ledCtr].dimrate;          ledState[ledCtr].time += MILLISPERDIMSTEP; // mark the time of next LED adjustment        } else if (ledState[ledCtr].brightness + (char) ledState[ledCtr].dimrate < 0) {          // need to stop at zero and not a negative number.          ledState[ledCtr].brightness = 0;          ledState[ledCtr].dimrate = 0; // zero dimrate so we stop dimming it        } else {          // need to stop at 255.          ledState[ledCtr].brightness = 255;          ledState[ledCtr].dimrate = 0; // zero dimrate.        }        analogWrite(ledCtr, ledState[ledCtr].brightness);      }     }  }    // Have 60 seconds elapsed? We need to restart if so.  if (millis() - kickoff > 60000) {    kickoff = millis();    sceneCtr = 0;  }}`

#### Tom-Kristensen

#17
##### Aug 15, 2012, 11:57 pm
Marco, I opened an Excel spreadsheet and got stuck into applying the sine wave fomula to produce a set of values to generate a lookup table. I didn't get too far before I decided to go back to basics and just produce a full cross fade of two LEDs jumping by 5 brightness points every 100 milliseconds. One led fading from 255 - 0. the other brightening from 0 - 255. Testing out my rusty Excel skills I came to see that it is not such a big deal to make these tables. I produced a matrix of 101 commands with 3 values per line. I then saved this as a CVC file and pasted it into the sketch built by Chagrin. Worked fine. Happy to post the code except that it is just a boring list of numbers that would produce a box that runs down to the floor.

Watching my slow 10 second cross fade I came to realise that there is more to producing a smooth fade than trying to apply a sine function. The brightness scale of 0 - 255 seems like it should produce a linear increase in brightness with each increasing step, but the perception of brightness is non-linear. The eye is far more sensitive to incremental changes to a low level light source than to a bright light source. So, ideally we would be applying an exponent other than sine to get the classic exponential growth curve - and even I can see that this is not going to happen.

But it was fun thinking about!

#### Tom-Kristensen

#18
##### Aug 16, 2012, 12:16 am
BREAKING NEWS The most exciting LED code ever written has arrived overnight from Chagrin.

I used to hate LED lighting. Its too bright for a start and then when used as dynamic decorative lighting the programmer makes something that would induce epilepsy. I don't want to dump on Christmas, but when I was a kid when we had actual candles on the tree and they looked beautiful. Like LED christmas lights, most arduino LED sketches are not pleasant to watch IMO. But LED is very reliable and low cost and the colours are pretty cool, best of all it is programmable with PWM. Or so I thought until I tried to find some code that would allow me to gently dim and brighten a bank of 12 lights, any lights at any time. No such code. Until now!

Too busy playing with my lights now. More later. Thank you Chagrin - there is a Santa after all.

#### Tom-Kristensen

#19
##### Aug 16, 2012, 02:00 pmLast Edit: Aug 16, 2012, 02:02 pm by Tom-Kristensen Reason: 1
I've been playing with a bank of 3 LEDs all day, on and off. The Chagrin code (that's an official code name) is excellent. I am able to do everything I was hoping for. Slow fades, fast fades, cross fades and best of all its all extremely flexible and simple to control. I really recommend that people try this code, it has to be the best thing yet for running LEDs in a controlled fashion.

I am not sure about limitations to the program. There is a time limit imposed by the unsigned int time of 65535 milliseconds which gives a time line of 65 seconds, but perhaps this could be extended with another board. In any case there is a loop function so lights keep running. Likewise I am not yet sure of the PWM capabilities of the Uno board when using a larger bank of LEDs. I am using pretty hefty 10mm LEDs that draw at least 20mA - sorry no means to measure this - and I am seeing some fluttering on particular dimming sequences. Perhaps this is a function of the hardware rather than the code, but the nice thing is that a dodgy fade can be corrected by tweaking the fade parameters.

I would be keen to hear from other who might try the code. My next exercise is to add more lights and see what happens. Might order a bigger board too. Having fun now.

#### marco_c

#20
##### Aug 16, 2012, 02:04 pm
We could try it if someone posts it ...
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

#### Tom-Kristensen

#21
##### Aug 16, 2012, 02:39 pm
OK sorry Marco. The code was a couple of posts back. I was not sure about re-posting stuff, but here it is:
Code: [Select]
`/*Fade up and down on multiple pinsCode written by Chagrin August 2012*/#define LED1 3 // assign the first LED to pin 3#define LED2 5 // assign the second LED to pin 5, etc...#define LED3 6#define MAXPINNUMBER 6 // LED3 is the highest pin number -- number 6#define MILLISPERDIMSTEP 10 // LED dimming is recalculated every X millis// Group LED commands into a structure (struct)struct command {  byte pin;          // 0 to 255  unsigned int time; // 0 to 65535  byte brightness;   // 0 to 255  char dimrate;      // -127 to 128};// The stored state of each LED; holds state of dimming.struct state {  unsigned int time;  byte brightness;  byte dimrate;};// Create the scene which is an array of "command" structsstruct command scene[] = {  {LED1,0,255,0},  {LED2,0,255,0},  {LED3,0,255,0},  {LED1,1000,0,0},  {LED2,2000,0,0},  {LED3,3000,0,10},  {LED3,6000,255,-10},  {LED3,9000,0,1},  {LED3,12000,255,-1}};// Initialize the LED states to off. Note 0 to MAXPINNUMBER is (MAXPINNUMBER + 1) states.struct state ledState[MAXPINNUMBER + 1] = {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}};void setup(){}void loop(){  static unsigned long kickoff = 0;  static unsigned int sceneCtr = 0;  byte ledCtr = 0;  // wait for a button press here to kick off the scene if desired  // Check the scene to see if we have a new command  if (sceneCtr < sizeof(scene) / sizeof(command)) {    if (scene[sceneCtr].time <= millis() - kickoff) {      analogWrite(scene[sceneCtr].pin, scene[sceneCtr].brightness);      if (scene[sceneCtr].dimrate != 0) {        // It dims; we have to add this to our ledState array and keep track of it.        ledState[scene[sceneCtr].pin].time = scene[sceneCtr].time + MILLISPERDIMSTEP;        ledState[scene[sceneCtr].pin].brightness = scene[sceneCtr].brightness;        ledState[scene[sceneCtr].pin].dimrate = scene[sceneCtr].dimrate;               }      sceneCtr += 1;    }  }    // Here we process through all the LEDs in a dimming state  for (ledCtr = 0; ledCtr < MAXPINNUMBER + 1; ledCtr++) {    if (ledState[ledCtr].dimrate != 0) { // only LEDs with a dimming are messed with.      if (ledState[ledCtr].time <= millis() - kickoff) {        if (ledState[ledCtr].brightness + (char) ledState[ledCtr].dimrate >= 0 &&            ledState[ledCtr].brightness + (char) ledState[ledCtr].dimrate <= 255) {          ledState[ledCtr].brightness += (char) ledState[ledCtr].dimrate;          ledState[ledCtr].time += MILLISPERDIMSTEP; // mark the time of next LED adjustment        } else if (ledState[ledCtr].brightness + (char) ledState[ledCtr].dimrate < 0) {          // need to stop at zero and not a negative number.          ledState[ledCtr].brightness = 0;          ledState[ledCtr].dimrate = 0; // zero dimrate so we stop dimming it        } else {          // need to stop at 255.          ledState[ledCtr].brightness = 255;          ledState[ledCtr].dimrate = 0; // zero dimrate.        }        analogWrite(ledCtr, ledState[ledCtr].brightness);      }     }  }    // Have 60 seconds elapsed? We need to restart if so.  if (millis() - kickoff > 60000) {    kickoff = millis();    sceneCtr = 0;  }}`

#### marco_c

#22
##### Aug 16, 2012, 04:18 pm
My mistake. I thought you had 'received' something else/more. Thanks for reposting.
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

#### Chagrin

#23
##### Aug 16, 2012, 06:33 pm
If you needed a longer time period you'd need to change the "command" struct "time" data type to something larger. That of course eats up more memory.

You could also scale up the time to 10x the actual time, assuming you can settle for .01 millisecond accuracy of when you want to change LED activities. That would just require:

Code: [Select]
`if (scene[sceneCtr].time * 10 <= millis() - kickoff) {`

There are so many ways to approach a problem like this. I was just doing my best at aiming for a clear, straightforward solution.

#### Tom-Kristensen

#24
##### Aug 17, 2012, 03:43 am
With a little more testing under the belt I wonder if I have hit the ceiling with the Uno microprocessor. I wired up three more LEDs to my board to test multi fading on the 6 PWM pins, 3,5,6,9,10,11. It seems that I can have PWM action on 3,5,6 but not on 9,10,11. I can get switching on 9,10,11. Before I order up more processing power I thought I would check with people interested in this thread.

Here is the code I have been running. The code preserves the original settings posted by Chagrin except that I have increased MILLIDIMSTEP from 10 to 75 to produce longer fades. And of course I have declared the extra PWM pins along with a string of new commands.

Code: [Select]
`/*Fade up and down on multiple pinsCode written by Chagrin August 2012*/#define LED1 3 // assign the first LED to pin 3#define LED2 5 // assign the second LED to pin 5, etc...#define LED3 6#define LED4 9 #define LED5 10 #define LED6 11#define MAXPINNUMBER 6 // LED6 is the highest pin number -- number 6#define MILLISPERDIMSTEP 75 // LED dimming is recalculated every X millis// Group LED commands into a structure (struct)struct command {  byte pin;          // 0 to 255  unsigned int time; // 0 to 65535  byte brightness;   // 0 to 255  char dimrate;      // -127 to 128};// The stored state of each LED; holds state of dimming.struct state {  unsigned int time;  byte brightness;  byte dimrate;};// Create the scene which is an array of "command" structsstruct command scene[] = {  {LED1,0,255,0},  {LED2,0,255,0},  {LED3,0,255,0},  {LED4,0,255,0},  {LED5,0,255,0},  {LED6,0,0,0},  {LED1,900,255,-2},  {LED6,1000,255,-2},  {LED2,8000,255,-1},  {LED1,15000,0,2},  {LED3,27000,255,-5},  {LED1,29000,255,-2},   {LED1,40000,255,0},   {LED1,40100,0,0},   {LED1,41000,255,0},  {LED1,41100,0,0},   {LED1,42000,255,0},  {LED1,42100,0,0},   {LED1,43000,255,0},  {LED1,43100,0,0},   {LED1,44000,255,0},  {LED1,44100,0,0},   {LED1,45000,255,0},  {LED1,45100,0,0},   {LED1,46000,255,0},  {LED1,46100,0,0},   {LED1,47000,255,0},  {LED1,47100,0,0},  {LED4,48300,255,-5},  {LED5,48400,255,-5},  {LED6,48500,255,-5},  {LED1,49000,0,1},  {LED2,49100,0,2},  {LED3,49200,0,3},};// Initialize the LED states to off. Note 0 to MAXPINNUMBER is (MAXPINNUMBER + 1) states.struct state ledState[MAXPINNUMBER + 1] = {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}};void setup(){}void loop(){  static unsigned long kickoff = 0;  static unsigned int sceneCtr = 0;  byte ledCtr = 0;  // wait for a button press here to kick off the scene if desired  // Check the scene to see if we have a new command  if (sceneCtr < sizeof(scene) / sizeof(command)) {    if (scene[sceneCtr].time <= millis() - kickoff) {      analogWrite(scene[sceneCtr].pin, scene[sceneCtr].brightness);      if (scene[sceneCtr].dimrate != 0) {        // It dims; we have to add this to our ledState array and keep track of it.        ledState[scene[sceneCtr].pin].time = scene[sceneCtr].time + MILLISPERDIMSTEP;        ledState[scene[sceneCtr].pin].brightness = scene[sceneCtr].brightness;        ledState[scene[sceneCtr].pin].dimrate = scene[sceneCtr].dimrate;               }      sceneCtr += 1;    }  }    // Here we process through all the LEDs in a dimming state  for (ledCtr = 0; ledCtr < MAXPINNUMBER + 1; ledCtr++) {    if (ledState[ledCtr].dimrate != 0) { // only LEDs with a dimming are messed with.      if (ledState[ledCtr].time <= millis() - kickoff) {        if (ledState[ledCtr].brightness + (char) ledState[ledCtr].dimrate >= 0 &&            ledState[ledCtr].brightness + (char) ledState[ledCtr].dimrate <= 255) {          ledState[ledCtr].brightness += (char) ledState[ledCtr].dimrate;          ledState[ledCtr].time += MILLISPERDIMSTEP; // mark the time of next LED adjustment        } else if (ledState[ledCtr].brightness + (char) ledState[ledCtr].dimrate < 0) {          // need to stop at zero and not a negative number.          ledState[ledCtr].brightness = 0;          ledState[ledCtr].dimrate = 0; // zero dimrate so we stop dimming it        } else {          // need to stop at 255.          ledState[ledCtr].brightness = 255;          ledState[ledCtr].dimrate = 0; // zero dimrate.        }        analogWrite(ledCtr, ledState[ledCtr].brightness);      }     }  }    // Have 60 seconds elapsed? We need to restart if so.  if (millis() - kickoff > 60000) {    kickoff = millis();    sceneCtr = 0;  }}`
The code begins with all lights on except that there is a one second delay on LED6 (pin11) this is to help identify the begining of the scene when it loops. After 900 millis LED1 begins a slow fade, 100millis later LED6 is commanded to begin the same fade. LED1 fades nicely, but LED6 remains on full bright. Then follows a series of slow fades  on LED1,2,3 which all execute nicely. At 40 seconds LED1 begins flashing leading to a set of commands to test LEDs 4,5,6. At this point, 48 seconds, the sketch reverts to kickoff rather than fading the last three LEDs. Interestingly, an additional three last commands to fade up LEDs 1,2,3 do not execute. The last 12 seconds of the sketch is lost. Who knows where the time goes?

#### Chagrin

#25
##### Aug 17, 2012, 05:25 am
Code: [Select]
`#define MAXPINNUMBER 11 // LED11 is the highest pin number`

so that the code knows to manage dimming for those higher pins and

Code: [Select]
`// Initialize the LED states to off. Note 0 to MAXPINNUMBER is (MAXPINNUMBER + 1) states.struct state ledState[MAXPINNUMBER + 1] = {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}};`

you have to create a storage area to store the states of those pins.

#### Tom-Kristensen

#26
##### Aug 17, 2012, 06:20 am
Excellent! Works perfectly. I should have thought a little bit harder, I thought the six pins under management were the PMW pins only. I now see that the storage role of the struct state ledState[MAXPINNUMBER + 1] covers all pins, though not quite sure about the +1 -something to do with how the counter works I suppose. Anyway, I'm just the driver, not the mechanic.

Since there are actually 11 pins being managed the next step is to insert some commands for the non PMW pins and see how they perform with simple on/off tasks.

I have everything I asked for as far as this basic Uno board goes, but I do have 12 circuits to control and this board will only stretch to 6 fading channels. I have been looking into the add-on options for the Uno and there is a plug-in TLC5940 shield that will boost my PWM pins from 6 to 16. Or I could buy a bigger board, the Arduino Mega2560 has 14 PWM pins. The TLC chips deliver more power off the board, but from my reading this may not be good thing. I think it is safer to deliver power via transistors than rely on the proccessor to do the thinking and the heavy lifting. Since I want my installation to keep running for years I am trying to engineer things to keep cool.

So, is there any reason why this excellent code would not expand to meet the capabilities of the Arduino Mega? I think it will.

#### Tom-Kristensen

#27
##### Aug 18, 2012, 01:45 am
So. The code works with the digital pins as well as the analogue pins. Only one surprise, it seems the digital pins deliver more power to the LED. My digital LED is burning significantly brighter than the analogue pins at 255. This adds weight to my decision to use transistors to deliver power.

I have ordered an Arduino mega board to see if I can get more PWM action.

#### Tom-Kristensen

#28
##### Aug 22, 2012, 12:22 am
My Arduino megao board will arrive today - I got a card telling me its waiting at the post office. Jumping the gun here, but I'm pretty confident I will soon have my 12 channels of individually controlled lighting.

My little Uno board has been faithfully looping through my 60 second lightshow for 7 channels (6 PWM, 1 digital) ever since I installed the code some days ago. It looks beautiful. For anyone who missed the code earlier here it is. I have included commands for the scene I am running.

A simple code to allow individual fading of lights within a 60 second loop:
Code: [Select]
`/*Fade up and down on multiple pinsCode written by Chagrin August 2012*/#define LED1 3 // assign the first LED to pin 3#define LED2 5 // assign the second LED to pin 5, etc...#define LED3 6#define LED4 9 #define LED5 10 #define LED6 11#define LED7 1#define MAXPINNUMBER 11 // LED11 is the highest pin number#define MILLISPERDIMSTEP 75 // LED dimming is recalculated every X millis// Group LED commands into a structure (struct)struct command {  byte pin;          // 0 to 255  unsigned int time; // 0 to 65535  byte brightness;   // 0 to 255  char dimrate;      // -127 to 128};// The stored state of each LED; holds state of dimming.struct state {  unsigned int time;  byte brightness;  byte dimrate;};// Create the scene which is an array of "command" structsstruct command scene[] = {  {LED1,0,255,0},  {LED2,0,255,0},  {LED3,0,255,0},  {LED4,0,255,0},  {LED5,0,255,0},  {LED6,0,0,0},  {LED7,0,255,0},  {LED1,1000,255,-2},  {LED6,1000,255,0},  {LED5,0,0,0},  {LED2,8000,255,-1},  {LED1,15000,0,2},  {LED3,27000,255,-5},   {LED7,2700,0,0},  {LED1,29000,255,-2},   {LED1,40000,255,0},   {LED1,40100,0,0},   {LED1,41000,255,0},  {LED1,41100,0,0},   {LED1,42000,255,0},  {LED1,42100,0,0},   {LED1,43000,255,0},  {LED1,43100,0,0},   {LED1,44000,255,0},  {LED1,44100,0,0},   {LED1,45000,255,0},  {LED1,45100,0,0},   {LED1,46000,255,0},  {LED1,46100,0,0},   {LED1,47000,255,0},  {LED1,47100,0,0},  {LED4,48000,0,0},  {LED5,48000,0,0},  {LED6,48000,0,0},  {LED4,48100,255,-4},  {LED5,48100,255,-3},  {LED6,48100,255,-2},  {LED1,49000,0,2},  {LED2,49100,0,4},  {LED3,49200,0,3},};// Initialize the LED states to off. Note 0 to MAXPINNUMBER is (MAXPINNUMBER + 1) states.struct state ledState[MAXPINNUMBER + 1] = {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}};void setup(){}void loop(){  static unsigned long kickoff = 0;  static unsigned int sceneCtr = 0;  byte ledCtr = 0;  // wait for a button press here to kick off the scene if desired  // Check the scene to see if we have a new command  if (sceneCtr < sizeof(scene) / sizeof(command)) {    if (scene[sceneCtr].time <= millis() - kickoff) {      analogWrite(scene[sceneCtr].pin, scene[sceneCtr].brightness);      if (scene[sceneCtr].dimrate != 0) {        // It dims; we have to add this to our ledState array and keep track of it.        ledState[scene[sceneCtr].pin].time = scene[sceneCtr].time + MILLISPERDIMSTEP;        ledState[scene[sceneCtr].pin].brightness = scene[sceneCtr].brightness;        ledState[scene[sceneCtr].pin].dimrate = scene[sceneCtr].dimrate;               }      sceneCtr += 1;    }  }    // Here we process through all the LEDs in a dimming state  for (ledCtr = 0; ledCtr < MAXPINNUMBER + 1; ledCtr++) {    if (ledState[ledCtr].dimrate != 0) { // only LEDs with a dimming are messed with.      if (ledState[ledCtr].time <= millis() - kickoff) {        if (ledState[ledCtr].brightness + (char) ledState[ledCtr].dimrate >= 0 &&            ledState[ledCtr].brightness + (char) ledState[ledCtr].dimrate <= 255) {          ledState[ledCtr].brightness += (char) ledState[ledCtr].dimrate;          ledState[ledCtr].time += MILLISPERDIMSTEP; // mark the time of next LED adjustment        } else if (ledState[ledCtr].brightness + (char) ledState[ledCtr].dimrate < 0) {          // need to stop at zero and not a negative number.          ledState[ledCtr].brightness = 0;          ledState[ledCtr].dimrate = 0; // zero dimrate so we stop dimming it        } else {          // need to stop at 255.          ledState[ledCtr].brightness = 255;          ledState[ledCtr].dimrate = 0; // zero dimrate.        }        analogWrite(ledCtr, ledState[ledCtr].brightness);      }     }  }    // Have 60 seconds elapsed? We need to restart if so.  if (millis() - kickoff > 60000) {    kickoff = millis();    sceneCtr = 0;  }}`

So my next challenge will be controlling my lights remotely. I need to start studying. I understand I will need to provide my mega board with an ethernet shield. From this point on I am clueless. Any tips on where I should go next would be greatly appreciated.

#### Tom-Kristensen

#29
##### Aug 24, 2012, 04:28 pmLast Edit: Aug 25, 2012, 12:11 am by Tom-Kristensen Reason: 1
So, I'm still struggling with uploading the Chagrin code -as posted in the last post- onto my Mega 2560 board. I can upload the blink sketch and I have the little on-board LED happily blinking away. But when I try the longer code the upload fails to complete. LED 13 continues to blink and there are momentary occasional flashes from the TX and RX LEDs until some minutes pass and the upload attempt has failed. These are the messages I get from the Arduino IDE:
Code: [Select]
`Binary sketch size: 2,510 bytes (of a 258,048 byte maximum)avrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_getsync(): timeout communicating with programmeravrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_getsync(): timeout communicating with programmeravrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_getsync(): timeout communicating with programmeravrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_getsync(): timeout communicating with programmeravrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_getsync(): timeout communicating with programmeravrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_getsync(): timeout communicating with programmeravrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_getsync(): timeout communicating with programmeravrdude: stk500v2_command(): failed miserably to execute command 0x10avrdude: initialization failed, rc=-1         Double check connections and try again, or use -F to override         this check.avrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_getsync(): timeout communicating with programmeravrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_getsync(): timeout communicating with programmeravrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_getsync(): timeout communicating with programmeravrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_getsync(): timeout communicating with programmeravrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_getsync(): timeout communicating with programmeravrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_ReceiveMessage(): timeoutavrdude: stk500v2_getsync(): timeout communicating with programmeravrdude: stk500v2_command(): failed miserably to execute command 0x11avrdude: stk500v2_disable(): failed to leave programming mode`
I am running a 2007 macbook pro with OS 10.4.11. Admittedly it is getting long in the tooth, I use an external keyboard since the onboard one is faulty - so one of my USB ports is given over to the keys. RAM is also running short. But still I don't understand why I can upload this code onto my Uno board but not onto the Mega. And I can upload the blink example onto the Mega but not the longer code. To me this is mysterious.

Go Up