RadiantRVA
/
rbVectorIQ
share for RS
Fork of rbVectorIQ by
patterns.cpp@7:0db51a3107fc, 2016-12-15 (annotated)
- Committer:
- MarkSPA
- Date:
- Thu Dec 15 23:25:16 2016 +0000
- Revision:
- 7:0db51a3107fc
- Parent:
- 6:074f5ec7428c
- Child:
- 8:e275405a431d
Added a couple of patterns, changed behavior or connect/disconnect.
Who changed what in which revision?
User | Revision | Line number | New 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 | 4:c8515fbd2e44 | 101 | |
MarkSPA | 6:074f5ec7428c | 102 | for (int i=0; i < numLEDs; i++) |
MarkSPA | 6:074f5ec7428c | 103 | neopixel_set_color(&m_strip, i, 235,235,235); //turn every pixel white |
MarkSPA | 6:074f5ec7428c | 104 | |
MarkSPA | 6:074f5ec7428c | 105 | int led_to_enable = rand()%numLEDs; |
MarkSPA | 6:074f5ec7428c | 106 | neopixel_set_color(&m_strip, led_to_enable, 0, 0, 235); // set random blue |
MarkSPA | 6:074f5ec7428c | 107 | neopixel_show(&m_strip); |
MarkSPA | 6:074f5ec7428c | 108 | wait_ms(delay); |
MarkSPA | 6:074f5ec7428c | 109 | } |
MarkSPA | 5:1f6311e0fc14 | 110 | |
MarkSPA | 5:1f6311e0fc14 | 111 | void xmas(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) { |
MarkSPA | 5:1f6311e0fc14 | 112 | //All green |
MarkSPA | 5:1f6311e0fc14 | 113 | for (int j=0; j<numLEDs; j++) |
MarkSPA | 5:1f6311e0fc14 | 114 | neopixel_set_color(&m_strip, j, 0,255,0); |
MarkSPA | 5:1f6311e0fc14 | 115 | neopixel_show(&m_strip); |
MarkSPA | 7:0db51a3107fc | 116 | wait_ms(1000); |
MarkSPA | 5:1f6311e0fc14 | 117 | //All red |
MarkSPA | 5:1f6311e0fc14 | 118 | for (int j=0; j<numLEDs; j++) |
MarkSPA | 5:1f6311e0fc14 | 119 | neopixel_set_color(&m_strip, j, 255,0,0); |
MarkSPA | 5:1f6311e0fc14 | 120 | neopixel_show(&m_strip); |
MarkSPA | 7:0db51a3107fc | 121 | wait_ms(1000); |
MarkSPA | 5:1f6311e0fc14 | 122 | //Green with a red mover |
MarkSPA | 5:1f6311e0fc14 | 123 | for (int j=0; j<numLEDs; j++) |
MarkSPA | 5:1f6311e0fc14 | 124 | neopixel_set_color(&m_strip, j, 0,255,0); |
MarkSPA | 5:1f6311e0fc14 | 125 | neopixel_show(&m_strip); |
MarkSPA | 6:074f5ec7428c | 126 | wait_ms(500); |
MarkSPA | 5:1f6311e0fc14 | 127 | for (int j=0; j<numLEDs; j++) |
MarkSPA | 5:1f6311e0fc14 | 128 | { |
MarkSPA | 5:1f6311e0fc14 | 129 | neopixel_set_color(&m_strip, j, 255,0,0); |
MarkSPA | 5:1f6311e0fc14 | 130 | neopixel_show(&m_strip); |
MarkSPA | 5:1f6311e0fc14 | 131 | wait_ms(delay); |
MarkSPA | 5:1f6311e0fc14 | 132 | } |
MarkSPA | 5:1f6311e0fc14 | 133 | //Red with a green mover |
MarkSPA | 5:1f6311e0fc14 | 134 | for (int j=0; j<numLEDs; j++) |
MarkSPA | 5:1f6311e0fc14 | 135 | neopixel_set_color(&m_strip, j, 255,0,0); |
MarkSPA | 5:1f6311e0fc14 | 136 | neopixel_show(&m_strip); |
MarkSPA | 5:1f6311e0fc14 | 137 | wait_ms(delay); |
MarkSPA | 5:1f6311e0fc14 | 138 | for (int j=0; j<numLEDs; j++) |
MarkSPA | 5:1f6311e0fc14 | 139 | { |
MarkSPA | 5:1f6311e0fc14 | 140 | neopixel_set_color(&m_strip, j, 0,255,0); |
MarkSPA | 5:1f6311e0fc14 | 141 | neopixel_show(&m_strip); |
MarkSPA | 5:1f6311e0fc14 | 142 | wait_ms(delay); |
MarkSPA | 5:1f6311e0fc14 | 143 | } |
MarkSPA | 4:c8515fbd2e44 | 144 | } |