PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Rainbow.ino 3.4KB

3 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* OctoWS2811 Rainbow.ino - Rainbow Shifting Test
  2. http://www.pjrc.com/teensy/td_libs_OctoWS2811.html
  3. Copyright (c) 2013 Paul Stoffregen, PJRC.COM, LLC
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. Required Connections
  20. --------------------
  21. pin 2: LED Strip #1 OctoWS2811 drives 8 LED Strips.
  22. pin 14: LED strip #2 All 8 are the same length.
  23. pin 7: LED strip #3
  24. pin 8: LED strip #4 A 100 ohm resistor should used
  25. pin 6: LED strip #5 between each Teensy pin and the
  26. pin 20: LED strip #6 wire to the LED strip, to minimize
  27. pin 21: LED strip #7 high frequency ringining & noise.
  28. pin 5: LED strip #8
  29. pin 15 & 16 - Connect together, but do not use
  30. pin 4 - Do not use
  31. pin 3 - Do not use as PWM. Normal use is ok.
  32. pin 1 - Output indicating CPU usage, monitor with an oscilloscope,
  33. logic analyzer or even an LED (brighter = CPU busier)
  34. */
  35. #include <OctoWS2811.h>
  36. const int ledsPerStrip = 60;
  37. DMAMEM int displayMemory[ledsPerStrip*6];
  38. int drawingMemory[ledsPerStrip*6];
  39. const int config = WS2811_GRB | WS2811_800kHz;
  40. OctoWS2811 leds(ledsPerStrip, displayMemory, drawingMemory, config);
  41. int rainbowColors[180];
  42. void setup() {
  43. pinMode(1, OUTPUT);
  44. digitalWrite(1, HIGH);
  45. for (int i=0; i<180; i++) {
  46. int hue = i * 2;
  47. int saturation = 100;
  48. int lightness = 50;
  49. // pre-compute the 180 rainbow colors
  50. rainbowColors[i] = makeColor(hue, saturation, lightness);
  51. }
  52. digitalWrite(1, LOW);
  53. leds.begin();
  54. }
  55. void loop() {
  56. rainbow(10, 2500);
  57. }
  58. // phaseShift is the shift between each row. phaseShift=0
  59. // causes all rows to show the same colors moving together.
  60. // phaseShift=180 causes each row to be the opposite colors
  61. // as the previous.
  62. //
  63. // cycleTime is the number of milliseconds to shift through
  64. // the entire 360 degrees of the color wheel:
  65. // Red -> Orange -> Yellow -> Green -> Blue -> Violet -> Red
  66. //
  67. void rainbow(int phaseShift, int cycleTime)
  68. {
  69. int color, x, y, wait;
  70. wait = cycleTime * 1000 / ledsPerStrip;
  71. for (color=0; color < 180; color++) {
  72. digitalWrite(1, HIGH);
  73. for (x=0; x < ledsPerStrip; x++) {
  74. for (y=0; y < 8; y++) {
  75. int index = (color + x + y*phaseShift/2) % 180;
  76. leds.setPixel(x + y*ledsPerStrip, rainbowColors[index]);
  77. }
  78. }
  79. leds.show();
  80. digitalWrite(1, LOW);
  81. delayMicroseconds(wait);
  82. }
  83. }