Advertisement
GyroGearloose

select animations with a pot

Jul 31st, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. // select animations with a pot (Code snipplet)
  2.  
  3.  
  4. #define NUMVIZ 7 // number of selectable options (0..6)
  5. #define POT_INPUT A3
  6.  
  7. int readpot()
  8. {
  9. return analogRead(POT_INPUT);
  10. }
  11.  
  12. in loop:
  13.  
  14. int potval = readpot();
  15. byte vizval = potval / (1024/NUMVIZ); // get a viz number based on the pot position
  16. // Serial.println (vizval);
  17. bool newviz = 0;
  18. if (vizval != lastvizval) newviz = 1; // if it's changed, trigger the initialisations
  19. switch (vizval)
  20. {
  21. case 0:
  22. if (newviz) fill_solid( &(leds[0]), NUM_LEDS, CRGB( 0,0,0) ); // switch strip to black
  23. // animation here
  24. break;
  25. case 1:
  26. if (newviz) fill_solid( &(leds[0]), NUM_LEDS, CRGB( 0,0,0) );
  27. // animation here
  28. break;
  29. case 2:
  30. if (newviz) fill_solid( &(leds[0]), NUM_LEDS, CRGB( 0,0,0) );
  31. // animation here
  32. break;
  33. case 3:
  34. if (newviz) fill_solid( &(leds[0]), NUM_LEDS, CRGB( 0,0,0) );
  35. // animation here
  36. break;
  37. case 4:
  38. if (newviz) fill_solid( &(leds[0]), NUM_LEDS, CRGB( 0,0,0) );
  39. // animation here
  40. break;
  41. case 5:
  42. if (newviz) initblobs();
  43. // animation here
  44. break;
  45. case 6:
  46. if (newviz) fill_solid( &(leds[0]), NUM_LEDS, CRGB( 0,0,0) );
  47. // animation here
  48. break;
  49.  
  50. }
  51. lastvizval = vizval;
  52. newviz = 0;
  53. FastLED.show(); // display this frame
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement