B4R Question Problem with RGB panel (or code maybe)

metheoneandonly

Member
Licensed User
Longtime User
I just got this RGB panel: http://www.ebay.com/itm/1PCS-WS2812...e=STRK:MEBIDX:IT&_trksid=p2055119.m1438.l2649

I've tested it and all LED's are working fine. Now, here is the code I'm having problems with:


#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public Serial1 As Serial
Dim LED As AdafruitNeoPixel
Dim n,r,g,b As Int
Dim c As ULong
Private raf As RandomAccessFile
Private buff(4) As Byte
End Sub

Private Sub AppStart
'AddLooper("LightShow")
raf.Initialize(buff, False)
Serial1.Initialize(256000)
Log("AppStart")
LED.Initialize(64,8,LED.NEO_GRB)
LED.SetBrightness(35)
For n=0 To 63
LED.SetPixelColor(n,0,0,0)
Next
LED.Show
Delay(100)

Log("RAM: ", AvailableRAM)
LightShow
End Sub

Sub LightShow

For n=0 To 63
c=GetByte(n)
ConvertToRGB(c)
LED.SetPixelColor(n,r,g,b)
Log("Red:",buff(1)," / Green:",buff(2)," / Blue:",buff(3))
'LED.Show
'Delay(1)
Next
LED.Show
Delay(250)
End Sub

Private Sub GetByte(Index As UInt) As Byte
Return RunNative("getdata", Index)
End Sub

Private Sub ConvertToRGB(color As ULong)
raf.WriteUlong32(color, 0)
r=buff(1)
g=buff(2)
b=buff(3)
End Sub
#if C
#include <avr/pgmspace.h>
const PROGMEM unsigned long data[] = { //change the data here
0xFFFFFFFF,8,8,8,8,8,8,8,
8,255,255,8,8,255,255,8,
8,255,255,8,8,255,255,8,
8,255,255,255,255,255,255,8,
8,255,255,8,8,255,255,8,
8,255,255,8,8,255,255,8,
8,8,255,255,255,255,8,8,
8,8,8,255,255,8,8,8
};

B4R::Object beo1;
B4R::Object* getdata(B4R::Object* o) {
return beo1.wrapNumber(pgm_read_byte_near(data + o->toLong()));
}
#end if

The problem is, it turns on only blue component of RGB LED's. What's wrong?
 

metheoneandonly

Member
Licensed User
Longtime User
Yes, it does work. Now I want to put some simple graphics into PROGMEM and I tried as in code I've put, but I'm not sure how to convert given values into RGB.
 
Upvote 0
Top