PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

262 lines
6.4KB

  1. #include <Adafruit_NeoPixel.h>
  2. #ifdef __AVR__
  3. #include <avr/power.h>
  4. #endif
  5. #define PIN 6
  6. #define NUM_LEDS 60
  7. #define BRIGHTNESS 50
  8. Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRBW + NEO_KHZ800);
  9. byte neopix_gamma[] = {
  10. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
  12. 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
  13. 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5,
  14. 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10,
  15. 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
  16. 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
  17. 25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
  18. 37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
  19. 51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
  20. 69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
  21. 90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114,
  22. 115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142,
  23. 144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,
  24. 177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
  25. 215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };
  26. void setup() {
  27. // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  28. #if defined (__AVR_ATtiny85__)
  29. if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  30. #endif
  31. // End of trinket special code
  32. strip.setBrightness(BRIGHTNESS);
  33. strip.begin();
  34. strip.show(); // Initialize all pixels to 'off'
  35. }
  36. void loop() {
  37. // Some example procedures showing how to display to the pixels:
  38. colorWipe(strip.Color(255, 0, 0), 50); // Red
  39. colorWipe(strip.Color(0, 255, 0), 50); // Green
  40. colorWipe(strip.Color(0, 0, 255), 50); // Blue
  41. colorWipe(strip.Color(0, 0, 0, 255), 50); // White
  42. whiteOverRainbow(20,75,5);
  43. pulseWhite(5);
  44. // fullWhite();
  45. // delay(2000);
  46. rainbowFade2White(3,3,1);
  47. }
  48. // Fill the dots one after the other with a color
  49. void colorWipe(uint32_t c, uint8_t wait) {
  50. for(uint16_t i=0; i<strip.numPixels(); i++) {
  51. strip.setPixelColor(i, c);
  52. strip.show();
  53. delay(wait);
  54. }
  55. }
  56. void pulseWhite(uint8_t wait) {
  57. for(int j = 0; j < 256 ; j++){
  58. for(uint16_t i=0; i<strip.numPixels(); i++) {
  59. strip.setPixelColor(i, strip.Color(0,0,0, neopix_gamma[j] ) );
  60. }
  61. delay(wait);
  62. strip.show();
  63. }
  64. for(int j = 255; j >= 0 ; j--){
  65. for(uint16_t i=0; i<strip.numPixels(); i++) {
  66. strip.setPixelColor(i, strip.Color(0,0,0, neopix_gamma[j] ) );
  67. }
  68. delay(wait);
  69. strip.show();
  70. }
  71. }
  72. void rainbowFade2White(uint8_t wait, int rainbowLoops, int whiteLoops) {
  73. float fadeMax = 100.0;
  74. int fadeVal = 0;
  75. uint32_t wheelVal;
  76. int redVal, greenVal, blueVal;
  77. for(int k = 0 ; k < rainbowLoops ; k ++){
  78. for(int j=0; j<256; j++) { // 5 cycles of all colors on wheel
  79. for(int i=0; i< strip.numPixels(); i++) {
  80. wheelVal = Wheel(((i * 256 / strip.numPixels()) + j) & 255);
  81. redVal = red(wheelVal) * float(fadeVal/fadeMax);
  82. greenVal = green(wheelVal) * float(fadeVal/fadeMax);
  83. blueVal = blue(wheelVal) * float(fadeVal/fadeMax);
  84. strip.setPixelColor( i, strip.Color( redVal, greenVal, blueVal ) );
  85. }
  86. //First loop, fade in!
  87. if(k == 0 && fadeVal < fadeMax-1) {
  88. fadeVal++;
  89. }
  90. //Last loop, fade out!
  91. else if(k == rainbowLoops - 1 && j > 255 - fadeMax ){
  92. fadeVal--;
  93. }
  94. strip.show();
  95. delay(wait);
  96. }
  97. }
  98. delay(500);
  99. for(int k = 0 ; k < whiteLoops ; k ++){
  100. for(int j = 0; j < 256 ; j++){
  101. for(uint16_t i=0; i < strip.numPixels(); i++) {
  102. strip.setPixelColor(i, strip.Color(0,0,0, neopix_gamma[j] ) );
  103. }
  104. strip.show();
  105. }
  106. delay(2000);
  107. for(int j = 255; j >= 0 ; j--){
  108. for(uint16_t i=0; i < strip.numPixels(); i++) {
  109. strip.setPixelColor(i, strip.Color(0,0,0, neopix_gamma[j] ) );
  110. }
  111. strip.show();
  112. }
  113. }
  114. delay(500);
  115. }
  116. void whiteOverRainbow(uint8_t wait, uint8_t whiteSpeed, uint8_t whiteLength ) {
  117. if(whiteLength >= strip.numPixels()) whiteLength = strip.numPixels() - 1;
  118. int head = whiteLength - 1;
  119. int tail = 0;
  120. int loops = 3;
  121. int loopNum = 0;
  122. static unsigned long lastTime = 0;
  123. while(true){
  124. for(int j=0; j<256; j++) {
  125. for(uint16_t i=0; i<strip.numPixels(); i++) {
  126. if((i >= tail && i <= head) || (tail > head && i >= tail) || (tail > head && i <= head) ){
  127. strip.setPixelColor(i, strip.Color(0,0,0, 255 ) );
  128. }
  129. else{
  130. strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
  131. }
  132. }
  133. if(millis() - lastTime > whiteSpeed) {
  134. head++;
  135. tail++;
  136. if(head == strip.numPixels()){
  137. loopNum++;
  138. }
  139. lastTime = millis();
  140. }
  141. if(loopNum == loops) return;
  142. head%=strip.numPixels();
  143. tail%=strip.numPixels();
  144. strip.show();
  145. delay(wait);
  146. }
  147. }
  148. }
  149. void fullWhite() {
  150. for(uint16_t i=0; i<strip.numPixels(); i++) {
  151. strip.setPixelColor(i, strip.Color(0,0,0, 255 ) );
  152. }
  153. strip.show();
  154. }
  155. // Slightly different, this makes the rainbow equally distributed throughout
  156. void rainbowCycle(uint8_t wait) {
  157. uint16_t i, j;
  158. for(j=0; j<256 * 5; j++) { // 5 cycles of all colors on wheel
  159. for(i=0; i< strip.numPixels(); i++) {
  160. strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
  161. }
  162. strip.show();
  163. delay(wait);
  164. }
  165. }
  166. void rainbow(uint8_t wait) {
  167. uint16_t i, j;
  168. for(j=0; j<256; j++) {
  169. for(i=0; i<strip.numPixels(); i++) {
  170. strip.setPixelColor(i, Wheel((i+j) & 255));
  171. }
  172. strip.show();
  173. delay(wait);
  174. }
  175. }
  176. // Input a value 0 to 255 to get a color value.
  177. // The colours are a transition r - g - b - back to r.
  178. uint32_t Wheel(byte WheelPos) {
  179. WheelPos = 255 - WheelPos;
  180. if(WheelPos < 85) {
  181. return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3,0);
  182. }
  183. if(WheelPos < 170) {
  184. WheelPos -= 85;
  185. return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3,0);
  186. }
  187. WheelPos -= 170;
  188. return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0,0);
  189. }
  190. uint8_t red(uint32_t c) {
  191. return (c >> 16);
  192. }
  193. uint8_t green(uint32_t c) {
  194. return (c >> 8);
  195. }
  196. uint8_t blue(uint32_t c) {
  197. return (c);
  198. }