
Arduino Quick Start
Environment Configuration: Refer to the Arduino IDE Quick Start Tutorial to install the IDE, add the board manager entries for your board, and install any required drivers and libraries.
Driver libraries used:
Hardware products used:


G6 (IN1) and G7 (IN2).#include "M5Unified.h"
const int IN1_PIN = 6;
const int IN2_PIN = 7;
const int VIN_PIN = 8;
const int FAULT_PIN = 5;
int freq = 10000;
int resolution = 10;
bool direction = true;
void setup() {
M5.begin();
M5.Display.setTextColor(GREEN);
M5.Display.setTextDatum(middle_center);
M5.Display.setFont(&fonts::Orbitron_Light_24);
M5.Display.drawString("H-Driver", M5.Display.width() / 2, M5.Display.height() / 2);
ledcAttach(IN1_PIN, freq, resolution);
ledcAttach(IN2_PIN, freq, resolution);
pinMode(VIN_PIN, INPUT);
pinMode(FAULT_PIN, INPUT);
ledcWrite(IN1_PIN, 0);
ledcWrite(IN2_PIN, 0);
}
void loop() {
if (M5.BtnA.pressedFor(1000)) {
ledcWrite(IN1_PIN, 0);
ledcWrite(IN2_PIN, 0);
}
if (M5.BtnA.wasPressed()) {
if (direction) {
ledcWrite(IN1_PIN, 300);
ledcWrite(IN2_PIN, 0);
} else {
ledcWrite(IN1_PIN, 0);
ledcWrite(IN2_PIN, 300);
}
direction = !direction;
}
M5.update();
if (digitalRead(FAULT_PIN) == 0) {
M5.Display.clear();
M5.Display.drawString("FAULT!", M5.Display.width() / 2, M5.Display.height() / 2);
}
}