RadiantRVA
/
rbVectorIQ
share for RS
Fork of rbVectorIQ by
Diff: patterns.cpp
- Revision:
- 4:c8515fbd2e44
- Child:
- 5:1f6311e0fc14
diff -r 823f105078c7 -r c8515fbd2e44 patterns.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/patterns.cpp Mon Nov 28 15:38:58 2016 +0000 @@ -0,0 +1,105 @@ +#include "mbed.h" // remove line if not using mbed + +#include <stdbool.h> +#include <stdint.h> +#include <stdlib.h> +#include "nrf_delay.h" +#include "nrf_gpio.h" +#include "neopixel.h" + +// Input a value 0 to 255 to get a color value. +// The colours are a transition r - g - b - back to r. +uint32_t Wheel(uint8_t WheelPos, neopixel_strip_t m_strip, uint8_t led_to_enable) { + WheelPos = 255 - WheelPos; + if(WheelPos < 85) { + return neopixel_set_color(&m_strip, led_to_enable, 255 - WheelPos * 3, 0, WheelPos * 3); + } + if(WheelPos < 170) { + WheelPos -= 85; + return neopixel_set_color(&m_strip, 0, led_to_enable, WheelPos * 3, 255 - WheelPos * 3); + } + WheelPos -= 170; + return neopixel_set_color(&m_strip, led_to_enable, WheelPos * 3, 255 - WheelPos * 3, 0); +} + +void rainbowCycle(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) { + uint16_t i, j; + uint32_t ret; + + for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel + for(i=0; i< numLEDs; i++) { + //neopixel_set_color(&m_strip, i, red, green, blue); + //strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255)); + ret = Wheel(i, m_strip, ((i * 256 / numLEDs) + j & 255)); + } + neopixel_show(&m_strip); + wait_ms(delay); + } +} + +void candyChase(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) { + for (int j=0; j<10; j++) { //do 10 cycles of chasing + for (int q=0; q < 3; q++) { + for (uint16_t i=0; i < numLEDs; i++) { + neopixel_set_color(&m_strip, i, 255,255,255); //turn every pixel white + } + for (uint16_t i=0; i < numLEDs; i=i+3) { + neopixel_set_color(&m_strip, i, 255,0,0); //turn every third pixel red + } + neopixel_show(&m_strip); + + wait_ms(delay); + + for (uint16_t i=0; i < numLEDs; i=i+3) { + neopixel_set_color(&m_strip, i, 0,0,0); //turn every third pixel off + } + } + } +} + +void snowflakes(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) { + + // Setup the pixel array + int pixel[numLEDs]; + for(int p=0; p<numLEDs; p++) + pixel[p] = rand()%255; + + + // Run some snowflake cycles + for (int j=0; j<20; j++) { + // Every five cycles, light a new pixel + if((j%5)==0) + neopixel_set_color(&m_strip, rand()%numLEDs, 255,255,255); + + // Dim all pixels by 10 + for(int p=0; p<numLEDs; p++){ + neopixel_set_color(&m_strip, p, pixel[p],pixel[p],pixel[p] ); + pixel[p] = pixel[p] - 10; + } + neopixel_show(&m_strip); + wait_ms(delay); + } +} + +void iceflakes(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) { + + // Setup the pixel array + int pixel[numLEDs]; + for(int p=0; p<numLEDs; p++) + pixel[p] = rand()%255; + + // Run some snowflake cycles + for (int j=0; j<20; j++) { + // Every five cycles, light a new pixel + if((j%5)==0) + neopixel_set_color(&m_strip, rand()%numLEDs, 0,0,255); + + // Dim all pixels by 10 + for(int p=0; p<numLEDs; p++){ + neopixel_set_color(&m_strip, p, 0,0,pixel[p] ); + pixel[p] = pixel[p] - 10; + } + neopixel_show(&m_strip); + wait_ms(delay); + } +} \ No newline at end of file