Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of rbVectorIQ by
patterns.cpp
00001 #include "mbed.h" // remove line if not using mbed 00002 00003 #include <stdbool.h> 00004 #include <stdint.h> 00005 #include <stdlib.h> 00006 #include "nrf_delay.h" 00007 #include "nrf_gpio.h" 00008 #include "neopixel.h" 00009 00010 // Input a value 0 to 255 to get a color value. 00011 // The colours are a transition r - g - b - back to r. 00012 uint32_t Wheel(uint8_t WheelPos, neopixel_strip_t m_strip, uint8_t led_to_enable) { 00013 WheelPos = 255 - WheelPos; 00014 if(WheelPos < 85) { 00015 return neopixel_set_color(&m_strip, led_to_enable, 255 - WheelPos * 3, 0, WheelPos * 3); 00016 } 00017 if(WheelPos < 170) { 00018 WheelPos -= 85; 00019 return neopixel_set_color(&m_strip, 0, led_to_enable, WheelPos * 3, 255 - WheelPos * 3); 00020 } 00021 WheelPos -= 170; 00022 return neopixel_set_color(&m_strip, led_to_enable, WheelPos * 3, 255 - WheelPos * 3, 0); 00023 } 00024 00025 void rainbowCycle(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) { 00026 uint16_t i, j; 00027 uint32_t ret; 00028 00029 for(j=0; j<256; j++) { 00030 for(i=0; i<numLEDs; i++) { 00031 //neopixel_set_color(&m_strip, i, Wheel((i+j) & 255)); 00032 ret = Wheel((i+j) & 255, m_strip, i); 00033 } 00034 neopixel_show(&m_strip); 00035 wait_ms(delay); 00036 } 00037 } 00038 00039 void candyChase(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) { 00040 00041 for (int i=0; i < numLEDs; i++) 00042 neopixel_set_color(&m_strip, i, 255,255,255); //turn every pixel white 00043 00044 for (int i=0; i < numLEDs-1; i++) { 00045 neopixel_set_color(&m_strip, i, 255,255,255); 00046 neopixel_set_color(&m_strip, i+1, 255,0,0); //turn on a red pixel and move it 00047 neopixel_show(&m_strip); 00048 wait_ms(delay); 00049 } 00050 wait_ms(delay); 00051 00052 for (int i=0; i < numLEDs; i++) 00053 neopixel_set_color(&m_strip, i, 255,0,0); //turn every pixel red 00054 00055 for (int i=0; i < numLEDs-1; i++) { 00056 neopixel_set_color(&m_strip, i, 255,0,0); 00057 neopixel_set_color(&m_strip, i+1, 255,255,255); //turn on a white pixel and move it 00058 neopixel_show(&m_strip); 00059 wait_ms(delay); 00060 } 00061 } 00062 00063 void snowflakes(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) { 00064 00065 for (int i=0; i < numLEDs; i++) 00066 neopixel_set_color(&m_strip, i, 0,0,235); //turn every pixel blue 00067 00068 for (int i=0; i < numLEDs-1; i++) { 00069 neopixel_set_color(&m_strip, i, 0,0,235); 00070 neopixel_set_color(&m_strip, i+1, 255,255,255); //turn on a white pixel and move it 00071 neopixel_show(&m_strip); 00072 wait_ms(delay); 00073 } 00074 } 00075 00076 void collegiate(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) { 00077 00078 for (int i=0; i < numLEDs; i++) 00079 neopixel_set_color(&m_strip, i, 224,193,36); //turn every pixel gold 00080 00081 for (int i=0; i < numLEDs-1; i++) { 00082 neopixel_set_color(&m_strip, i, 224,193,36); 00083 neopixel_set_color(&m_strip, i+1, 0,255,0); //turn on a green pixel and move it 00084 neopixel_show(&m_strip); 00085 wait_ms(delay); 00086 } 00087 wait_ms(delay); 00088 00089 for (int i=0; i < numLEDs; i++) 00090 neopixel_set_color(&m_strip, i, 0,255,0); //turn every pixel green 00091 00092 for (int i=0; i < numLEDs-1; i++) { 00093 neopixel_set_color(&m_strip, i, 0,255,0); 00094 neopixel_set_color(&m_strip, i+1, 224,193,36); //turn on a gold pixel and move it 00095 neopixel_show(&m_strip); 00096 wait_ms(delay); 00097 } 00098 } 00099 00100 void iceflakes(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) { 00101 uint8_t led; 00102 00103 for (uint8_t i=0; i < numLEDs; i++) 00104 neopixel_set_color(&m_strip, i, 235,235,235); //turn every pixel white 00105 00106 led = rand()%numLEDs; 00107 neopixel_set_color(&m_strip, led, 0, 0, 235); // set random blue 00108 neopixel_show(&m_strip); 00109 wait_ms(delay); 00110 } 00111 00112 void xmas(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) { 00113 //All green 00114 for (int j=0; j<numLEDs; j++) 00115 neopixel_set_color(&m_strip, j, 0,255,0); 00116 neopixel_show(&m_strip); 00117 wait_ms(1000); 00118 //All red 00119 for (int j=0; j<numLEDs; j++) 00120 neopixel_set_color(&m_strip, j, 255,0,0); 00121 neopixel_show(&m_strip); 00122 wait_ms(1000); 00123 //Green with a red mover 00124 for (int j=0; j<numLEDs; j++) 00125 neopixel_set_color(&m_strip, j, 0,255,0); 00126 neopixel_show(&m_strip); 00127 wait_ms(500); 00128 for (int j=0; j<numLEDs; j++) 00129 { 00130 neopixel_set_color(&m_strip, j, 255,0,0); 00131 neopixel_show(&m_strip); 00132 wait_ms(delay); 00133 } 00134 //Red with a green mover 00135 for (int j=0; j<numLEDs; j++) 00136 neopixel_set_color(&m_strip, j, 255,0,0); 00137 neopixel_show(&m_strip); 00138 wait_ms(delay); 00139 for (int j=0; j<numLEDs; j++) 00140 { 00141 neopixel_set_color(&m_strip, j, 0,255,0); 00142 neopixel_show(&m_strip); 00143 wait_ms(delay); 00144 } 00145 } 00146 00147 void irondude(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) { 00148 00149 for (int i=0; i < numLEDs; i++) 00150 neopixel_set_color(&m_strip, i, 255,255,255); //turn every pixel white 00151 00152 for (int i=0; i < numLEDs; i++) { 00153 neopixel_set_color(&m_strip, i, 255,0,0); //change whites to reds 00154 neopixel_show(&m_strip); 00155 wait_ms(delay); 00156 } 00157 wait_ms(delay); 00158 00159 for (int i=0; i <= numLEDs; i++) { 00160 neopixel_set_color(&m_strip, numLEDs - i, 255,255,255); //change reds to white, in reverse 00161 neopixel_show(&m_strip); 00162 wait_ms(delay); 00163 } 00164 } 00165 00166 void easter(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) { 00167 //All purple 00168 for (int j=0; j<numLEDs; j++) 00169 neopixel_set_color(&m_strip, j, 102,0,102); 00170 neopixel_show(&m_strip); 00171 wait_ms(1000); 00172 //All white 00173 for (int j=0; j<numLEDs; j++) 00174 neopixel_set_color(&m_strip, j, 255,255,255); 00175 neopixel_show(&m_strip); 00176 wait_ms(1000); 00177 //All gold 00178 for (int j=0; j<numLEDs; j++) 00179 neopixel_set_color(&m_strip, j, 255,204,0); 00180 neopixel_show(&m_strip); 00181 wait_ms(1000); 00182 } 00183 00184 void spring(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) { 00185 //All pink 00186 for (int j=0; j<numLEDs; j++) 00187 neopixel_set_color(&m_strip, j, 255,102,255); 00188 neopixel_show(&m_strip); 00189 wait_ms(1000); 00190 //All blue 00191 for (int j=0; j<numLEDs; j++) 00192 neopixel_set_color(&m_strip, j, 153,204,255); 00193 neopixel_show(&m_strip); 00194 wait_ms(1000); 00195 //All green 00196 for (int j=0; j<numLEDs; j++) 00197 neopixel_set_color(&m_strip, j, 153,255,153); 00198 neopixel_show(&m_strip); 00199 wait_ms(1000); 00200 //All yellow 00201 for (int j=0; j<numLEDs; j++) 00202 neopixel_set_color(&m_strip, j, 255,255,153); 00203 neopixel_show(&m_strip); 00204 wait_ms(1000); 00205 } 00206 00207 void memorial(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) { 00208 //All red 00209 for (int j=0; j<numLEDs; j++) 00210 neopixel_set_color(&m_strip, j, 255,0,0); 00211 neopixel_show(&m_strip); 00212 wait_ms(1000); 00213 //All white 00214 for (int j=0; j<numLEDs; j++) 00215 neopixel_set_color(&m_strip, j, 255,255,255); 00216 neopixel_show(&m_strip); 00217 wait_ms(1000); 00218 //All blue 00219 for (int j=0; j<numLEDs; j++) 00220 neopixel_set_color(&m_strip, j, 0,0,255); 00221 neopixel_show(&m_strip); 00222 wait_ms(1000); 00223 }
Generated on Tue Jul 12 2022 21:09:08 by
1.7.2
