PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

CircularLightBuffer.pde 1.4KB

3 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. A circular light buffer. If you manage to construct a circle of LEDs,
  3. definitely send in pictures. What this sketch does is take an analog
  4. reading off of analog pin 0 and add it to the current value of the last LED.
  5. If the resultant sum is greater than 4095, it turns the LED off,
  6. otherwise sets LED 0 to the value of the sum.
  7. If you ground pin 12, it will set LED 0 to zero.
  8. Then it shifts all the LED values up one (so LED 0 becomes LED 1) and sets
  9. LED 0 to the value shifted off the last LED (so if one LED is on, it will
  10. go in a circle forever).
  11. See the BasicUse example for hardware setup.
  12. Alex Leone <acleone ~AT~ gmail.com>, 2009-02-04 */
  13. #include "Tlc5940.h"
  14. #include "tlc_shifts.h"
  15. // which analog pin to use
  16. #define ANALOG_PIN 0
  17. // which pin to clear the LEDs with
  18. #define CLEAR_PIN 12
  19. // how many millis for one full revolution over all the LEDs
  20. #define SCOPE_PERIOD (2000 * NUM_TLCS)
  21. #define LED_PERIOD SCOPE_PERIOD / (NUM_TLCS * 16)
  22. void setup()
  23. {
  24. pinMode(CLEAR_PIN, INPUT);
  25. digitalWrite(CLEAR_PIN, HIGH); // enable pull-up
  26. Tlc.init();
  27. }
  28. void loop()
  29. {
  30. // shiftUp returns the value shifted off the last pin
  31. uint16_t sum = tlc_shiftUp() + analogRead(ANALOG_PIN) * 4;
  32. if (digitalRead(CLEAR_PIN) == LOW || sum > 4095)
  33. sum = 0;
  34. Tlc.set(0, sum);
  35. Tlc.update();
  36. delay(LED_PERIOD);
  37. }