|
| 1 | +/** |
| 2 | + * @file AtomicHDriver.ino |
| 3 | + * @author SeanKwok ([email protected]) |
| 4 | + * @brief M5AtomS3 Atomic H-Driver Base Test |
| 5 | + * @version 0.1 |
| 6 | + * @date 2024-01-19 |
| 7 | + * |
| 8 | + * |
| 9 | + * @Hardwares: M5AtomS3 + Atomic H-Driver Base |
| 10 | + * @Platform Version: Arduino M5Stack Board Manager v2.1.0 |
| 11 | + * @Dependent Library: |
| 12 | + * M5GFX: https://github.com/m5stack/M5GFX |
| 13 | + * M5Unified: https://github.com/m5stack/M5Unified |
| 14 | + * M5AtomS3: https://github.com/m5stack/M5AtomS3 |
| 15 | + */ |
| 16 | + |
| 17 | +#include "M5AtomS3.h" |
| 18 | + |
| 19 | +const int IN1_PIN = 6; |
| 20 | +const int IN2_PIN = 7; |
| 21 | +int freq = 10000; |
| 22 | +int ledChannel1 = 0; |
| 23 | +int ledChannel2 = 1; |
| 24 | +int resolution = 10; |
| 25 | +bool direction = true; |
| 26 | +int VIN_PIN = 8; |
| 27 | +int FAULT_PIN = 5; |
| 28 | + |
| 29 | +void setup() { |
| 30 | + auto cfg = M5.config(); |
| 31 | + AtomS3.begin(cfg); |
| 32 | + |
| 33 | + AtomS3.Display.setTextColor(GREEN); |
| 34 | + AtomS3.Display.setTextDatum(middle_center); |
| 35 | + AtomS3.Display.setTextFont(&fonts::Orbitron_Light_24); |
| 36 | + AtomS3.Display.setTextSize(1); |
| 37 | + AtomS3.Display.drawString("H-Driver", AtomS3.Display.width() / 2, |
| 38 | + AtomS3.Display.height() / 2); |
| 39 | + |
| 40 | + ledcSetup(ledChannel1, freq, resolution); |
| 41 | + ledcSetup(ledChannel2, freq, resolution); |
| 42 | + ledcAttachPin(IN1_PIN, ledChannel1); |
| 43 | + ledcAttachPin(IN2_PIN, ledChannel2); |
| 44 | + pinMode(VIN_PIN, INPUT); |
| 45 | + pinMode(FAULT_PIN, INPUT); |
| 46 | + ledcWrite(ledChannel1, 0); |
| 47 | + ledcWrite(ledChannel2, 0); |
| 48 | +} |
| 49 | + |
| 50 | +void loop() { |
| 51 | + if (M5.BtnA.pressedFor(2000)) { |
| 52 | + ledcWrite(ledChannel1, 0); |
| 53 | + ledcWrite(ledChannel2, 0); |
| 54 | + } |
| 55 | + |
| 56 | + if (M5.BtnA.wasPressed()) { |
| 57 | + if (direction) { |
| 58 | + ledcWrite(ledChannel1, 1000); |
| 59 | + ledcWrite(ledChannel2, 0); |
| 60 | + } else { |
| 61 | + ledcWrite(ledChannel1, 0); |
| 62 | + ledcWrite(ledChannel2, 1000); |
| 63 | + } |
| 64 | + direction = !direction; |
| 65 | + } |
| 66 | + |
| 67 | + M5.update(); |
| 68 | + Serial.println("VIN IN: " + |
| 69 | + String((analogRead(VIN_PIN) * 10.0 / 4095.0) * 3.6)); |
| 70 | + if (digitalRead(FAULT_PIN) == 0) { |
| 71 | + Serial.println("FAULT!"); |
| 72 | + } |
| 73 | +} |
0 commit comments