본문 바로가기

ESP32

ESP32 C3 Super Mini Pomodoro timer

반응형

포모도로 기법은 25분간 고도로 집중하고 5분간 휴식하는 과정을 4번 반복한 뒤, 15~20분의 긴 휴식을 갖는 시간 관리 및 생산성 향상법입니다. 1980년대 후반 프란체스코 시릴로가 개발했으며, 토마토 모양 타이머에서 유래했습니다. 집중력을 높이고 번아웃을 예방하는 데 효과적입니다. 

 

 

 

Resources

 

코드 깃허브

 

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Arduino.h>
#include <Ticker.h>
#include <Wire.h>

#define SCREEN_WIDTH 128  // OLED display width, in pixels
#define SCREEN_HEIGHT 64  // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

#define OLED_RESET -1
uint32_t workTime = 60 * 25 + 1;
uint32_t breakTime = 60 * 5 + 1;
Ticker tkSec;
uint32_t remainingTime = workTime;
bool work = true;
bool running = false;
bool startStopLastState = false;
const unsigned char playPauseBitmap[] PROGMEM = {
    0x00, 0x00, 0x41, 0x80, 0xf0, 0x00, 0x41, 0x80, 0xfc, 0x00, 0x41, 0x80,
    0xce, 0x00, 0x41, 0x80, 0xc3, 0x80, 0x41, 0x80, 0xc0, 0xe0, 0x41, 0x80,
    0xc0, 0x70, 0x41, 0x80, 0xc0, 0x1c, 0x41, 0x80, 0xc0, 0x0c, 0x41, 0x80,
    0xc0, 0x38, 0x41, 0x80, 0xc0, 0x70, 0x41, 0x80, 0xc1, 0xc0, 0x41, 0x80,
    0xc7, 0x80, 0x41, 0x80, 0xce, 0x00, 0x41, 0x80, 0xf8, 0x00, 0x41, 0x80,
    0xe0, 0x00, 0x41, 0x80, 0x00, 0x00, 0x41, 0x80};
const unsigned char resetBitmap[] PROGMEM = {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x3e, 0x30, 0x00, 0x00, 0xff, 0xf0, 0x00, 0x03, 0xe3, 0xf0, 0x00,
    0x07, 0x00, 0xf8, 0x00, 0x06, 0x00, 0xf8, 0x00, 0x0c, 0x00, 0x00, 0x00,
    0x0c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
    0x18, 0x00, 0x0c, 0x00, 0x18, 0x00, 0x0c, 0x00, 0x1c, 0x00, 0x0c, 0x00,
    0x0c, 0x00, 0x18, 0x00, 0x0c, 0x00, 0x18, 0x00, 0x06, 0x00, 0x30, 0x00,
    0x07, 0x00, 0x70, 0x00, 0x03, 0xc1, 0xe0, 0x00, 0x00, 0xff, 0x80, 0x00,
    0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00};

void everySecond() {
  Serial.println("Tick");
  if (running) {
    Serial.println("Running");
    if (remainingTime && --remainingTime == 0) {
      if (work) {
        work = false;
        remainingTime = breakTime;
      } else {
        running = false;
      }
    } else {
      display.clearDisplay();
      display.setTextSize(2);
      display.setTextColor(WHITE);
      display.setCursor(0, 10);
      // Display left time in mm:ss
      if (work) {
        display.println("HUSSLE");
      } else {
        display.println("CHILL");
      }
      display.setCursor(0, 40);
      display.setTextSize(3);
      if (remainingTime < 600) {
        display.print("0");
        display.print(remainingTime / 60);
      } else {
        display.print(remainingTime / 60);
      }
      display.print(":");
      if (remainingTime % 60 < 10) {
        display.print("0");
      }
      display.println(remainingTime % 60);
      display.drawBitmap(100, 10, playPauseBitmap, 25, 17, WHITE);
      display.drawBitmap(100, 40, resetBitmap, 25, 25, WHITE);
      display.display();
    }
  }
}

void setup() {
  Serial.begin(9600);
  while (!Serial)
    ;
  Serial.println("Pomodoro Timer");

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {  // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for (;;)
      ;
  }
  tkSec.attach(1, everySecond);
  display.clearDisplay();

  Serial.println("Reset");
  running = true;
  work = true;
  remainingTime = workTime;
  everySecond();
  running = false;
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
}

void loop() {
  int startStop = digitalRead(1);
  int reset = digitalRead(2);

  // reset
  if (reset == LOW) {
    running = true;
    work = true;
    remainingTime = workTime;
    everySecond();
    delay(10);
  }

  // start/stop
  if (startStop == LOW && startStopLastState == HIGH) {
    Serial.println("Start/Stop");
    running = !running;
  }
  startStopLastState = startStop;
}

 

 

반응형

캐어랩 고객 지원

취업, 창업의 막막함, 외주 관리, 제품 부재!

당신의 고민은 무엇입니까? 현실과 동떨어진 교육, 실패만 반복하는 외주 계약, 아이디어는 있지만 구현할 기술이 없는 막막함.

우리는 알고 있습니다. 문제의 원인은 '명확한 학습, 실전 경험과 신뢰할 수 있는 기술력의 부재'에서 시작됩니다.

이제 고민을 멈추고, 캐어랩을 만나세요!

코딩(펌웨어), 전자부품과 디지털 회로설계, PCB 설계 제작, 고객(시장/수출) 발굴과 마케팅 전략으로 당신을 지원합니다.

제품 설계의 고수는 성공이 만든 게 아니라 실패가 만듭니다. 아이디어를 양산 가능한 제품으로!

귀사의 제품을 만드세요. 교육과 개발 실적으로 신뢰할 수 있는 파트너를 확보하세요.

지난 30년 여정, 캐어랩이 얻은 모든 것을 함께 나누고 싶습니다.

카카오 채널 추가하기

카톡 채팅방에서 무엇이든 물어보세요

당신의 성공을 위해 캐어랩과 함께 하세요.

캐어랩 온라인 채널 바로가기

캐어랩