Guest User

Untitled

a guest
Feb 24th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #include <TM1638.h>
  2. // Wemos D1 Mini = Data:D2,Clock:D5,Strobe:D6
  3. TM1638 module(4, 14, 12);
  4. const char alpha[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'x', 'y', 'z'};
  5. int pos = 8;
  6. //Demo how you can define place of dot
  7. //Dot will move from left to right and index number for the place will be shown.
  8. void scrollDots() {
  9. for (int i = 0; i < 8; i++)
  10. {
  11. module.clearDisplay();
  12. //Move dot one place to right
  13. module.setDisplayToDecNumber(i, 128 >> i);
  14. delay(1000);
  15. }
  16. delay(2000);
  17. }
  18. //Scroll all alphabets
  19. void scrollAlpha() {
  20. String s = "";
  21. for (int i = 0; i < 26; i++)
  22. {
  23. module.clearDisplay();
  24. //When we have 8 characters on display, start to scroll them.
  25. if (i > 8) {
  26. s.remove(0, 1);
  27. }
  28. s = s + alpha[i];
  29. module.setDisplayToString(s);
  30. delay(1000);
  31. }
  32. delay(2000);
  33. }
  34. void setup() {
  35. Serial.begin(9600);
  36. /** Set the display (segments and LEDs) active or off and intensity (range from 0-7). */
  37. module.setupDisplay(true, 0);
  38. scrollDots();
  39. scrollAlpha();
  40. module.clearDisplay();
  41. }
  42.  
  43. //Move leds with first and second button
  44. void loop() {
  45. byte keys = module.getButtons();
  46. int a = keys;
  47. delay(100);
  48. switch (keys) {
  49. case 1 :
  50. pos = pos >> 1;
  51. break;
  52. case 2 :
  53. pos = pos << 1;
  54. break;
  55. //Other keys are cases 4,8,16,32,64,128
  56. //If you need to check if second and third buttons are bot pressed, make case for (2+4)=6
  57. }
  58. //Dont let red dot escape from the playground
  59. if (pos > 128) pos = 1;
  60. if (pos < 1) pos = 128;
  61. module.setLEDs(pos);
  62. }
Add Comment
Please, Sign In to add comment