RadiantRVA
/
rbVectorIQ
share for RS
Fork of rbVectorIQ by
patterns.cpp@4:c8515fbd2e44, 2016-11-28 (annotated)
- Committer:
- MarkSPA
- Date:
- Mon Nov 28 15:38:58 2016 +0000
- Revision:
- 4:c8515fbd2e44
- Child:
- 5:1f6311e0fc14
Initial (buggy) version
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 | 4:c8515fbd2e44 | 26 | uint16_t i, j; |
MarkSPA | 4:c8515fbd2e44 | 27 | uint32_t ret; |
MarkSPA | 4:c8515fbd2e44 | 28 | |
MarkSPA | 4:c8515fbd2e44 | 29 | for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel |
MarkSPA | 4:c8515fbd2e44 | 30 | for(i=0; i< numLEDs; i++) { |
MarkSPA | 4:c8515fbd2e44 | 31 | //neopixel_set_color(&m_strip, i, red, green, blue); |
MarkSPA | 4:c8515fbd2e44 | 32 | //strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255)); |
MarkSPA | 4:c8515fbd2e44 | 33 | ret = Wheel(i, m_strip, ((i * 256 / numLEDs) + j & 255)); |
MarkSPA | 4:c8515fbd2e44 | 34 | } |
MarkSPA | 4:c8515fbd2e44 | 35 | neopixel_show(&m_strip); |
MarkSPA | 4:c8515fbd2e44 | 36 | wait_ms(delay); |
MarkSPA | 4:c8515fbd2e44 | 37 | } |
MarkSPA | 4:c8515fbd2e44 | 38 | } |
MarkSPA | 4:c8515fbd2e44 | 39 | |
MarkSPA | 4:c8515fbd2e44 | 40 | void candyChase(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) { |
MarkSPA | 4:c8515fbd2e44 | 41 | for (int j=0; j<10; j++) { //do 10 cycles of chasing |
MarkSPA | 4:c8515fbd2e44 | 42 | for (int q=0; q < 3; q++) { |
MarkSPA | 4:c8515fbd2e44 | 43 | for (uint16_t i=0; i < numLEDs; i++) { |
MarkSPA | 4:c8515fbd2e44 | 44 | neopixel_set_color(&m_strip, i, 255,255,255); //turn every pixel white |
MarkSPA | 4:c8515fbd2e44 | 45 | } |
MarkSPA | 4:c8515fbd2e44 | 46 | for (uint16_t i=0; i < numLEDs; i=i+3) { |
MarkSPA | 4:c8515fbd2e44 | 47 | neopixel_set_color(&m_strip, i, 255,0,0); //turn every third pixel red |
MarkSPA | 4:c8515fbd2e44 | 48 | } |
MarkSPA | 4:c8515fbd2e44 | 49 | neopixel_show(&m_strip); |
MarkSPA | 4:c8515fbd2e44 | 50 | |
MarkSPA | 4:c8515fbd2e44 | 51 | wait_ms(delay); |
MarkSPA | 4:c8515fbd2e44 | 52 | |
MarkSPA | 4:c8515fbd2e44 | 53 | for (uint16_t i=0; i < numLEDs; i=i+3) { |
MarkSPA | 4:c8515fbd2e44 | 54 | neopixel_set_color(&m_strip, i, 0,0,0); //turn every third pixel off |
MarkSPA | 4:c8515fbd2e44 | 55 | } |
MarkSPA | 4:c8515fbd2e44 | 56 | } |
MarkSPA | 4:c8515fbd2e44 | 57 | } |
MarkSPA | 4:c8515fbd2e44 | 58 | } |
MarkSPA | 4:c8515fbd2e44 | 59 | |
MarkSPA | 4:c8515fbd2e44 | 60 | void snowflakes(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) { |
MarkSPA | 4:c8515fbd2e44 | 61 | |
MarkSPA | 4:c8515fbd2e44 | 62 | // Setup the pixel array |
MarkSPA | 4:c8515fbd2e44 | 63 | int pixel[numLEDs]; |
MarkSPA | 4:c8515fbd2e44 | 64 | for(int p=0; p<numLEDs; p++) |
MarkSPA | 4:c8515fbd2e44 | 65 | pixel[p] = rand()%255; |
MarkSPA | 4:c8515fbd2e44 | 66 | |
MarkSPA | 4:c8515fbd2e44 | 67 | |
MarkSPA | 4:c8515fbd2e44 | 68 | // Run some snowflake cycles |
MarkSPA | 4:c8515fbd2e44 | 69 | for (int j=0; j<20; j++) { |
MarkSPA | 4:c8515fbd2e44 | 70 | // Every five cycles, light a new pixel |
MarkSPA | 4:c8515fbd2e44 | 71 | if((j%5)==0) |
MarkSPA | 4:c8515fbd2e44 | 72 | neopixel_set_color(&m_strip, rand()%numLEDs, 255,255,255); |
MarkSPA | 4:c8515fbd2e44 | 73 | |
MarkSPA | 4:c8515fbd2e44 | 74 | // Dim all pixels by 10 |
MarkSPA | 4:c8515fbd2e44 | 75 | for(int p=0; p<numLEDs; p++){ |
MarkSPA | 4:c8515fbd2e44 | 76 | neopixel_set_color(&m_strip, p, pixel[p],pixel[p],pixel[p] ); |
MarkSPA | 4:c8515fbd2e44 | 77 | pixel[p] = pixel[p] - 10; |
MarkSPA | 4:c8515fbd2e44 | 78 | } |
MarkSPA | 4:c8515fbd2e44 | 79 | neopixel_show(&m_strip); |
MarkSPA | 4:c8515fbd2e44 | 80 | wait_ms(delay); |
MarkSPA | 4:c8515fbd2e44 | 81 | } |
MarkSPA | 4:c8515fbd2e44 | 82 | } |
MarkSPA | 4:c8515fbd2e44 | 83 | |
MarkSPA | 4:c8515fbd2e44 | 84 | void iceflakes(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) { |
MarkSPA | 4:c8515fbd2e44 | 85 | |
MarkSPA | 4:c8515fbd2e44 | 86 | // Setup the pixel array |
MarkSPA | 4:c8515fbd2e44 | 87 | int pixel[numLEDs]; |
MarkSPA | 4:c8515fbd2e44 | 88 | for(int p=0; p<numLEDs; p++) |
MarkSPA | 4:c8515fbd2e44 | 89 | pixel[p] = rand()%255; |
MarkSPA | 4:c8515fbd2e44 | 90 | |
MarkSPA | 4:c8515fbd2e44 | 91 | // Run some snowflake cycles |
MarkSPA | 4:c8515fbd2e44 | 92 | for (int j=0; j<20; j++) { |
MarkSPA | 4:c8515fbd2e44 | 93 | // Every five cycles, light a new pixel |
MarkSPA | 4:c8515fbd2e44 | 94 | if((j%5)==0) |
MarkSPA | 4:c8515fbd2e44 | 95 | neopixel_set_color(&m_strip, rand()%numLEDs, 0,0,255); |
MarkSPA | 4:c8515fbd2e44 | 96 | |
MarkSPA | 4:c8515fbd2e44 | 97 | // Dim all pixels by 10 |
MarkSPA | 4:c8515fbd2e44 | 98 | for(int p=0; p<numLEDs; p++){ |
MarkSPA | 4:c8515fbd2e44 | 99 | neopixel_set_color(&m_strip, p, 0,0,pixel[p] ); |
MarkSPA | 4:c8515fbd2e44 | 100 | pixel[p] = pixel[p] - 10; |
MarkSPA | 4:c8515fbd2e44 | 101 | } |
MarkSPA | 4:c8515fbd2e44 | 102 | neopixel_show(&m_strip); |
MarkSPA | 4:c8515fbd2e44 | 103 | wait_ms(delay); |
MarkSPA | 4:c8515fbd2e44 | 104 | } |
MarkSPA | 4:c8515fbd2e44 | 105 | } |