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.

strandtest.ino 4.1KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include <Adafruit_NeoPixel.h>
  2. #ifdef __AVR__
  3. #include <avr/power.h>
  4. #endif
  5. #define PIN 6
  6. // Parameter 1 = number of pixels in strip
  7. // Parameter 2 = Arduino pin number (most are valid)
  8. // Parameter 3 = pixel type flags, add together as needed:
  9. // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  10. // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  11. // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
  12. // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  13. // NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
  14. Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
  15. // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
  16. // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
  17. // and minimize distance between Arduino and first pixel. Avoid connecting
  18. // on a live circuit...if you must, connect GND first.
  19. void setup() {
  20. // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  21. #if defined (__AVR_ATtiny85__)
  22. if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  23. #endif
  24. // End of trinket special code
  25. strip.begin();
  26. strip.setBrightness(50);
  27. strip.show(); // Initialize all pixels to 'off'
  28. }
  29. void loop() {
  30. // Some example procedures showing how to display to the pixels:
  31. colorWipe(strip.Color(255, 0, 0), 50); // Red
  32. colorWipe(strip.Color(0, 255, 0), 50); // Green
  33. colorWipe(strip.Color(0, 0, 255), 50); // Blue
  34. //colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
  35. // Send a theater pixel chase in...
  36. theaterChase(strip.Color(127, 127, 127), 50); // White
  37. theaterChase(strip.Color(127, 0, 0), 50); // Red
  38. theaterChase(strip.Color(0, 0, 127), 50); // Blue
  39. rainbow(20);
  40. rainbowCycle(20);
  41. theaterChaseRainbow(50);
  42. }
  43. // Fill the dots one after the other with a color
  44. void colorWipe(uint32_t c, uint8_t wait) {
  45. for(uint16_t i=0; i<strip.numPixels(); i++) {
  46. strip.setPixelColor(i, c);
  47. strip.show();
  48. delay(wait);
  49. }
  50. }
  51. void rainbow(uint8_t wait) {
  52. uint16_t i, j;
  53. for(j=0; j<256; j++) {
  54. for(i=0; i<strip.numPixels(); i++) {
  55. strip.setPixelColor(i, Wheel((i+j) & 255));
  56. }
  57. strip.show();
  58. delay(wait);
  59. }
  60. }
  61. // Slightly different, this makes the rainbow equally distributed throughout
  62. void rainbowCycle(uint8_t wait) {
  63. uint16_t i, j;
  64. for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
  65. for(i=0; i< strip.numPixels(); i++) {
  66. strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
  67. }
  68. strip.show();
  69. delay(wait);
  70. }
  71. }
  72. //Theatre-style crawling lights.
  73. void theaterChase(uint32_t c, uint8_t wait) {
  74. for (int j=0; j<10; j++) { //do 10 cycles of chasing
  75. for (int q=0; q < 3; q++) {
  76. for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
  77. strip.setPixelColor(i+q, c); //turn every third pixel on
  78. }
  79. strip.show();
  80. delay(wait);
  81. for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
  82. strip.setPixelColor(i+q, 0); //turn every third pixel off
  83. }
  84. }
  85. }
  86. }
  87. //Theatre-style crawling lights with rainbow effect
  88. void theaterChaseRainbow(uint8_t wait) {
  89. for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
  90. for (int q=0; q < 3; q++) {
  91. for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
  92. strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
  93. }
  94. strip.show();
  95. delay(wait);
  96. for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
  97. strip.setPixelColor(i+q, 0); //turn every third pixel off
  98. }
  99. }
  100. }
  101. }
  102. // Input a value 0 to 255 to get a color value.
  103. // The colours are a transition r - g - b - back to r.
  104. uint32_t Wheel(byte WheelPos) {
  105. WheelPos = 255 - WheelPos;
  106. if(WheelPos < 85) {
  107. return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  108. }
  109. if(WheelPos < 170) {
  110. WheelPos -= 85;
  111. return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  112. }
  113. WheelPos -= 170;
  114. return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  115. }