m5cnt
*腹筋ローラー用カウンタ m5cnt [[index]] [[m5stickcplus]] 2022-09-28 #contents **はじめに 最近運動しているんだけど、どうしても回数数えててわからんくなるのでカウンタ作ってみた。 2022-07-18からアブローラー開始 [[https://twitter.com/mikekoma/status/1548934749544013824]] **ハード ***材料 [[M5StickC Plus>https://docs.m5stack.com/en/core/m5stickc_plus]] GROVEケーブル フットスイッチ [[オジデン OFL-S-H>https://ojiden.co.jp/item/detail.html?itemId=I20130821003]] ***作成 GROVEケーブルを半分に切って、1ピン(GND)と4ピン(SCL)をフットスイッチに配線する。 以上 ***写真 全体 &simg(sys.jpg); フットスイッチの裏面には磁石貼り付け &simg(sw.jpg); 使用する時。 アモ缶に磁石で装着。 &simg(work.jpg); &youtube(gJhkpmZTjyI); **ソフト 開発環境 ArduinoIDE 1.8.13 ライブラリ -LovyanGFX 0.4.18 -M5StickCPlus 0.0.8 ***使い方 |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
> #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 -自動パワーオフ追加(5分) > /* > board M5StickC plusr > */ > #define LGFX_AUTODETECT > #define LGFX_USE_V1 > #include
> #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.
2025-03-31 22:54:54 32400