-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add copyright and dependency information(Module)
- Loading branch information
renletao
committed
Jan 16, 2025
1 parent
d375924
commit 60cba67
Showing
63 changed files
with
1,758 additions
and
1,391 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 |
---|---|---|
@@ -1,16 +1,14 @@ | ||
/** | ||
* @file DriverSample.ino | ||
* @author SeanKwok ([email protected]) | ||
* @brief Module 4EncoderMotor Test Demo. | ||
* @version 0.1 | ||
* @date 2024-01-19 | ||
* | ||
/* | ||
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
/* | ||
* @Hardwares: M5Core + Module 4EncoderMotor | ||
* @Platform Version: Arduino M5Stack Board Manager v2.1.0 | ||
* @Platform Version: Arduino M5Stack Board Manager v2.1.3 | ||
* @Dependent Library: | ||
* M5Unified: https://github.com/m5stack/M5Unified | ||
* M5GFX: https://github.com/m5stack/M5GFX | ||
* M5GFX@^0.2.3: https://github.com/m5stack/M5GFX | ||
* M5Unified@^0.2.2: https://github.com/m5stack/M5Unified | ||
* M5Module4EncoderMotor: https://github.com/m5stack/M5Module-4EncoderMotor | ||
*/ | ||
|
||
|
@@ -20,15 +18,16 @@ | |
|
||
M5Module4EncoderMotor driver; | ||
|
||
#define MAX_RECORD_SIZE 256 | ||
#define MAX_RECORD_SIZE (256) | ||
|
||
float amp_record[MAX_RECORD_SIZE] = {0}; | ||
uint8_t record_index = 0; | ||
float amp_value = 0.0f; | ||
|
||
uint8_t avg_filter_level = 20; | ||
|
||
float avg_filter(float *data, int len) { | ||
float avg_filter(float *data, int len) | ||
{ | ||
float sum = 0; | ||
float min = data[0]; | ||
float max = data[0]; | ||
|
@@ -46,7 +45,8 @@ float avg_filter(float *data, int len) { | |
return sum / (len - 2); | ||
} | ||
|
||
void setup() { | ||
void setup() | ||
{ | ||
M5.begin(); | ||
M5.Display.begin(); | ||
|
||
|
@@ -78,13 +78,13 @@ void setup() { | |
bool direction = true; | ||
int mode = NORMAL_MODE; | ||
|
||
void loop() { | ||
void loop() | ||
{ | ||
M5.update(); | ||
for (uint8_t i = 0; i < 4; i++) { | ||
M5.Display.fillRect(20, 40 + 35 * i, 300, 35, BLACK); | ||
int32_t encoder_value = driver.getEncoderValue(i); | ||
M5.Display.drawString("CH" + String(i) + ": " + String(encoder_value), | ||
20, 40 + 35 * i); | ||
M5.Display.drawString("CH" + String(i) + ": " + String(encoder_value), 20, 40 + 35 * i); | ||
} | ||
|
||
if (avg_filter_level != 0) { | ||
|
@@ -100,12 +100,9 @@ void loop() { | |
float current = amp_value; | ||
|
||
M5.Display.fillRect(20, 40 + 35 * 4, 300, 35, BLACK); | ||
M5.Display.drawString( | ||
"POWER: " + String(voltage) + "V/" + String(current) + "A", 20, | ||
40 + 35 * 4); | ||
M5.Display.drawString("POWER: " + String(voltage) + "V/" + String(current) + "A", 20, 40 + 35 * 4); | ||
|
||
if (M5.BtnA.wasClicked() || | ||
(M5.Touch.getCount() && M5.Touch.getDetail(0).wasClicked())) { | ||
if (M5.BtnA.wasClicked() || (M5.Touch.getCount() && M5.Touch.getDetail(0).wasClicked())) { | ||
mode++; | ||
if (mode > SPEED_MODE) { | ||
mode = NORMAL_MODE; | ||
|
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
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.