Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <M5Stack.h>
- #define TFT_GREY 0x5AEB
- uint32_t targetTime = 0;
- static uint8_t conv2d(const char *p);
- int mm = 0, ss = 0;
- byte omm = 99, oss = 99;
- byte xcolon = 0, xsecs = 0;
- bool run = false;
- unsigned int colour = 0;
- void setup(void)
- {
- M5.begin();
- M5.Lcd.fillScreen(TFT_BLACK);
- M5.Lcd.setTextSize(1);
- M5.Lcd.setTextColor(TFT_YELLOW, TFT_BLACK);
- targetTime = millis() + 10;
- }
- void loop()
- {
- if(M5.BtnA.wasPressed() && !run) mm++;
- if(M5.BtnB.wasPressed() && !run) ss++;
- if(M5.BtnC.wasPressed()) run = !run;
- if(M5.BtnC.pressedFor(5000))
- {
- mm = 0;
- ss = 0;
- run = false;
- }
- if(run)
- {
- if (targetTime < millis())
- {
- targetTime = millis() + 1000;
- ss--;
- if (ss == 0)
- {
- ss = 59;
- omm = mm;
- mm--;
- if (mm > 0)
- {
- mm = 59;
- }
- }
- }
- int xpos = 0;
- int ypos = 85;
- int ysecs = ypos + 24;
- if (omm != mm)
- {
- omm = mm;
- if (mm < 10)
- xpos += M5.Lcd.drawChar('0', xpos, ypos, 7);
- xpos += M5.Lcd.drawNumber(mm, xpos, ypos, 7);
- xsecs = xpos;
- }
- if (oss != ss)
- {
- oss = ss;
- xpos = xsecs;
- if (ss % 2)
- {
- M5.Lcd.setTextColor(0x39C4, TFT_BLACK);
- M5.Lcd.drawChar(':', xcolon, ypos, 7);
- xpos += M5.Lcd.drawChar(':', xsecs, ypos, 7);
- M5.Lcd.setTextColor(TFT_YELLOW, TFT_BLACK);
- }
- else
- {
- M5.Lcd.drawChar(':', xcolon, ypos, 7);
- xpos += M5.Lcd.drawChar(':', xsecs, ypos, 7);
- }
- if (ss < 10)
- xpos += M5.Lcd.drawChar('0', xpos, ypos, 7);
- xpos += M5.Lcd.drawNumber(ss, xpos, ypos, 7);
- }
- }
- else
- {
- int xpos = 0;
- int ypos = 85;
- if (mm < 10)
- xpos += M5.Lcd.drawChar('0', xpos, ypos, 7);
- xpos += M5.Lcd.drawNumber(mm, xpos, ypos, 7);
- xsecs = xpos;
- xpos += M5.Lcd.drawChar(':', xsecs, ypos, 7);
- if (ss < 10)
- xpos += M5.Lcd.drawChar('0', xpos, ypos, 7);
- xpos += M5.Lcd.drawNumber(ss, xpos, ypos, 7);
- }
- M5.update();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement