generated from m5stack/M5Template-C-CPP
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
541 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,7 @@ jobs: | |
|
||
unit: | ||
- UnitWeightI2C | ||
# - UnitMiniscale | ||
- UnitMiniScales | ||
|
||
board: | ||
- m5stack-atom | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,7 @@ jobs: | |
|
||
unit: | ||
- UnitWeightI2C | ||
# - UnitMiniscale | ||
- UnitMiniScales | ||
|
||
board: | ||
- m5stack_atom | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,7 @@ jobs: | |
|
||
unit: | ||
- UnitWeightI2C | ||
# - UnitMiniscale | ||
- UnitMiniScales | ||
|
||
board: | ||
- m5stack_atom | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,7 @@ jobs: | |
|
||
unit: | ||
- UnitWeightI2C | ||
# - UnitMiniscale | ||
- UnitMiniScales | ||
|
||
board: | ||
- Core | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
examples/UnitUnified/UnitMiniScales/PlotToSerial/PlotToSerial.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
/* | ||
Example using M5UnitUnified for UnitMiniScales | ||
*/ | ||
#include "main/PlotToSerial.cpp" |
111 changes: 111 additions & 0 deletions
111
examples/UnitUnified/UnitMiniScales/PlotToSerial/main/PlotToSerial.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
/* | ||
Example using M5UnitUnified for UnitMiniScales | ||
*/ | ||
#include <M5Unified.h> | ||
#include <M5UnitUnified.h> | ||
#include <M5UnitUnifiedWEIGHT.h> | ||
#include <M5Utility.h> | ||
|
||
using m5::unit::weighti2c::Mode; | ||
|
||
namespace { | ||
auto& lcd = M5.Display; | ||
m5::unit::UnitUnified Units; | ||
m5::unit::UnitMiniScales unit; | ||
|
||
uint32_t idx{}; | ||
constexpr Mode mode_table[] = {Mode::Float, Mode::Int}; | ||
|
||
constexpr lgfx::rgb888_t color_table[] = { | ||
{128, 16, 32}, | ||
{32, 128, 16}, | ||
{16, 32, 128}, | ||
{0, 0, 0}, | ||
}; | ||
|
||
} // namespace | ||
|
||
void setup() | ||
{ | ||
m5::utility::delay(2000); | ||
|
||
M5.begin(); | ||
|
||
auto pin_num_sda = M5.getPin(m5::pin_name_t::port_a_sda); | ||
auto pin_num_scl = M5.getPin(m5::pin_name_t::port_a_scl); | ||
M5_LOGI("getPin: SDA:%u SCL:%u", pin_num_sda, pin_num_scl); | ||
Wire.begin(pin_num_sda, pin_num_scl, 100 * 1000U); | ||
|
||
if (!Units.add(unit, Wire) || !Units.begin()) { | ||
M5_LOGE("Failed to begin"); | ||
lcd.clear(TFT_RED); | ||
while (true) { | ||
m5::utility::delay(10000); | ||
} | ||
} | ||
unit.resetOffset(); | ||
|
||
M5_LOGI("M5UnitUnified has been begun"); | ||
M5_LOGI("%s", Units.debugInfo().c_str()); | ||
|
||
lcd.clear(TFT_DARKGREEN); | ||
} | ||
|
||
void loop() | ||
{ | ||
M5.update(); | ||
auto touch = M5.Touch.getDetail(); | ||
|
||
Units.update(); | ||
if (unit.updated()) { | ||
// Can be checked e.g. by serial plotters | ||
if (!idx) { | ||
M5_LOGI("\n>Weight:%f", unit.weight()); | ||
} else { | ||
M5_LOGI("\n>iWeight:%d", unit.iweight()); | ||
} | ||
} | ||
|
||
// Button on MiniScales | ||
if (unit.wasPressed()) { | ||
static uint32_t cidx{}; | ||
unit.writeLEDColor((uint32_t)color_table[cidx]); | ||
cidx = ++cidx % m5::stl::size(color_table); | ||
} | ||
|
||
// Behavior when BtnA is clicked changes depending on the value. | ||
constexpr int32_t BTN_A_FUNCTION{-1}; | ||
|
||
if (M5.BtnA.wasClicked() || touch.wasClicked()) { | ||
switch (BTN_A_FUNCTION) { | ||
case 0: { // Change mode | ||
if (++idx > 1) { | ||
idx = 0; | ||
} | ||
unit.stopPeriodicMeasurement(); | ||
unit.startPeriodicMeasurement(mode_table[idx]); | ||
} break; | ||
case 1: { // Singleshot as text | ||
static uint32_t sscnt{}; | ||
unit.stopPeriodicMeasurement(); | ||
char txt[16]{}; | ||
if (unit.measureSingleshot(txt)) { | ||
M5_LOGI("\n>Singleshort:%s", txt); | ||
} else { | ||
M5_LOGE("Failed to measure"); | ||
} | ||
// Return to periodic measurement after 8 measurements | ||
if (++sscnt >= 8) { | ||
sscnt = 0; | ||
unit.startPeriodicMeasurement(Mode::Float); | ||
} | ||
|
||
} break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.