SHARE
TWEET

Untitled

a guest Oct 21st, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <M5StickC.h>
  2. #include <BleKeyboard.h>
  3.  
  4. BleKeyboard bleKeyboard;
  5.  
  6. void setup() {
  7.   Serial.begin(115200);
  8.   Serial.println("Starting ...");
  9.  
  10.   M5.begin();
  11.   M5.Axp.ScreenBreath(8);
  12.   M5.Lcd.setRotation(3);
  13.   drawPaused();
  14.  
  15.   // bleKeyboard.begin();
  16. }
  17.  
  18. bool paused = true;
  19. int max_cnt = 0;
  20.  
  21. void drawPaused() {
  22.   M5.Lcd.fillScreen(TFT_BLACK);
  23.   M5.Lcd.setTextColor(TFT_WHITE);
  24.   M5.Lcd.setTextSize(2);
  25.   M5.Lcd.setCursor(50, 20, 4);
  26.   M5.Lcd.println("||");
  27. }
  28.  
  29. bool setPaused() {
  30.   M5.update();
  31.   int last_max_cnt = max_cnt;
  32.   if (paused) {
  33.     if (M5.BtnA.pressedFor(1800))
  34.       max_cnt = 1000;
  35.     else if (M5.BtnA.pressedFor(1500))
  36.       max_cnt = 500;
  37.     else if (M5.BtnA.pressedFor(1200))
  38.       max_cnt = 400;
  39.     else if (M5.BtnA.pressedFor(900))
  40.       max_cnt = 300;
  41.     else if (M5.BtnA.pressedFor(600))
  42.       max_cnt = 200;
  43.     else if (M5.BtnA.pressedFor(300))
  44.       max_cnt = 100;
  45.     else if (M5.BtnA.isPressed())
  46.       max_cnt = 0;
  47.  
  48.     if (last_max_cnt != max_cnt) {
  49.       M5.Lcd.fillScreen(TFT_BLACK);
  50.       M5.Lcd.setTextColor(TFT_WHITE);
  51.       M5.Lcd.setCursor(85, 50, 4);
  52.       M5.Lcd.setTextSize(1);
  53.       M5.Lcd.printf("%4d", max_cnt);
  54.     }
  55.   }
  56.   if (M5.BtnA.wasReleased()) {
  57.     paused = !paused;
  58.     Serial.print("paused = ");
  59.     Serial.println(paused);
  60.  
  61.     if (paused) {
  62.       drawPaused();
  63.       ESP.restart();
  64.     } else {
  65.       bleKeyboard.begin();
  66.     }
  67.   }
  68.   return paused;
  69. }
  70.  
  71. void loop() {
  72.   if (setPaused()) {
  73.     delay(50);
  74.     return;
  75.   }
  76.  
  77.   if (bleKeyboard.isConnected()) {
  78.     M5.Lcd.fillScreen(TFT_BLUE);
  79.     Serial.println("Sending Ctrl...");
  80.  
  81.     bleKeyboard.press(KEY_LEFT_CTRL);
  82.     delay(30);
  83.     bleKeyboard.releaseAll();
  84.  
  85.   } else {
  86.     M5.Lcd.fillScreen(TFT_RED);
  87.   }
  88.  
  89.   if (max_cnt > 0) {
  90.     if (--max_cnt == 0) {
  91.       paused = true;
  92.       drawPaused();
  93.       ESP.restart();
  94.       return;
  95.     }
  96.   }
  97.  
  98.   Serial.println("Waiting 5 seconds...");
  99.  
  100.   M5.Lcd.setTextColor(TFT_WHITE);
  101.   for (int i = 5; i > 0; i--) {
  102.     if (bleKeyboard.isConnected()) {
  103.       M5.Lcd.fillScreen(TFT_BLUE);
  104.     } else {
  105.       M5.Lcd.fillScreen(TFT_RED);
  106.     }
  107.     M5.Lcd.setCursor(30, 4, 8);
  108.     M5.Lcd.setTextSize(1);
  109.     M5.Lcd.print(i);
  110.     M5.Lcd.setCursor(85, 50, 4);
  111.     M5.Lcd.setTextSize(1);
  112.     M5.Lcd.printf("%4d", max_cnt);
  113.  
  114.     for (int j = 0; j < 10; j++) {
  115.       if (setPaused())
  116.         return;
  117.       delay(100);
  118.     }
  119.   }      
  120. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top