![]() |
Forum Index : Microcontroller and PC projects : WS2812B LED with picoMite questions
Author | Message | ||||
Amnesie Guru ![]() Joined: 30/06/2020 Location: GermanyPosts: 538 |
Hello, I successfully connected a matrix of 4x4= 16 LEDs from type "WS2812B" to the picoMiteVGA (latest beta version). I've got two questions: 1st question: While playing with it, I've noticed that it seems to be not possible to only drive one single LED in that matrix of 16 LEDs with the example of the manual: DIM b%(4)=(RGB(red), Rgb(green), RGB(blue), RGB(Yellow), rgb(cyan)) SETPIN GP5, DOUT WS2812 B, GP0, 5, b%() To drive one LED after another I tried this: DIM b%(4)=(RGB(red), Rgb(green), RGB(blue), RGB(Yellow), rgb(cyan)) SETPIN GP5, DOUT WS2812 B, GP0, 5, b%() For led= 1 To 5 WS2812 B, GP0, led, b%() Next led And got the error: "Error: Dimensions" Solution is to start with led=2, but WHY? I want to light one led after another, starting by the very first. Hm.. Any ideas? 2nd question: In the manual I find nothing about controlling the brightness, so I guess that I need to control it with an additional transistor through PWM "manually"? I always thought that the WS2812 chip has some brightness adjusting capabilities. But this is the very first time I am using this chip... ![]() Greetings Daniel Edited 2025-05-28 01:14 by Amnesie |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10106 |
You need to send enough values for all the LED in the string each time. Otherwise just the first LED will light. To light them in sequence just adjust the contents of the array as required Just set the RGB level e.g. RGB(50,0,0) would be a dimmer red Edited 2025-05-28 01:38 by matherp |
||||
Amnesie Guru ![]() Joined: 30/06/2020 Location: GermanyPosts: 538 |
Even by filling the entire array for all 16 leds, it is not possible to start my FOR LOOP with the led value of 1, always "Error: Dimensions". I always have to enter at least 2 as a value. My code is: DIM b%(15)=(RGB(red), Rgb(green), RGB(blue), RGB(Yellow), RGB(red), Rgb(green), RGB(blue), RGB(Yellow), RGB(red), Rgb(green), RGB(blue), RGB(Yellow), RGB(red), Rgb(green), RGB(blue), RGB(Yellow)) SETPIN GP0, DOUT For led= 1 To 16 WS2812 B, GP0, led, b%() Next led I've played with: led= 0 To 15 .. Then the Error arises that only 1...256 is allowed... Ok.. led= 1 To 15 doesn't work either. led= 2 To 15 will work.. But skips the first LED... I am confused. Greetings Daniel Edited 2025-05-28 02:06 by Amnesie |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10106 |
You can't do it like that. Send the entire array each time and change its contents between each transfer. DIM b%(4)=(RGB(red), Rgb(green), RGB(blue), RGB(Yellow), rgb(cyan)) dim a%(4) SETPIN GP5, DOUT For led= 1 To 5 a%(led-1)=b%(led-1) WS2812 B, GP0, 5, a%() pause 1000 Next led |
||||
Amnesie Guru ![]() Joined: 30/06/2020 Location: GermanyPosts: 538 |
Peter, thank you a lot. I had to stare for 5 minutes at your code to really understand what is happening, never could have worked out this by myself! Thanks, it works now. It is one thing to read the manual, another is to really interpret and understand it without some examples. Greetings Daniel |
||||
Amnesie Guru ![]() Joined: 30/06/2020 Location: GermanyPosts: 538 |
Hi all, I played around and came up with some example code.. just to sum up some ideas and for later reference, if anyone also should run into this questions I had. 'IMPORTANT: "OPTION CONTINUATION LINES ON" must be set! ' 'This example shows how to illuminate each LED from a 4x4 LED matrix after another 'This isn't trivial, since the "16" in "WS2812 B, GP0, 16, a%()" can't be changed 'The array values itself must be changed instead! ' Dim b%(15)=(RGB(blue),RGB(red),RGB(green),RGB(blue),RGB(yellow),RGB(cyan),RGB(red) _ ,RGB(blue),RGB(red),RGB(green),RGB(blue),RGB(yellow),RGB(cyan),RGB(red),RGB(yellow) _ ,RGB(blue)) Dim a%(15) Dim c%(15)=(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) Dim integer red=0, green=0, blue=0 SetPin GP0, DOUT Do 'Illuminate one LED after another For led=1 To 16 a%(led-1)=b%(led-1) WS2812 B, GP0, 16, a%() Pause 100 Next led 'This next example shows how to clear the LEDs one after another, notice how to deal 'with the arrays! Pause 1000 For led=1 To 16 a%(led-1)=c%(led-1) WS2812 B, GP0, 16, a%() Pause 50 Next led Pause 1000 'This next example shows how to change the brightness of the first LED in red color For red=0 To 255 a%(0)=RGB(red,0,0) WS2812 B, GP0, 16, a%() Pause 10 Next red Pause 1000 'This next example shows how to change the brightness of the second LED in green color For green=0 To 255 a%(1)=RGB(0,green,0) WS2812 B, GP0, 16, a%() Pause 10 Next green Pause 1000 'This next example shows how to change the brightness of all LEDs in blue color '(fade in) For blue=0 To 255 a%(0)=RGB(0,0,blue) a%(1)=RGB(0,0,blue) a%(2)=RGB(0,0,blue) a%(3)=RGB(0,0,blue) a%(4)=RGB(0,0,blue) a%(5)=RGB(0,0,blue) a%(6)=RGB(0,0,blue) a%(7)=RGB(0,0,blue) a%(8)=RGB(0,0,blue) a%(9)=RGB(0,0,blue) a%(10)=RGB(0,0,blue) a%(11)=RGB(0,0,blue) a%(12)=RGB(0,0,blue) a%(13)=RGB(0,0,blue) a%(14)=RGB(0,0,blue) a%(15)=RGB(0,0,blue) WS2812 B, GP0, 16, a%() Pause 10 Next blue 'This next example shows how to change the brightness of all LEDs in blue color '(fade out) For blue=255 To 0 Step -1 a%(0)=RGB(0,0,blue) a%(1)=RGB(0,0,blue) a%(2)=RGB(0,0,blue) a%(3)=RGB(0,0,blue) a%(4)=RGB(0,0,blue) a%(5)=RGB(0,0,blue) a%(6)=RGB(0,0,blue) a%(7)=RGB(0,0,blue) a%(8)=RGB(0,0,blue) a%(9)=RGB(0,0,blue) a%(10)=RGB(0,0,blue) a%(11)=RGB(0,0,blue) a%(12)=RGB(0,0,blue) a%(13)=RGB(0,0,blue) a%(14)=RGB(0,0,blue) a%(15)=RGB(0,0,blue) WS2812 B, GP0, 16, a%() Pause 10 Next blue Pause 1000 Loop Greetings Daniel Edited 2025-05-28 08:23 by Amnesie |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2473 |
Saving a little typing. skip c%() 'This next example shows how to clear the LEDs one after another ... a%(led-1)=0 Using MATH SET 'This next example shows how to change the brightness of all LEDs in blue color '(fade out) For blue=255 To 0 Step -1 MATH SET RGB(0,0,blue), a%() WS2812 B, GP0, 16, a%() Pause 10 Next blue Pause 1000 Loop Edit. shorter still MATH SET 255, a%() 'green = 255<<8, red = 255<<16 for 50% MATH SET 127, a%() 'green = 127<<8, red = 127<<16 Edited 2025-05-28 10:13 by phil99 |
||||
Bill.b![]() Senior Member ![]() Joined: 25/06/2011 Location: AustraliaPosts: 234 |
This is a scrolling message using 4 8 x 8 WS2812B RGB displays The full message is loaded into an array then transferred to the display, then the array ins indexed 8 bytes then displayed again. The brightness of the LED is determined by the number in the array - 0 - Hex FF I find that Hex30 is bright enough for most applications. By combining differed values in the RED, Green Blue sections you can generate any colour you require - &h301000 = orange. hope this may be some help. Option autorun on OPTION DEFAULT NONE OPTION EXPLICIT DIM integer i, j, count,loop1, loop2, loop3, count2 diM integer LEDcolour1(660) dim integer tempbuff(24) For i = 0 To 632 Read LEDcolour1(i) Next i senddata do 'copy first row of leds into tempory buffer for loop3 = 0 to 8 tempbuff(loop3) = LEDcolour1(loop3) next loop3 for loop1 = 8 to 632 step 8 for loop2 = loop1 to loop1 + 8 LEDcolour1(loop2-8) = LEDcolour1(loop2) next loop2 PAUSE 2 next loop1 'load temproy buffer into last row of leds for loop3 = 0 to 8 LEDcolour1(loop3 + 632)= tempbuff(loop3) next loop3 senddata loop sub senddata SetPin GP5, DOUT Bitbang WS2812 B, GP5, 256, LEDcolour1() end sub ' ' ********************************************************************* ' -------------LED Number Side row ------------------------------------------ ' 1 2 3 4 5 6 7 8 ' 1 R G B| R G B |R G B| R G B| R G B| R G B| R G B| R G B| Data &h301000,&h000000,&h300000,&h300000,&h300000,&h300000,&h300000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h300000,&h000000,&h000000 Data &h301000,&h000000,&h000000,&h300000,&h300000,&h000000,&h000000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h300000,&h000000,&h000000 'M Data &h301000,&h000000,&h300000,&h300000,&h300000,&h300000,&h300000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Data &h301000,&h000000,&h300000,&h300000,&h300000,&h300000,&h300000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h300000,&h000000,&h300000,&h000000 Data &h301000,&h000000,&h300000,&h300000,&h000000,&h300000,&h000000,&h000000 'R Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Data &h301000,&h000000,&h300000,&h000000,&h000000,&h300000,&h000000,&h000000 Data &h301000,&h000000,&h300000,&h000000,&h300000,&h000000,&h300000,&h000000 Data &h301000,&h000000,&h000000,&h300000,&h000000,&h000000,&h300000,&h000000 'S Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Data &h301000,&h000000,&h003000,&h003000,&h003000,&h003000,&h003000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h003000,&h000000,&h003000,&h000000 'P Data &h301000,&h000000,&h000000,&h000000,&h000000,&h003000,&h000000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 ' 1 R G B| R G B |R G B| R G B| R G B| R G B| R G B| R G B| Data &h301000,&h000000,&h000000,&h003000,&h003000,&h003000,&h000000,&h000000 Data &h301000,&h000000,&h003000,&h000000,&h000000,&h000000,&h003000,&h000000 'O Data &h301000,&h000000,&h000000,&h003000,&h003000,&h003000,&h000000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h003000,&h000000 Data &h301000,&h000000,&h003000,&h003000,&h003000,&h003000,&h003000,&h000000 'T Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h003000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 ' 1 R G B| R G B |R G B| R G B| R G B| R G B| R G B| R G B| Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h003000,&h000000 Data &h301000,&h000000,&h003000,&h003000,&h003000,&h003000,&h003000,&h000000 'T Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h003000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Data &h301000,&h000000,&h003000,&h000000,&h000000,&h003000,&h000000,&h000000 Data &h301000,&h000000,&h003000,&h000000,&h003000,&h000000,&h003000,&h000000 'S Data &h301000,&h000000,&h000000,&h003000,&h000000,&h000000,&h003000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000030,&h000000 ' 1 R G B| R G B |R G B| R G B| R G B| R G B| R G B| R G B| .' Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000030 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h303000,&h000000 Data &h301000,&h000000,&h303000,&h303000,&h303000,&h303000,&h303000,&h000000 'T Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h303000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Data &h301000,&h000000,&h303000,&h303000,&h303000,&h303000,&h303000,&h000000 Data &h301000,&h000000,&h303000,&h000000,&h303000,&h000000,&h303000,&h000000 'E Data &h301000,&h000000,&h303000,&h000000,&h000000,&h000000,&h303000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 ' 1 R G B| R G B |R G B| R G B| R G B| R G B| R G B| R G B| Data &h301000,&h000000,&h303000,&h303000,&h303000,&h303000,&h000000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h303000,&h000000,&h303000,&h000000 'A Data &h301000,&h000000,&h303000,&h303000,&h303000,&h303000,&h000000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Data &h301000,&h000000,&h000000,&h000030,&h000030,&h000030,&h000000,&h000000 Data &h301000,&h000000,&h000030,&h000000,&h000000,&h000000,&h000030,&h000000 'C Data &h301000,&h000000,&h000030,&h000000,&h000000,&h000000,&h000030,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 ' 1 R G B| R G B |R G B| R G B| R G B| R G B| R G B| R G B| Data &h301000,&h000000,&h000030,&h000030,&h000030,&h000030,&h000030,&h000000 Data &h301000,&h000000,&h000030,&h000000,&h000000,&h000000,&h000000,&h000000 'U Data &h301000,&h000000,&h000030,&h000030,&h000030,&h000030,&h000030,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Data &h301000,&h000000,&h000030,&h000030,&h000030,&h000030,&h000030,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000030,&h000000,&h000030,&h000000 'P Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000030,&h000000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Data &h301000,&h000000,&h000030,&h000000,&h000000,&h000030,&h000000,&h000000 Data &h301000,&h000000,&h000030,&h000000,&h000030,&h000000,&h000030,&h000000 'S Data &h301000,&h000000,&h000000,&h000030,&h000000,&h000000,&h000030,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Data &h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Data &h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Data &h000000,&h003000,&h000000,&h000000,&h000000,&h000000,&h303030,&h000000 Data &h003000,&h000000,&h300030,&h300030,&h300030,&h303030,&h000000,&h303030 Data &h003000,&h300030,&h300030,&h300030,&h300030,&h000000,&h000000,&h000000 Data &h003000,&h300030,&h300030,&h300030,&h300030,&h000000,&h000000,&h000000 Data &h003000,&h300030,&h300030,&h300030,&h300030,&h000000,&h303030,&h000000 Data &h003000,&h000000,&h300030,&h300030,&h300030,&h303030,&h000000,&h303030 Data &h000000,&h003000,&h000030,&h000000,&h000030,&h000000,&h000000,&h000000 Data &h000000,&h000000,&h000000,&h000030,&h000000,&h000000,&h000000,&h000000 Data &h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Data &h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Data &h301000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000,&h000000 Bill Edited 2025-05-28 11:42 by Bill.b In the interests of the environment, this post has been constructed entirely from recycled electrons. |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 4940 |
Hi Bill, Will this be shown in your next Christmas Garden Light show ? I loved your last video. Man .. have you been busy building all these items. Volhout . PicomiteVGA PETSCII ROBOTS |
||||
Bill.b![]() Senior Member ![]() Joined: 25/06/2011 Location: AustraliaPosts: 234 |
Hi Volhout This program was used for the cupride last Christmas ![]() Bill In the interests of the environment, this post has been constructed entirely from recycled electrons. |
||||
Amnesie Guru ![]() Joined: 30/06/2020 Location: GermanyPosts: 538 |
Hello, I tested your examples, really impressive what MMBASIC is capable off! @ phil99 shorter still MATH SET 255, a%() 'green = 255<<8, red = 255<<16 for 50% MATH SET 127, a%() 'green = 127<<8, red = 127<<16 Even though you commented it for the other colors, I don't understand how this works... Is this some kind of bit-operation? Greetings Daniel |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2473 |
RGB(red,green,blue) can be regarded as a Function that returns a 24 bit number. Bill.B uses Hex numbers which make it easier to see. If you enter Print RGB(0,0,255), "&H";Hex$(RGB(0,0,255),6) you can see how it works. The 255<<8 and 255<<16 shift the bits of the number 255 to the left by 8 and 16 places producing the same 24 bit number as green and red. > Print RGB(0,0,255), "&H";Hex$(RGB(0,0,255),6) 255 &H0000FF > Print RGB(0,255,0), "&H";Hex$(255<<8,6), "&H";Hex$(RGB(0,255,0),6) 65280 &H00FF00 &H00FF00 > Print RGB(255,0,0), "&H";Hex$(255<<16,6), "&H";Hex$(RGB(255,0,0),6) 16711680 &HFF0000 &HFF0000 > |
||||
Amnesie Guru ![]() Joined: 30/06/2020 Location: GermanyPosts: 538 |
phil99, This is a REALLY good explanation, thank you very much - now I understand what happens! Pretty clever to do it this way! Greetings Daniel |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |