Home New Help Edit

腹筋ローラー用カウンタ m5cnt

Suns & Moon Laboratory
M5StickC Plusメモ
2022-09-28



はじめに

最近運動しているんだけど、どうしても回数数えててわからんくなるのでカウンタ作ってみた。
2022-07-18からアブローラー開始

ハード


材料

M5StickC Plus
GROVEケーブル
フットスイッチ オジデン OFL-S-H

作成

GROVEケーブルを半分に切って、1ピン(GND)と4ピン(SCL)をフットスイッチに配線する。
以上

写真

全体


フットスイッチの裏面には磁石貼り付け


使用する時。
アモ缶に磁石で装着。




ソフト


開発環境
ArduinoIDE 1.8.13

ライブラリ

使い方

Aボタンカウンタリセット
Bボタンカウンタインクリメント
GROVE端子に接続したフットスイッチカウンタインクリメント

ソース

ライセンス
MIT License

Copyright (c) 2022 Suns & Moon Laboratory

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

VER001

#define LGFX_AUTODETECT #define LGFX_USE_V1 #include <LovyanGFX.hpp> #include "M5StickCPlus.h" static LGFX lcd; int push_count = 0; int chat_count = 0; #define PIN_SW GPIO_NUM_33 void setup(void) { M5.begin(); lcd.init(); lcd.setRotation(1); pinMode(PIN_SW, INPUT_PULLUP); } void loop(void) { if (digitalRead(PIN_SW) == LOW) { if (chat_count < 5) { chat_count++; if (chat_count == 5) { //event key press push_count++; } } } else { if (chat_count == 5) { //event key release } chat_count = 0; } M5.update(); if (M5.BtnB.wasReleased()) { push_count++; } if (M5.BtnA.wasReleased()) { push_count = 0; } lcd.setCursor(0, 0); lcd.setTextSize(1, 1); lcd.printf("SW counter V001"); lcd.setCursor(32, 16); lcd.setTextSize(16, 16); lcd.printf("%02d", push_count); delay(1); }

VER002

/* board M5StickC plusr */ #define LGFX_AUTODETECT #define LGFX_USE_V1 #include <LovyanGFX.hpp> #include "M5StickCPlus.h" #include "Ticker.h" static LGFX lcd; int push_count = 0; int chat_count = 0; bool redraw; Ticker tick; int tick_wait_sec = 0; #define TIME_TO_POWER_OFF (5*60) #define PIN_SW GPIO_NUM_33 void tick_1sec(int val) { if (tick_wait_sec) { tick_wait_sec--; redraw = true; if (tick_wait_sec == 0) { M5.Axp.PowerOff(); } } } void setup(void) { M5.begin(); lcd.init(); lcd.setRotation(1); pinMode(PIN_SW, INPUT_PULLUP); tick_wait_sec = TIME_TO_POWER_OFF; tick.attach_ms(1000, tick_1sec, 0); redraw = true; } void loop(void) { bool flag_push_sw = false; if (digitalRead(PIN_SW) == LOW) { if (chat_count < 5) { chat_count++; if (chat_count == 5) { //event key press flag_push_sw = true; } } } else { if (chat_count == 5) { //event key release } chat_count = 0; } M5.update(); if (M5.BtnB.wasReleased()) { flag_push_sw = true; } if (M5.BtnA.wasReleased()) { push_count = 0; redraw = true; } if (flag_push_sw) { push_count++; redraw = true; tick_wait_sec = TIME_TO_POWER_OFF; } if (redraw) { redraw = false; lcd.startWrite(); lcd.setCursor(0, 0); lcd.setTextSize(1, 1); lcd.printf("SW counter V002"); lcd.setCursor(32, 16); lcd.setTextSize(16, 16); lcd.printf("%02d", push_count); float wait_ratio; wait_ratio = (float)tick_wait_sec / TIME_TO_POWER_OFF; lcd.drawLine(0, lcd.height() / 2, (lcd.width() - 1), lcd.height() / 2, GREEN); lcd.drawLine(0, lcd.height() / 2, (lcd.width() - 1) * wait_ratio, lcd.height() / 2, RED); lcd.endWrite(); } }
end.

Home New Help Edit
2022-10-27 17:12:18 32400