generated from m5stack/M5Template-C-CPP
-
Notifications
You must be signed in to change notification settings - Fork 22
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
1 parent
a38e2e4
commit a8a232a
Showing
1 changed file
with
73 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* @file AtomicHDriver.ino | ||
* @author SeanKwok ([email protected]) | ||
* @brief M5AtomS3 Atomic H-Driver Base Test | ||
* @version 0.1 | ||
* @date 2024-01-19 | ||
* | ||
* | ||
* @Hardwares: M5AtomS3 + Atomic H-Driver Base | ||
* @Platform Version: Arduino M5Stack Board Manager v2.1.0 | ||
* @Dependent Library: | ||
* M5GFX: https://github.com/m5stack/M5GFX | ||
* M5Unified: https://github.com/m5stack/M5Unified | ||
* M5AtomS3: https://github.com/m5stack/M5AtomS3 | ||
*/ | ||
|
||
#include "M5AtomS3.h" | ||
|
||
const int IN1_PIN = 6; | ||
const int IN2_PIN = 7; | ||
int freq = 10000; | ||
int ledChannel1 = 0; | ||
int ledChannel2 = 1; | ||
int resolution = 10; | ||
bool direction = true; | ||
int VIN_PIN = 8; | ||
int FAULT_PIN = 5; | ||
|
||
void setup() { | ||
auto cfg = M5.config(); | ||
AtomS3.begin(cfg); | ||
|
||
AtomS3.Display.setTextColor(GREEN); | ||
AtomS3.Display.setTextDatum(middle_center); | ||
AtomS3.Display.setTextFont(&fonts::Orbitron_Light_24); | ||
AtomS3.Display.setTextSize(1); | ||
AtomS3.Display.drawString("H-Driver", AtomS3.Display.width() / 2, | ||
AtomS3.Display.height() / 2); | ||
|
||
ledcSetup(ledChannel1, freq, resolution); | ||
ledcSetup(ledChannel2, freq, resolution); | ||
ledcAttachPin(IN1_PIN, ledChannel1); | ||
ledcAttachPin(IN2_PIN, ledChannel2); | ||
pinMode(VIN_PIN, INPUT); | ||
pinMode(FAULT_PIN, INPUT); | ||
ledcWrite(ledChannel1, 0); | ||
ledcWrite(ledChannel2, 0); | ||
} | ||
|
||
void loop() { | ||
if (M5.BtnA.pressedFor(2000)) { | ||
ledcWrite(ledChannel1, 0); | ||
ledcWrite(ledChannel2, 0); | ||
} | ||
|
||
if (M5.BtnA.wasPressed()) { | ||
if (direction) { | ||
ledcWrite(ledChannel1, 1000); | ||
ledcWrite(ledChannel2, 0); | ||
} else { | ||
ledcWrite(ledChannel1, 0); | ||
ledcWrite(ledChannel2, 1000); | ||
} | ||
direction = !direction; | ||
} | ||
|
||
M5.update(); | ||
Serial.println("VIN IN: " + | ||
String((analogRead(VIN_PIN) * 10.0 / 4095.0) * 3.6)); | ||
if (digitalRead(FAULT_PIN) == 0) { | ||
Serial.println("FAULT!"); | ||
} | ||
} |