Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. #include <M5Stack.h>
  2. #define TFT_GREY 0x5AEB
  3. uint32_t targetTime = 0;
  4. static uint8_t conv2d(const char *p);
  5. int mm = 0, ss = 0;
  6.  
  7. byte omm = 99, oss = 99;
  8. byte xcolon = 0, xsecs = 0;
  9. bool run = false;
  10. unsigned int colour = 0;
  11.  
  12. void setup(void)
  13. {
  14. M5.begin();
  15. M5.Lcd.fillScreen(TFT_BLACK);
  16. M5.Lcd.setTextSize(1);
  17. M5.Lcd.setTextColor(TFT_YELLOW, TFT_BLACK);
  18. targetTime = millis() + 10;
  19. }
  20.  
  21. void loop()
  22. {
  23. if(M5.BtnA.wasPressed() && !run) mm++;
  24. if(M5.BtnB.wasPressed() && !run) ss++;
  25. if(M5.BtnC.wasPressed()) run = !run;
  26. if(M5.BtnC.pressedFor(5000))
  27. {
  28. mm = 0;
  29. ss = 0;
  30. run = false;
  31. }
  32. if(run)
  33. {
  34. if (targetTime < millis())
  35. {
  36. targetTime = millis() + 1000;
  37. ss--;
  38. if (ss == 0)
  39. {
  40. ss = 59;
  41. omm = mm;
  42. mm--;
  43. if (mm > 0)
  44. {
  45. mm = 59;
  46.  
  47. }
  48. }
  49. }
  50. int xpos = 0;
  51. int ypos = 85;
  52. int ysecs = ypos + 24;
  53. if (omm != mm)
  54. {
  55. omm = mm;
  56.  
  57. if (mm < 10)
  58. xpos += M5.Lcd.drawChar('0', xpos, ypos, 7);
  59. xpos += M5.Lcd.drawNumber(mm, xpos, ypos, 7);
  60. xsecs = xpos;
  61. }
  62. if (oss != ss)
  63. {
  64. oss = ss;
  65. xpos = xsecs;
  66. if (ss % 2)
  67. {
  68. M5.Lcd.setTextColor(0x39C4, TFT_BLACK);
  69. M5.Lcd.drawChar(':', xcolon, ypos, 7);
  70. xpos += M5.Lcd.drawChar(':', xsecs, ypos, 7);
  71. M5.Lcd.setTextColor(TFT_YELLOW, TFT_BLACK);
  72. }
  73. else
  74. {
  75. M5.Lcd.drawChar(':', xcolon, ypos, 7);
  76. xpos += M5.Lcd.drawChar(':', xsecs, ypos, 7);
  77. }
  78. if (ss < 10)
  79. xpos += M5.Lcd.drawChar('0', xpos, ypos, 7);
  80. xpos += M5.Lcd.drawNumber(ss, xpos, ypos, 7);
  81.  
  82. }
  83. }
  84.  
  85. else
  86. {
  87. int xpos = 0;
  88. int ypos = 85;
  89. if (mm < 10)
  90. xpos += M5.Lcd.drawChar('0', xpos, ypos, 7);
  91. xpos += M5.Lcd.drawNumber(mm, xpos, ypos, 7);
  92. xsecs = xpos;
  93. xpos += M5.Lcd.drawChar(':', xsecs, ypos, 7);
  94. if (ss < 10)
  95. xpos += M5.Lcd.drawChar('0', xpos, ypos, 7);
  96. xpos += M5.Lcd.drawNumber(ss, xpos, ypos, 7);
  97. }
  98.  
  99. M5.update();
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement