animation.ino 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Edgelit "animation" example
  3. * Counts from 0 to 4,294,967,295 with transitions and theming
  4. */
  5. #include "Edgelit.h"
  6. #define DATA_PIN 5 // Pin "D1" using Wemos D1 mini's stupid labels
  7. #define DISPLAY_COUNT 6 // Number of displays in chain
  8. #define DISPLAY_TYPE LIXIE_1 // Type of display (LIXIE_1, NIXIE_PIPE, etc.)
  9. Edgelit lit(DATA_PIN, DISPLAY_COUNT, DISPLAY_TYPE);
  10. uint32_t count = 123456;
  11. uint8_t hue = 0;
  12. uint8_t pos = 0;
  13. uint8_t animation_type = 0;
  14. void setup(){
  15. lit.begin(); // Initialize the interrupts for animation
  16. lit.transition_type(FADE_TO_BLACK); // Can be INSTANT, CROSSFADE, or FADE_TO_BLACK
  17. lit.transition_time(250); // Transition time in milliseconds. (Does nothing for INSTANT transitions)
  18. lit.animation_callback(animator); // User function called at 100FPS when displays are updated
  19. lit.empty_displays(true); // Allows showing background color on displays not currently showing a numeral
  20. }
  21. void loop() {
  22. lit.write(count);
  23. count++;
  24. delay(500);
  25. if(millis() >= 20000 && animation_type == 0){
  26. animation_type = 1;
  27. }
  28. }
  29. // All of this happens in the background while loop() is running your own code!
  30. void animator(){
  31. hue++;
  32. // Rainbow with twinkling colors
  33. if(animation_type == 0){
  34. if(random(1,10) == 1){ // 10% chance
  35. uint8_t sparkle_pos = random(0,lit.led_count()); // pick a random location in the string
  36. lit.color_pixel(sparkle_pos,CHSV(random(0,256),255,96), BACK); // set this random location to a random color
  37. }
  38. for(uint16_t i = 0; i < lit.led_count(); i++){
  39. CRGB col = lit.color_pixel(i, BACK); // get pixel color
  40. // Fade all "BACK" pixels to black over time
  41. col.r = col.r*0.95;
  42. col.g = col.g*0.95;
  43. col.b = col.b*0.95;
  44. lit.color_pixel(i, col, BACK); // set pixel color
  45. lit.color_pixel(i,CHSV(hue+i,255,255), FRONT); // Creates cycling rainbow for foreground colors
  46. }
  47. }
  48. // White with color scanning in background
  49. else if(animation_type == 1){
  50. pos++; // "pos" is where in the chain we're currently turning pixels on
  51. if(pos >= lit.led_count()){ // If we reach the end of the chain, start over
  52. pos = 0;
  53. }
  54. lit.color(CRGB(255,255,255),FRONT); // Foreground color to white
  55. lit.color_pixel(pos, CHSV(hue,255,127),BACK); // Set one background pixel @ "pos" to "hue"
  56. // Fade all background pixels to black over time
  57. for(uint16_t i = 0; i < lit.led_count(); i++){
  58. CRGB col = lit.color_pixel(i, BACK); // get pixel color
  59. col.r = col.r*0.95;
  60. col.g = col.g*0.95;
  61. col.b = col.b*0.95;
  62. lit.color_pixel(i, col, BACK); // set pixel color
  63. }
  64. }
  65. }