In SX Microcontrollers, SX/B Compiler and SX-Key Tool, PJMonty wrote: Kevin, Yes, the fourth number is the "on" time. Bean's not much for comments in his code, but his variables provide clues as to his intent. This line: [code]READ colors+pos, dutyRed, dutyGreen, dutyBlue, duration[/code] Reads the "color table" with an offset of "pos" (short for "position" as in "position in the table"). The first three things it reads are all called "duty" followed by a color. The duty in this case refers to duty cycle which means the percentage of on time to off time. The last thing it reads is "duration", which refers to, well, the duration that each color is lit for. It's tricky to read someone else's code, so I imagine you looked at it as one big lump without comments and kind of scratched your head. As obvious as it may sound, the key is to take it a line at a time and step through as if you are the computer. Since Bean used good variable names, his intent could be inferred with some deductive reasoning as long as you didn't get overwhelmed at the start. Regarding longer on time, the way Bean has built his code, the duration is as long as it can be without changing the code. The key here is to extend the duration to be 16 bits instead of 8. This means the read statement would look something like this: [code]READ colors+pos, dutyRed, dutyGreen, dutyBlue, durLow, durHigh[/code] and the data statments would increase to something like this: [code]DATA 255, 0, 0, 255, 1[/code] "Duration" is now split into a low byte and a high byte. The low byte works the way it does now, with a maximum duration of 255. The high byte ("durHigh") can be thought of as the number of times you want to execute the low value. Finally, the loop would change to incorporate the high byte of the duration by doing something like this: [code] FOR durCntH = 1 to durHigh FOR durCntL = 1 to durLow UpdateLEDs NEXT NEXT[/code] Note that "durCnt" is now also split into two variables called "durCntL" and "durCntH", which refer to the high and low bytes. Do you see how the inner loop is still the same, but now we wrap that in a loop as well? This lets you multiply the time of "durLow" by "durHigh", thus extending your duration by up to 255 times. There are some "gotchas" with the code as written. For example, if "durhigh" is 0, then that outer loop will never execute, which means the inner loop will never execute, even if it has a value of 255. However, play with it and see if you can make this work. I think that there is a limit on the size of data tables in SX/B, so now that each DATA line has 5 elements, it might reduce the number lines you can have. I'm not an SX/B guy though, so don't quote me on that. Also, you'll have to change a variable name or two, and add a variable or two, but, as they always say in books, "I leave that as an exercise for the reader." Finally, the waveform from Bean's code would look like a square wave where the overall duration of each wave is constant, but the amount of on time to off time varies. [list]Thanks, PeterM[/list] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=118695#m120590 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)