Inhaltsverzeichnis

BASCOM WS2812 Knightrider

rainbow_ws2812_Knightrider

  1. '-------------------------------------------------------------------------------
  2. ' rainbow_ws2812_Knightrider.bas
  3. ' based on sample from Galahat
  4. '-------------------------------------------------------------------------------
  5. $Regfile = "m88pdef.dat"
  6. $Crystal = 8000000
  7. $hwstack = 40
  8. $swstack = 16
  9. $framesize = 32
  10.  
  11. Config RAINBOW=1, RB0_LEN=8, RB0_PORT=PORTB,rb0_pin=0
  12. ' ^ connected to pin 0
  13. ' ^------------ connected to portB
  14. ' ^-------------------------- 8 leds on stripe
  15. ' ^------------------------------------- 1 channel
  16.  
  17.  
  18. 'Global Color-variables
  19. Dim Color(3) as Byte
  20. R alias Color(_base) : G alias Color(_base + 1) : B alias Color(_base + 2)
  21.  
  22. 'CONST
  23. const numLeds=8
  24.  
  25. '----[MAIN]---------------------------------------------------------------------
  26. Dim n as Byte
  27.  
  28. RB_SelectChannel 0 ' select first channel
  29. R = 50 : G = 0 : B = 100 ' define a color
  30. RB_SetColor 0 , color(1) ' update leds
  31. RB_Send
  32.  
  33. Do
  34. For n = 1 to Numleds-1
  35. rb_Shiftright 0 , Numleds 'shift to the right all leds except the last one
  36. Waitms 100
  37. RB_Send
  38. Next
  39. For n = 1 to Numleds-1
  40. rb_Shiftleft 0 , Numleds 'shift to the left all leds except the last one
  41. Waitms 100
  42. RB_Send
  43. Next
  44. waitms 500 'wait a bit
  45. Loop

rainbow_ws2812_KnightriderDual-RGBW

  1. '-------------------------------------------------------------------------------
  2. ' rainbow_ws2812_KnightriderDual-RGBW.bas
  3. ' based on sample from Galahat
  4. '-------------------------------------------------------------------------------
  5. $Regfile = "m88pdef.dat"
  6. $Crystal = 8000000
  7. $hwstack = 40
  8. $swstack = 16
  9. $framesize = 32
  10.  
  11. Config RAINBOW = 1 , rgb = 4 , RB0_LEN = 8 , RB0_PORT = PORTB , rb0_pin = 0
  12. ' ^-- using rgbW leds #### MUST BE FIRST PARAMETER when defined ###
  13. ' ^ connected to pin 0
  14. ' ^------------ connected to portB
  15. ' ^-------------------------- 8 leds on stripe
  16. ' ^------------------------------------- 1 channel
  17.  
  18.  
  19. 'Global Color-variables
  20. Dim Color(4) as Byte
  21. R alias Color(_base) : G alias Color(_base + 1) : B alias Color(_base + 2) : W alias color(_base + 3)
  22.  
  23. 'CONST
  24. const numLeds = 8
  25.  
  26. '----[MAIN]---------------------------------------------------------------------
  27. Dim n as Byte
  28.  
  29. RB_SelectChannel 0 ' select first channel
  30. R = 50 : G = 0 : B = 100 : w = 10 ' define a color
  31. RB_SetColor 0 , color(_base) ' update led on the left
  32. RB_SetColor numleds - 1 , color(_base) ' update led on the right
  33. RB_Send
  34. waitms 2000
  35.  
  36. Do
  37. For n = 1 to Numleds / 2 - 1
  38. rb_Shiftright 0 , Numleds / 2 'shift to the right
  39. rb_Shiftleft Numleds / 2 , Numleds / 2 'shift to the left all leds except the last one
  40. Waitms 1000
  41. RB_Send
  42. Next
  43. For n = 1 to Numleds/2 - 1
  44. rb_Shiftleft 0 , Numleds / 2 'shift to the left all leds except the last one
  45. rb_Shiftright Numleds / 2 , Numleds / 2 'shift to the right
  46. Waitms 1000
  47. RB_Send
  48. Next
  49. waitms 500 'wait a bit
  50. Loop