Creating an Multiple LED Stepping pattern

BobTPH

Joined Jun 5, 2013
8,659
Here is the code I use in C for WS2812B. This is in XC16 on PIC24 or PIC33 with 8 MHz instruction cycle.


void one()
{
DATAOUT = 1;
__asm("NOP");
__asm("NOP");
__asm("NOP");
__asm("NOP");
__asm("NOP");
__asm("NOP");
DATAOUT = 0;
__asm("NOP");
__asm("NOP");
__asm("NOP");
}

void zero()
{
DATAOUT = 1;
__asm("NOP");
__asm("NOP");
DATAOUT = 0;
__asm("NOP");
__asm("NOP");
__asm("NOP");
__asm("NOP");
__asm("NOP");
__asm("NOP");
__asm("NOP");
}

void shift_out(unsigned char c)
{
if (c & 0x80) one(); else zero();
if (c & 0x40) one(); else zero();
if (c & 0x20) one(); else zero();
if (c & 0x10) one(); else zero();
if (c & 0x08) one(); else zero();
if (c & 0x04) one(); else zero();
if (c & 0x02) one(); else zero();
if (c & 0x01) one(); else zero();
}

void rgb(unsigned char r, unsigned char g, unsigned char b)
{
shift_out(g);
shift_out(r);
shift_out(b);
}


Handcrafted assembly code? I think not. I think it is pretty straightforward. The rgb function is called for each LED in the strinp, followed by a delay of 50usec or more to cause the strip to latch the new data.

And here is the code for the "one" function in bobl, a language I am developing whose father is Ada and mother is Java. This on is for a 16MHz instruction cycle, so, twice as many instructions.


-- this is tricky. It all depends on timing. I count on the fact
-- the compiler will generate exactly 1 instruction taking 1
-- cycle to execute. Thus this routine will keep the line high for
-- 14 cycles and low for 6 cycles. Which, with a 16 MHz instruction
-- clock translates to 875 usec high and 375 usec low. This is
-- within the WS2812B specs of 850 and 400 += 150 for the high
-- and low times.
static procedure one is
begin
portb.lat.b12 := 1;
portb.lat.b12 := 1;
portb.lat.b12 := 1;
portb.lat.b12 := 1;
portb.lat.b12 := 1;
portb.lat.b12 := 1;
portb.lat.b12 := 1;
portb.lat.b12 := 1;
portb.lat.b12 := 1;
portb.lat.b12 := 1;
portb.lat.b12 := 1;
portb.lat.b12 := 1;
portb.lat.b12 := 1;
portb.lat.b12 := 1;
portb.lat.b12 := 0;
portb.lat.b12 := 0;
portb.lat.b12 := 0;
portb.lat.b12 := 0;
portb.lat.b12 := 0;
portb.lat.b12 := 0;
end one;


Bob
 

Thread Starter

iONic

Joined Nov 16, 2007
1,662
It seems apparent that I have no takers for the work I am requesting. Learning to program efficiently to create this project, buying all the necessary hardware/software is really not a path I'd like to go down as the time involved, especially the learning, would stretch out way too far.

What I wanted to get out of the device was as follows:
I have nearly ZERO programming skills but am curious as to what it might take to create the effect I am looking for.
The project is for some art that I have yet to produce but will simulate the hours of a clock or, in this case, the direction of the sun. An example would be:
with a string of 60 LEDs, (possible even 120 LEDs, but we'll stick to 60 for the example) I would like to have10-15 of them Lit at any one time. As time steps forward, the trailing edge LED turns off as the leading Edge LED adds another lit LED. This should pretty closely follow a 12hr rotation so that the process repeats every 12 hours. Given this, there will be a time where there will be some LEDs lit at the beginning of the String and some lit at the end of the same string of LEDs. Given that the art may be 2ft x 2ft. many more LEDs may be required....depends on the LED spacing I would guess.

Controls:
  1. On/Off
  2. cycle color
  3. brightness +/-
  4. Jump current time by 1hr
  5. Jump current time by 5min

Since no one here has jumped at this opportunity (ha ha...burden i' sure you will say!) I am asking for your ideas on what forum I may go to to put forth my request for help.

Thanks
Brian
 
Top