Initial (buggy) version

Dependencies:   BLE_API mbed nRF51822

Fork of nRF51822_SimpleControls by RedBearLab

Committer:
MarkSPA
Date:
Fri Dec 09 15:50:13 2016 +0000
Revision:
6:074f5ec7428c
Parent:
5:1f6311e0fc14
Child:
7:0db51a3107fc
Fixed up most of the patterns

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 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 6:074f5ec7428c 41
MarkSPA 6:074f5ec7428c 42 for (int i=0; i < numLEDs; i++)
MarkSPA 6:074f5ec7428c 43 neopixel_set_color(&m_strip, i, 255,255,255); //turn every pixel white
MarkSPA 6:074f5ec7428c 44
MarkSPA 6:074f5ec7428c 45 for (int i=0; i < numLEDs-1; i++) {
MarkSPA 6:074f5ec7428c 46 neopixel_set_color(&m_strip, i, 255,255,255);
MarkSPA 6:074f5ec7428c 47 neopixel_set_color(&m_strip, i+1, 255,0,0); //turn on a red pixel and move it
MarkSPA 6:074f5ec7428c 48 neopixel_show(&m_strip);
MarkSPA 6:074f5ec7428c 49 wait_ms(delay);
MarkSPA 4:c8515fbd2e44 50 }
MarkSPA 6:074f5ec7428c 51 wait_ms(delay);
MarkSPA 6:074f5ec7428c 52
MarkSPA 6:074f5ec7428c 53 for (int i=0; i < numLEDs; i++)
MarkSPA 6:074f5ec7428c 54 neopixel_set_color(&m_strip, i, 255,0,0); //turn every pixel red
MarkSPA 6:074f5ec7428c 55
MarkSPA 6:074f5ec7428c 56 for (int i=0; i < numLEDs-1; i++) {
MarkSPA 6:074f5ec7428c 57 neopixel_set_color(&m_strip, i, 255,0,0);
MarkSPA 6:074f5ec7428c 58 neopixel_set_color(&m_strip, i+1, 255,255,255); //turn on a white pixel and move it
MarkSPA 6:074f5ec7428c 59 neopixel_show(&m_strip);
MarkSPA 6:074f5ec7428c 60 wait_ms(delay);
MarkSPA 6:074f5ec7428c 61 }
MarkSPA 4:c8515fbd2e44 62 }
MarkSPA 4:c8515fbd2e44 63
MarkSPA 4:c8515fbd2e44 64 void snowflakes(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) {
MarkSPA 4:c8515fbd2e44 65
MarkSPA 6:074f5ec7428c 66 for (int i=0; i < numLEDs; i++)
MarkSPA 6:074f5ec7428c 67 neopixel_set_color(&m_strip, i, 0,0,235); //turn every pixel blue
MarkSPA 6:074f5ec7428c 68
MarkSPA 6:074f5ec7428c 69 for (int i=0; i < numLEDs-1; i++) {
MarkSPA 6:074f5ec7428c 70 neopixel_set_color(&m_strip, i, 0,0,235);
MarkSPA 6:074f5ec7428c 71 neopixel_set_color(&m_strip, i+1, 255,255,255); //turn on a white pixel and move it
MarkSPA 4:c8515fbd2e44 72 neopixel_show(&m_strip);
MarkSPA 6:074f5ec7428c 73 wait_ms(delay);
MarkSPA 4:c8515fbd2e44 74 }
MarkSPA 4:c8515fbd2e44 75 }
MarkSPA 4:c8515fbd2e44 76
MarkSPA 4:c8515fbd2e44 77 void iceflakes(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) {
MarkSPA 4:c8515fbd2e44 78
MarkSPA 6:074f5ec7428c 79 for (int i=0; i < numLEDs; i++)
MarkSPA 6:074f5ec7428c 80 neopixel_set_color(&m_strip, i, 235,235,235); //turn every pixel white
MarkSPA 6:074f5ec7428c 81
MarkSPA 6:074f5ec7428c 82 int led_to_enable = rand()%numLEDs;
MarkSPA 6:074f5ec7428c 83 neopixel_set_color(&m_strip, led_to_enable, 0, 0, 235); // set random blue
MarkSPA 6:074f5ec7428c 84 neopixel_show(&m_strip);
MarkSPA 6:074f5ec7428c 85 wait_ms(delay);
MarkSPA 6:074f5ec7428c 86 }
MarkSPA 5:1f6311e0fc14 87
MarkSPA 5:1f6311e0fc14 88 void xmas(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) {
MarkSPA 5:1f6311e0fc14 89 //All green
MarkSPA 5:1f6311e0fc14 90 for (int j=0; j<numLEDs; j++)
MarkSPA 5:1f6311e0fc14 91 neopixel_set_color(&m_strip, j, 0,255,0);
MarkSPA 5:1f6311e0fc14 92 neopixel_show(&m_strip);
MarkSPA 6:074f5ec7428c 93 wait_ms(500);
MarkSPA 5:1f6311e0fc14 94 //All red
MarkSPA 5:1f6311e0fc14 95 for (int j=0; j<numLEDs; j++)
MarkSPA 5:1f6311e0fc14 96 neopixel_set_color(&m_strip, j, 255,0,0);
MarkSPA 5:1f6311e0fc14 97 neopixel_show(&m_strip);
MarkSPA 5:1f6311e0fc14 98 wait_ms(delay);
MarkSPA 5:1f6311e0fc14 99 //Green with a red mover
MarkSPA 5:1f6311e0fc14 100 for (int j=0; j<numLEDs; j++)
MarkSPA 5:1f6311e0fc14 101 neopixel_set_color(&m_strip, j, 0,255,0);
MarkSPA 5:1f6311e0fc14 102 neopixel_show(&m_strip);
MarkSPA 6:074f5ec7428c 103 wait_ms(500);
MarkSPA 5:1f6311e0fc14 104 for (int j=0; j<numLEDs; j++)
MarkSPA 5:1f6311e0fc14 105 {
MarkSPA 5:1f6311e0fc14 106 neopixel_set_color(&m_strip, j, 255,0,0);
MarkSPA 5:1f6311e0fc14 107 neopixel_show(&m_strip);
MarkSPA 5:1f6311e0fc14 108 wait_ms(delay);
MarkSPA 5:1f6311e0fc14 109 }
MarkSPA 5:1f6311e0fc14 110 //Red with a green mover
MarkSPA 5:1f6311e0fc14 111 for (int j=0; j<numLEDs; j++)
MarkSPA 5:1f6311e0fc14 112 neopixel_set_color(&m_strip, j, 255,0,0);
MarkSPA 5:1f6311e0fc14 113 neopixel_show(&m_strip);
MarkSPA 5:1f6311e0fc14 114 wait_ms(delay);
MarkSPA 5:1f6311e0fc14 115 for (int j=0; j<numLEDs; j++)
MarkSPA 5:1f6311e0fc14 116 {
MarkSPA 5:1f6311e0fc14 117 neopixel_set_color(&m_strip, j, 0,255,0);
MarkSPA 5:1f6311e0fc14 118 neopixel_show(&m_strip);
MarkSPA 5:1f6311e0fc14 119 wait_ms(delay);
MarkSPA 5:1f6311e0fc14 120 }
MarkSPA 4:c8515fbd2e44 121 }