share for RS

Fork of rbVectorIQ by Mark @RRVA

Committer:
MarkSPA
Date:
Mon Jun 19 18:12:42 2017 +0000
Revision:
16:4fca60460b7e
Parent:
patterns.cpp@13:047bbd59f351
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MarkSPA 4:c8515fbd2e44 1 #include "mbed.h" // remove line if not using mbed
MarkSPA 4:c8515fbd2e44 2
MarkSPA 4:c8515fbd2e44 3 #include <stdbool.h>
MarkSPA 4:c8515fbd2e44 4 #include <stdint.h>
MarkSPA 4:c8515fbd2e44 5 #include <stdlib.h>
MarkSPA 4:c8515fbd2e44 6 #include "nrf_delay.h"
MarkSPA 4:c8515fbd2e44 7 #include "nrf_gpio.h"
MarkSPA 4:c8515fbd2e44 8 #include "neopixel.h"
MarkSPA 4:c8515fbd2e44 9
MarkSPA 4:c8515fbd2e44 10 // Input a value 0 to 255 to get a color value.
MarkSPA 4:c8515fbd2e44 11 // The colours are a transition r - g - b - back to r.
MarkSPA 4:c8515fbd2e44 12 uint32_t Wheel(uint8_t WheelPos, neopixel_strip_t m_strip, uint8_t led_to_enable) {
MarkSPA 4:c8515fbd2e44 13 WheelPos = 255 - WheelPos;
MarkSPA 4:c8515fbd2e44 14 if(WheelPos < 85) {
MarkSPA 4:c8515fbd2e44 15 return neopixel_set_color(&m_strip, led_to_enable, 255 - WheelPos * 3, 0, WheelPos * 3);
MarkSPA 4:c8515fbd2e44 16 }
MarkSPA 4:c8515fbd2e44 17 if(WheelPos < 170) {
MarkSPA 4:c8515fbd2e44 18 WheelPos -= 85;
MarkSPA 4:c8515fbd2e44 19 return neopixel_set_color(&m_strip, 0, led_to_enable, WheelPos * 3, 255 - WheelPos * 3);
MarkSPA 4:c8515fbd2e44 20 }
MarkSPA 4:c8515fbd2e44 21 WheelPos -= 170;
MarkSPA 4:c8515fbd2e44 22 return neopixel_set_color(&m_strip, led_to_enable, WheelPos * 3, 255 - WheelPos * 3, 0);
MarkSPA 4:c8515fbd2e44 23 }
MarkSPA 4:c8515fbd2e44 24
MarkSPA 4:c8515fbd2e44 25 void rainbowCycle(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) {
MarkSPA 7:0db51a3107fc 26 uint16_t i, j;
MarkSPA 7:0db51a3107fc 27 uint32_t ret;
MarkSPA 4:c8515fbd2e44 28
MarkSPA 7:0db51a3107fc 29 for(j=0; j<256; j++) {
MarkSPA 7:0db51a3107fc 30 for(i=0; i<numLEDs; i++) {
MarkSPA 7:0db51a3107fc 31 //neopixel_set_color(&m_strip, i, Wheel((i+j) & 255));
MarkSPA 7:0db51a3107fc 32 ret = Wheel((i+j) & 255, m_strip, i);
MarkSPA 4:c8515fbd2e44 33 }
MarkSPA 4:c8515fbd2e44 34 neopixel_show(&m_strip);
MarkSPA 4:c8515fbd2e44 35 wait_ms(delay);
MarkSPA 4:c8515fbd2e44 36 }
MarkSPA 4:c8515fbd2e44 37 }
MarkSPA 4:c8515fbd2e44 38
MarkSPA 4:c8515fbd2e44 39 void candyChase(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) {
MarkSPA 6:074f5ec7428c 40
MarkSPA 6:074f5ec7428c 41 for (int i=0; i < numLEDs; i++)
MarkSPA 6:074f5ec7428c 42 neopixel_set_color(&m_strip, i, 255,255,255); //turn every pixel white
MarkSPA 6:074f5ec7428c 43
MarkSPA 6:074f5ec7428c 44 for (int i=0; i < numLEDs-1; i++) {
MarkSPA 6:074f5ec7428c 45 neopixel_set_color(&m_strip, i, 255,255,255);
MarkSPA 6:074f5ec7428c 46 neopixel_set_color(&m_strip, i+1, 255,0,0); //turn on a red pixel and move it
MarkSPA 6:074f5ec7428c 47 neopixel_show(&m_strip);
MarkSPA 6:074f5ec7428c 48 wait_ms(delay);
MarkSPA 4:c8515fbd2e44 49 }
MarkSPA 6:074f5ec7428c 50 wait_ms(delay);
MarkSPA 6:074f5ec7428c 51
MarkSPA 6:074f5ec7428c 52 for (int i=0; i < numLEDs; i++)
MarkSPA 6:074f5ec7428c 53 neopixel_set_color(&m_strip, i, 255,0,0); //turn every pixel red
MarkSPA 6:074f5ec7428c 54
MarkSPA 6:074f5ec7428c 55 for (int i=0; i < numLEDs-1; i++) {
MarkSPA 6:074f5ec7428c 56 neopixel_set_color(&m_strip, i, 255,0,0);
MarkSPA 6:074f5ec7428c 57 neopixel_set_color(&m_strip, i+1, 255,255,255); //turn on a white pixel and move it
MarkSPA 6:074f5ec7428c 58 neopixel_show(&m_strip);
MarkSPA 6:074f5ec7428c 59 wait_ms(delay);
MarkSPA 6:074f5ec7428c 60 }
MarkSPA 4:c8515fbd2e44 61 }
MarkSPA 4:c8515fbd2e44 62
MarkSPA 4:c8515fbd2e44 63 void snowflakes(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) {
MarkSPA 4:c8515fbd2e44 64
MarkSPA 6:074f5ec7428c 65 for (int i=0; i < numLEDs; i++)
MarkSPA 6:074f5ec7428c 66 neopixel_set_color(&m_strip, i, 0,0,235); //turn every pixel blue
MarkSPA 6:074f5ec7428c 67
MarkSPA 6:074f5ec7428c 68 for (int i=0; i < numLEDs-1; i++) {
MarkSPA 6:074f5ec7428c 69 neopixel_set_color(&m_strip, i, 0,0,235);
MarkSPA 6:074f5ec7428c 70 neopixel_set_color(&m_strip, i+1, 255,255,255); //turn on a white pixel and move it
MarkSPA 4:c8515fbd2e44 71 neopixel_show(&m_strip);
MarkSPA 6:074f5ec7428c 72 wait_ms(delay);
MarkSPA 4:c8515fbd2e44 73 }
MarkSPA 4:c8515fbd2e44 74 }
MarkSPA 4:c8515fbd2e44 75
MarkSPA 7:0db51a3107fc 76 void collegiate(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) {
MarkSPA 7:0db51a3107fc 77
MarkSPA 7:0db51a3107fc 78 for (int i=0; i < numLEDs; i++)
MarkSPA 7:0db51a3107fc 79 neopixel_set_color(&m_strip, i, 224,193,36); //turn every pixel gold
MarkSPA 7:0db51a3107fc 80
MarkSPA 7:0db51a3107fc 81 for (int i=0; i < numLEDs-1; i++) {
MarkSPA 7:0db51a3107fc 82 neopixel_set_color(&m_strip, i, 224,193,36);
MarkSPA 7:0db51a3107fc 83 neopixel_set_color(&m_strip, i+1, 0,255,0); //turn on a green pixel and move it
MarkSPA 7:0db51a3107fc 84 neopixel_show(&m_strip);
MarkSPA 7:0db51a3107fc 85 wait_ms(delay);
MarkSPA 7:0db51a3107fc 86 }
MarkSPA 7:0db51a3107fc 87 wait_ms(delay);
MarkSPA 7:0db51a3107fc 88
MarkSPA 7:0db51a3107fc 89 for (int i=0; i < numLEDs; i++)
MarkSPA 7:0db51a3107fc 90 neopixel_set_color(&m_strip, i, 0,255,0); //turn every pixel green
MarkSPA 7:0db51a3107fc 91
MarkSPA 7:0db51a3107fc 92 for (int i=0; i < numLEDs-1; i++) {
MarkSPA 7:0db51a3107fc 93 neopixel_set_color(&m_strip, i, 0,255,0);
MarkSPA 7:0db51a3107fc 94 neopixel_set_color(&m_strip, i+1, 224,193,36); //turn on a gold pixel and move it
MarkSPA 7:0db51a3107fc 95 neopixel_show(&m_strip);
MarkSPA 7:0db51a3107fc 96 wait_ms(delay);
MarkSPA 7:0db51a3107fc 97 }
MarkSPA 7:0db51a3107fc 98 }
MarkSPA 7:0db51a3107fc 99
MarkSPA 4:c8515fbd2e44 100 void iceflakes(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) {
MarkSPA 9:02ac9f6bb320 101 uint8_t led;
MarkSPA 11:45f76d2b5b8c 102
MarkSPA 11:45f76d2b5b8c 103 for (uint8_t i=0; i < numLEDs; i++)
MarkSPA 6:074f5ec7428c 104 neopixel_set_color(&m_strip, i, 235,235,235); //turn every pixel white
MarkSPA 6:074f5ec7428c 105
MarkSPA 9:02ac9f6bb320 106 led = rand()%numLEDs;
MarkSPA 9:02ac9f6bb320 107 neopixel_set_color(&m_strip, led, 0, 0, 235); // set random blue
MarkSPA 6:074f5ec7428c 108 neopixel_show(&m_strip);
MarkSPA 9:02ac9f6bb320 109 wait_ms(delay);
MarkSPA 6:074f5ec7428c 110 }
MarkSPA 5:1f6311e0fc14 111
MarkSPA 5:1f6311e0fc14 112 void xmas(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) {
MarkSPA 5:1f6311e0fc14 113 //All green
MarkSPA 5:1f6311e0fc14 114 for (int j=0; j<numLEDs; j++)
MarkSPA 5:1f6311e0fc14 115 neopixel_set_color(&m_strip, j, 0,255,0);
MarkSPA 5:1f6311e0fc14 116 neopixel_show(&m_strip);
MarkSPA 7:0db51a3107fc 117 wait_ms(1000);
MarkSPA 5:1f6311e0fc14 118 //All red
MarkSPA 5:1f6311e0fc14 119 for (int j=0; j<numLEDs; j++)
MarkSPA 5:1f6311e0fc14 120 neopixel_set_color(&m_strip, j, 255,0,0);
MarkSPA 5:1f6311e0fc14 121 neopixel_show(&m_strip);
MarkSPA 7:0db51a3107fc 122 wait_ms(1000);
MarkSPA 5:1f6311e0fc14 123 //Green with a red mover
MarkSPA 5:1f6311e0fc14 124 for (int j=0; j<numLEDs; j++)
MarkSPA 5:1f6311e0fc14 125 neopixel_set_color(&m_strip, j, 0,255,0);
MarkSPA 5:1f6311e0fc14 126 neopixel_show(&m_strip);
MarkSPA 6:074f5ec7428c 127 wait_ms(500);
MarkSPA 5:1f6311e0fc14 128 for (int j=0; j<numLEDs; j++)
MarkSPA 5:1f6311e0fc14 129 {
MarkSPA 5:1f6311e0fc14 130 neopixel_set_color(&m_strip, j, 255,0,0);
MarkSPA 5:1f6311e0fc14 131 neopixel_show(&m_strip);
MarkSPA 5:1f6311e0fc14 132 wait_ms(delay);
MarkSPA 5:1f6311e0fc14 133 }
MarkSPA 5:1f6311e0fc14 134 //Red with a green mover
MarkSPA 5:1f6311e0fc14 135 for (int j=0; j<numLEDs; j++)
MarkSPA 5:1f6311e0fc14 136 neopixel_set_color(&m_strip, j, 255,0,0);
MarkSPA 5:1f6311e0fc14 137 neopixel_show(&m_strip);
MarkSPA 5:1f6311e0fc14 138 wait_ms(delay);
MarkSPA 5:1f6311e0fc14 139 for (int j=0; j<numLEDs; j++)
MarkSPA 5:1f6311e0fc14 140 {
MarkSPA 5:1f6311e0fc14 141 neopixel_set_color(&m_strip, j, 0,255,0);
MarkSPA 5:1f6311e0fc14 142 neopixel_show(&m_strip);
MarkSPA 5:1f6311e0fc14 143 wait_ms(delay);
MarkSPA 5:1f6311e0fc14 144 }
MarkSPA 8:e275405a431d 145 }
MarkSPA 8:e275405a431d 146
MarkSPA 8:e275405a431d 147 void irondude(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) {
MarkSPA 8:e275405a431d 148
MarkSPA 8:e275405a431d 149 for (int i=0; i < numLEDs; i++)
MarkSPA 8:e275405a431d 150 neopixel_set_color(&m_strip, i, 255,255,255); //turn every pixel white
MarkSPA 8:e275405a431d 151
MarkSPA 8:e275405a431d 152 for (int i=0; i < numLEDs; i++) {
MarkSPA 8:e275405a431d 153 neopixel_set_color(&m_strip, i, 255,0,0); //change whites to reds
MarkSPA 8:e275405a431d 154 neopixel_show(&m_strip);
MarkSPA 8:e275405a431d 155 wait_ms(delay);
MarkSPA 8:e275405a431d 156 }
MarkSPA 8:e275405a431d 157 wait_ms(delay);
MarkSPA 8:e275405a431d 158
MarkSPA 8:e275405a431d 159 for (int i=0; i <= numLEDs; i++) {
MarkSPA 8:e275405a431d 160 neopixel_set_color(&m_strip, numLEDs - i, 255,255,255); //change reds to white, in reverse
MarkSPA 8:e275405a431d 161 neopixel_show(&m_strip);
MarkSPA 8:e275405a431d 162 wait_ms(delay);
MarkSPA 8:e275405a431d 163 }
MarkSPA 13:047bbd59f351 164 }
MarkSPA 13:047bbd59f351 165
MarkSPA 13:047bbd59f351 166 void easter(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) {
MarkSPA 13:047bbd59f351 167 //All purple
MarkSPA 13:047bbd59f351 168 for (int j=0; j<numLEDs; j++)
MarkSPA 13:047bbd59f351 169 neopixel_set_color(&m_strip, j, 102,0,102);
MarkSPA 13:047bbd59f351 170 neopixel_show(&m_strip);
MarkSPA 13:047bbd59f351 171 wait_ms(1000);
MarkSPA 13:047bbd59f351 172 //All white
MarkSPA 13:047bbd59f351 173 for (int j=0; j<numLEDs; j++)
MarkSPA 13:047bbd59f351 174 neopixel_set_color(&m_strip, j, 255,255,255);
MarkSPA 13:047bbd59f351 175 neopixel_show(&m_strip);
MarkSPA 13:047bbd59f351 176 wait_ms(1000);
MarkSPA 13:047bbd59f351 177 //All gold
MarkSPA 13:047bbd59f351 178 for (int j=0; j<numLEDs; j++)
MarkSPA 13:047bbd59f351 179 neopixel_set_color(&m_strip, j, 255,204,0);
MarkSPA 13:047bbd59f351 180 neopixel_show(&m_strip);
MarkSPA 13:047bbd59f351 181 wait_ms(1000);
MarkSPA 13:047bbd59f351 182 }
MarkSPA 13:047bbd59f351 183
MarkSPA 13:047bbd59f351 184 void spring(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) {
MarkSPA 13:047bbd59f351 185 //All pink
MarkSPA 13:047bbd59f351 186 for (int j=0; j<numLEDs; j++)
MarkSPA 13:047bbd59f351 187 neopixel_set_color(&m_strip, j, 255,102,255);
MarkSPA 13:047bbd59f351 188 neopixel_show(&m_strip);
MarkSPA 13:047bbd59f351 189 wait_ms(1000);
MarkSPA 13:047bbd59f351 190 //All blue
MarkSPA 13:047bbd59f351 191 for (int j=0; j<numLEDs; j++)
MarkSPA 13:047bbd59f351 192 neopixel_set_color(&m_strip, j, 153,204,255);
MarkSPA 13:047bbd59f351 193 neopixel_show(&m_strip);
MarkSPA 13:047bbd59f351 194 wait_ms(1000);
MarkSPA 13:047bbd59f351 195 //All green
MarkSPA 13:047bbd59f351 196 for (int j=0; j<numLEDs; j++)
MarkSPA 13:047bbd59f351 197 neopixel_set_color(&m_strip, j, 153,255,153);
MarkSPA 13:047bbd59f351 198 neopixel_show(&m_strip);
MarkSPA 13:047bbd59f351 199 wait_ms(1000);
MarkSPA 13:047bbd59f351 200 //All yellow
MarkSPA 13:047bbd59f351 201 for (int j=0; j<numLEDs; j++)
MarkSPA 13:047bbd59f351 202 neopixel_set_color(&m_strip, j, 255,255,153);
MarkSPA 13:047bbd59f351 203 neopixel_show(&m_strip);
MarkSPA 13:047bbd59f351 204 wait_ms(1000);
MarkSPA 13:047bbd59f351 205 }
MarkSPA 13:047bbd59f351 206
MarkSPA 13:047bbd59f351 207 void memorial(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) {
MarkSPA 13:047bbd59f351 208 //All red
MarkSPA 13:047bbd59f351 209 for (int j=0; j<numLEDs; j++)
MarkSPA 13:047bbd59f351 210 neopixel_set_color(&m_strip, j, 255,0,0);
MarkSPA 13:047bbd59f351 211 neopixel_show(&m_strip);
MarkSPA 13:047bbd59f351 212 wait_ms(1000);
MarkSPA 13:047bbd59f351 213 //All white
MarkSPA 13:047bbd59f351 214 for (int j=0; j<numLEDs; j++)
MarkSPA 13:047bbd59f351 215 neopixel_set_color(&m_strip, j, 255,255,255);
MarkSPA 13:047bbd59f351 216 neopixel_show(&m_strip);
MarkSPA 13:047bbd59f351 217 wait_ms(1000);
MarkSPA 13:047bbd59f351 218 //All blue
MarkSPA 13:047bbd59f351 219 for (int j=0; j<numLEDs; j++)
MarkSPA 13:047bbd59f351 220 neopixel_set_color(&m_strip, j, 0,0,255);
MarkSPA 13:047bbd59f351 221 neopixel_show(&m_strip);
MarkSPA 13:047bbd59f351 222 wait_ms(1000);
MarkSPA 4:c8515fbd2e44 223 }