Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 21:46 26 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Error with WS2812 on RP2040_zero

Author Message
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3150
Posted: 02:20am 07 Jan 2024
Copy link to clipboard 
Print this post

Likely enough user error, but can anyone see what I'm doing wrong trying to randomly change the color on the WS2812 which is on the RP2040_zero?

> option list
PicoMite MMBasic Version 5.08.00b5
OPTION SYSTEM SPI GP10,GP11,GP12
OPTION DISPLAY 50, 120
OPTION SDCARD GP13

> list
Dim integer d%(15),e%(15)=(RGB(red), RGB(green), RGB(blue),0,0,0,0,0,0,0,0,0,0,0,0,0)
e%(5)=RGB(gold): e%(6)=RGB(magenta): e%(7)=RGB(brown): e%(8)=RGB(pink)
e%(9)=RGB(salmon): e%(10)=RGB(orange):e%(11)=RGB(grey):e%(12)=RGB(white)
e%(9)=RGB(salmon): e%(10)=RGB(orange):e%(11)=RGB(grey):e%(12)=RGB(white)
e%(13)=RGB(lightgrey): e%(14)=RGB(beige): e%(15)=0 ' black
Dim integer i,j,k,l,m,n

Do
 j=Rnd()*15
 d%(0)=e%(j)
 Device WS2812 b,gp16,1,d%()
 Pause 1000
Loop

> run
[11] Device WS2812 b,gp16,1,d%()
Error : Dimensions

>> ?hex$(d%(0))
D2D2D2
>

I started with the BITBANG command, but it was changed to DEVICE (as per the post for RC21). I don't know whether the WS2812 is O, B, or S, but I tried all three.

Hex D2D2D2 is the value for RGB(lightgrey).
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
ebbandflow
Newbie

Joined: 31/08/2023
Location: United States
Posts: 19
Posted: 04:12am 07 Jan 2024
Copy link to clipboard 
Print this post

hmm... maybe this?
Device WS2812 b,gp16,1,d%(0)
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9115
Posted: 08:20am 07 Jan 2024
Copy link to clipboard 
Print this post

n=1 is a special case to allow a simple variable to be used rather than an array. This is because there is a limitation in MMBasic that you can't have an array with only one element.

This gives a particular issue with some matrix calculations where an array with one of its dimensions having a cardinality of 1 would be very useful
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6792
Posted: 08:49am 07 Jan 2024
Copy link to clipboard 
Print this post

This definitely works on a RP204-Zero
Bitbang ws2812 b,gp16,1,rgb(red)

This was before DEVICE so I haven't tested that.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Zonker

Guru

Joined: 18/08/2012
Location: United States
Posts: 761
Posted: 11:54am 07 Jan 2024
Copy link to clipboard 
Print this post

This was a test I ran on a strip of 8 RGBW LED's...
The brightness values are set to "02" (very low) so the phone wouldn't freak out...  


' RGBW LED test (8 LED's)

Option explicit

Dim integer pattern1(7)=(&H00000002,&H00000200,&H00020000,&H02000000,&H00000002,&H00000200,&H00020000,&H02000000)
Dim integer pattern2(7)=(&H00000200,&H00020000,&H02000000,&H00000002,&H00000200,&H00020000,&H02000000,&H00000002)
Dim integer pattern3(7)=(&H00020000,&H02000000,&H00000002,&H00000200,&H00020000,&H02000000,&H00000002,&H00000200)
Dim integer pattern4(7)=(&H02000000,&H00000002,&H00000200,&H00020000,&H02000000,&H00000002,&H00000200,&H00020000)

SetPin gp22,dout

Do
Bitbang ws2812 w,gp22,8,pattern1()
Pause 1000
Bitbang ws2812 w,gp22,8,pattern2()
Pause 1000
Bitbang ws2812 w,gp22,8,pattern3()
Pause 1000
Bitbang ws2812 w,gp22,8,pattern4()
Pause 1000
Loop





This seemed to run OK on the Pico...  
I haven't tried the device command yet...
Edited 2024-01-07 21:59 by Zonker
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3150
Posted: 02:33pm 07 Jan 2024
Copy link to clipboard 
Print this post

  matherp said  n=1 is a special case to allow a simple variable to be used rather than an array.


Ok, thanks. I'll try it when I get to my desk.

EDIT: that did it, thanks.

~
Edited 2024-01-08 01:57 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024