CONFIG RAINBOW

From MCS Wiki AVR
Revision as of 21:27, 15 June 2015 by Admin (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

Action

This configuration command sets up the number of rainbow channels and their ports & pins.

 

 

Syntax

CONFIG RAINBOW=channels, RBx_LEN=leds, RBx_PORT=port, RBx_PIN=pin

 

Remarks

Channels

The number of channels. This is a numeric value in the range from 1-8.

RBx_LEN

The number of LED's for the channel. The minimum number of leds is 1. Each LED is made of 3 colors : R(ed), G(reen), and B(lue). A byte array named RAINBOW0_ will be created with a size of len * 3. Thus RB0_LEN=8 will create an array of RAINBOW0_(24).

RBx_PORT

The name of the PORT which is connected to the DI of the rainbow led(stripe). This is a port like PORTB.

RBx_PIN

The pin number of the port pin which is connected to the DI of the rainbow led(stripe). This is a number between 0-7.

  • The x should be replaced by a numeric value from 0-7.

 

 

Rainbow leds come in different forms and shapes. There are single LED, stripes with 8 leds, round circles with 24 leds, etc. All have a built in WS2812 RGB controller. The nice thing is that you can cascade leds by connecting the DO (output) to another DI (input). These stripes only requires 5V, GND and DI. You can connect different stripes to different port pins.

 

The original rainbow library is written by Galahat from the German bascom-forum. It is an excellent example on how to write your own libraries.

The MCS version is for the BASCOM integrated statements and functions. It is named rainbowBSC.lib. The lib uses a few routines from mcs.lib

 

noticeA minimum CPU-speed of 8 MHz is required. Tests with  WS1812b- types showed, it also works with frequencies down to 6.5 MHz because of the tolerance bandwidth by the chips.


 

 

See also

RB_ADDCOLOR , RB_ANDCOLOR , RB_ORCOLOR, RB_SUBCOLOR, RB_CLEARSTRIPE , RB_CLEARCOLORS , RB_FILL , RB_FILLCOLORS , RB_FILLSTRIPE , RB_SELECTCHANNEL , RB_SEND, RB_SETCOLOR , RB_SWAPCOLOR , RB_ROTATELEFT , RB_ROTATERIGHT , RB_SHIFTLEFT , RB_SHIFTRIGHT , RB_CHANGEPIN , RB_SETTABLECOLOR , RB_GETCOLOR , RB_LOOKUPCOLOR

Example

'-------------------------------------------------------------------------------
' rainbow_ws2812_Knightrider.bas
' based on sample from Galahat
'-------------------------------------------------------------------------------
$Regfile = "m88pdef.dat"
$Crystal = 8000000
$hwstack = 40
$swstack = 16
$framesize = 32
 
Config RAINBOW=1, RB0_LEN=8, RB0_PORT=PORTB,rb0_pin=0
' ^ connected to pin 0
' ^------------ connected to portB
' ^-------------------------- 8 leds on stripe
' ^------------------------------------- 1 channel
 
 
'Global Color-variables
Dim Color(3) as Byte
R alias Color(_base) : G alias Color(_base + 1) : B alias Color(_base + 2)
 
'CONST
const numLeds=8
 
'----[MAIN]---------------------------------------------------------------------
Dim n as Byte
 
RB_SelectChannel 0 ' select first channel
R = 50 : G = 0 : B = 100 ' define a color
RB_SetColor 0 , color(1) ' update leds
RB_Send
 
Do
 For n = 1 to Numleds-1
 rb_Shiftright 0 , Numleds 'shift to the right all leds except the last one
 Waitms 100
 RB_Send
 Next
 For n = 1 to Numleds-1
 rb_Shiftleft 0 , Numleds 'shift to the left all leds except the last one
 Waitms 100
 RB_Send
 Next
 waitms 500 'wait a bit
Loop
Languages   English  
Personal tools
Namespaces
Variants
Actions
Navigation
Language