Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

BasicTest.ino 1.5KB

7 år sedan
7 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* WS2812Serial BasicTest Example
  2. Test LEDs by turning then 7 different colors.
  3. This example code is in the public domain. */
  4. #include <WS2812Serial.h>
  5. const int numled = 64;
  6. const int pin = 1;
  7. // Usable pins:
  8. // Teensy LC: 1, 4, 5, 24
  9. // Teensy 3.2: 1, 5, 8, 10, 31 (overclock to 120 MHz for pin 8)
  10. // Teensy 3.5: 1, 5, 8, 10, 26, 32, 33, 48
  11. // Teensy 3.6: 1, 5, 8, 10, 26, 32, 33
  12. // Teensy 4.0: 1, 8, 14, 17, 20, 24, 29, 39
  13. // Teensy 4.1: 1, 8, 14, 17, 20, 24, 29, 35, 47, 53
  14. byte drawingMemory[numled*3]; // 3 bytes per LED
  15. DMAMEM byte displayMemory[numled*12]; // 12 bytes per LED
  16. WS2812Serial leds(numled, displayMemory, drawingMemory, pin, WS2812_GRB);
  17. #define RED 0xFF0000
  18. #define GREEN 0x00FF00
  19. #define BLUE 0x0000FF
  20. #define YELLOW 0xFFFF00
  21. #define PINK 0xFF1088
  22. #define ORANGE 0xE05800
  23. #define WHITE 0xFFFFFF
  24. // Less intense...
  25. /*
  26. #define RED 0x160000
  27. #define GREEN 0x001600
  28. #define BLUE 0x000016
  29. #define YELLOW 0x101400
  30. #define PINK 0x120009
  31. #define ORANGE 0x100400
  32. #define WHITE 0x101010
  33. */
  34. void setup() {
  35. leds.begin();
  36. }
  37. void loop() {
  38. // change all the LEDs in 1.5 seconds
  39. int microsec = 1500000 / leds.numPixels();
  40. colorWipe(RED, microsec);
  41. colorWipe(GREEN, microsec);
  42. colorWipe(BLUE, microsec);
  43. colorWipe(YELLOW, microsec);
  44. colorWipe(PINK, microsec);
  45. colorWipe(ORANGE, microsec);
  46. colorWipe(WHITE, microsec);
  47. }
  48. void colorWipe(int color, int wait) {
  49. for (int i=0; i < leds.numPixels(); i++) {
  50. leds.setPixel(i, color);
  51. leds.show();
  52. delayMicroseconds(wait);
  53. }
  54. }