This an example of using a light strip of individually addressable RGB LEDs to make a star for a Christmas decoration. Two meters of APA102 LED stripe were used, cut every 12 LEDs. Code runs on a MicroMite with power provided by a large external power supply.
Project by RonnS.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
Option autorun on Option DEFAULT NONE option explicit cpu 48 randomize timer Dim integer count, count1, counter,counterB, rndnum, loopcount, offset, w0, w10, w11,speed,Ledcounter2,Ledcounter1 Dim INTEGER HOW_MANY_LEDS=120 Dim integer red1, red,bgR Dim integer green1, green,bgG Dim integer blue1, blue ,bgB dim integer LedCounterA,leds_armsA dim integer LedCounterB,leds_armsB dim integer LedCounterC,leds_armsC dim integer BRIGHTNESS :BRIGHTNESS = 30 bgR=002: bgG=001: bgB=000 red1=250: green1=151: blue1=000 dim integer colours(28)=(003, 000, 227, 255, 000, 220, 059, 000, 199, 087, 000, 157, 115, 000, 145, 135, 000, 135, 059, 000, 199, 031, 000, 227, 003, 000, 255, 255, 000) data 255,000,003,227,000,031,199,000,059,171,000,087,143,000,115,000,000,171,059,000,199,031,000,227,003,000,255,255,000,003, 227,000,031,199 data 000,059,255,000,003,227,000,031,199,000,059,115,000,000,171,059,000,199,031,000,227,003,000,255,255,000 SPI open 5000000, 3,8 speed=150 head for w0 = 0 To HOW_MANY_LEDS sendled 000, 000, 000 next tail Pause 100 Sub sendLed (red as integer,green as integer,blue as integer) ' Send a LED controlling command SPI write 4, 225, blue,green,red End Sub Sub Head ' Send the start of data header SPI write 4, &H00,&H00,&H00,&H00 End Sub Sub tail 'Send the end of data tail SPI write 4, &HFF,&HFF,&HFF,&HFF End Sub sub getcolour red = Int(RND()*10)+1 red1 = red * 10 and 10 + 100 green = Int(RND()*10)+1 green1 = green * 10 and 10 +100 blue = Int(RND()*10)+1 blue1 = blue * 10 and 10 +100 rem print blue1;green1;red1 end sub PowerOnReset: do count1=0 do count1=count1+1 LedcounterB=11 LedCounterA=0 'first segment for counter=1 to 11 step 2 ledcounterA = ledcounterA + counter LedCounterB = LedCounterB - counter pause speed head 'from the middle to the ends for loopcount = 0 to 4 ' loop 5 time for the arms for w10=0 to LedcounterB sendled 002, 001, 000 next for w11=1 to LedCounterA sendled 210,105,030 next for w11=1 to LedCounterA sendled 210,105,030 next for w10=0 to LedcounterB sendled 002, 001, 000 next next loopcount tail next counter loop until count1 > 2 do count1=count1+1 LedcounterB=11 LedCounterA=0 'first segment for counter=1 to 11 step 2 ledcounterA = ledcounterA + counter LedCounterB = LedCounterB - counter pause speed head 'from the middle to the ends for loopcount = 0 to 4 ' loop 5 time for the arms getcolour for w10=0 to LedcounterB sendled 002, 001, 000 next for w11=1 to LedCounterA sendled red1,green1,blue1 next for w11=1 to LedCounterA sendled red1,green1,blue1 next for w10=0 to LedcounterB sendled 002, 001, 000 next next loopcount tail next counter loop until count1 > 20 rotate: count1=0 leds_armsA=12: leds_armsB=12 LedcounterB=12 LedCounterA=1 counter=1 do getcolour count1= count1+1 head 'first arm 0 for w10=1 to 12 sendled red1,green1,blue1 next for w11 = 13 To HOW_MANY_LEDS-12 sendLed bgR, bgG, bgB ' to last = Off next for w10=HOW_MANY_LEDS-11 to HOW_MANY_LEDS sendled red1,green1,blue1 next tail for counter=1 to 9 step 2 ledcounterA = counter*leds_armsA counterB=counter+2 LedCounterB = counterB*leds_armsB head 'second arm 1 for w11 = 1 To LedCounterA sendled bgR, bgG, bgB next for w10=LedCounterA to LedCounterB sendled red1,green1,blue1 next for w11 = LedCounterB To HOW_MANY_LEDs sendled bgR, bgG, bgB next tail next rem leds_armsA=12:leds_armsB=12:LedcounterB=12:LedCounterA=1:counter=1 pause speed loop until count1>20 loop |
Leave a Reply