0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Cでポモドーロタイマーを作りました

Last updated at Posted at 2021-03-23

初めに

ポモドーロタイマーは一般的に「25分+5分」ですが、自分にはちょっと短いかなと思っていました。そこで「30分+10分」のものを自作してみました。

「もっとこうしたらいいんじゃない」というところがあったらぜひ教えてください。

コード

  • OSはmacOSです
  • 音源は主にこちらからダウンロードしました
  • afplayというコマンドを使うと、mp3ファイルをコマンドラインで再生できるので、これを使いました
# include <stdio.h>
# include <unistd.h>
# include <stdlib.h>

/*
    A "pomodoro" is a set of a working session and a short break.
    And we define a "tomato" as a set of several pomodoros. We put a long break between two tomatoes.
    But we don't put a short break at the end of a tomato.
*/

void work(double t /* min */)
{
    system("afplay ~/Downloads/「開始します」.mp3 && afplay ~/Downloads/「がんばりましょう」.mp3");
    printf("work start\n");
    sleep(t * 60 /* seconds */);
    printf("work end\n");
    system("afplay ~/Downloads/warning1.mp3 && afplay ~/Downloads/「そこまで」.mp3");
}

void short_break(double t /* min */)
{
    system("afplay ~/Downloads/「これより10分間の休憩となります」.mp3");
    printf("short break start\n");
    usleep(t * 3 / 4 * 60 * 1000000 /* micro s */);
    system("afplay ~/Downloads/「始まるよ~」.mp3");
    usleep(t * 1 / 4 * 60 * 1000000 /* micro s */);
    printf("short break end\n");
}

void long_break(double t /* min */)
{
    system("afplay ~/Downloads/「頑張ったね」.mp3");
    printf("long break start\n");
    usleep(t * 3 / 4 * 60 * 1000000 /* micro s */);
    system("afplay ~/Downloads/「始まるよ~」.mp3");
    usleep(t * 1 / 4 * 60 * 1000000 /* micro s */);
    printf("long brek end\n");
}

int main()
{
    int n_pomodoro = 3; // in one tomato
    int n_tomato = 3;
    double t_work = 30;        // min
    double t_short_break = 10; // min
    double t_long_break = 30;  // min

    for (int i = 1; i <= n_tomato; i++)
    {
        for (int j = 1; j <= n_pomodoro; j++)
        {
            printf("%d-th tomato, %d-th pomodoro\n", i, j);
            if (j == n_pomodoro)
            { // if the pomodoro is the last one in a tomato
                work(t_work);
            }
            else
            {
                work(t_work);
                short_break(t_short_break);
            }
        }
        long_break(t_long_break);
    }
    return 0;
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?