|
| 1 | +/** |
| 2 | + * @file AtomicMotion.ino |
| 3 | + * @author SeanKwok ([email protected]) |
| 4 | + * @brief M5AtomS3 Atomic Motion Test |
| 5 | + * @version 0.1 |
| 6 | + * @date 2024-01-24 |
| 7 | + * |
| 8 | + * |
| 9 | + * @Hardwares: M5AtomS3 + Atomic Motion |
| 10 | + * @Platform Version: Arduino M5Stack Board Manager v2.0.9 |
| 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 | + * M5AtomicMotion: https://github.com/m5stack/M5Atomic-Motion |
| 16 | + */ |
| 17 | + |
| 18 | +#include "M5AtomS3.h" |
| 19 | +#include "M5AtomicMotion.h" |
| 20 | + |
| 21 | +M5AtomicMotion AtomicMotion; |
| 22 | + |
| 23 | +void setup() { |
| 24 | + auto cfg = M5.config(); |
| 25 | + AtomS3.begin(cfg); |
| 26 | + |
| 27 | + AtomS3.Display.setTextColor(GREEN); |
| 28 | + AtomS3.Display.setTextDatum(middle_center); |
| 29 | + AtomS3.Display.setTextSize(2); |
| 30 | + AtomS3.Display.drawString("Atomic Init", AtomS3.Display.width() / 2, |
| 31 | + AtomS3.Display.height() / 2); |
| 32 | + while ( |
| 33 | + !AtomicMotion.begin(&Wire, M5_ATOMIC_MOTION_I2C_ADDR, 38, 39, 100000)) { |
| 34 | + AtomS3.Display.clear(); |
| 35 | + AtomS3.Display.drawString("Init Fail", AtomS3.Display.width() / 2, |
| 36 | + AtomS3.Display.height() / 2); |
| 37 | + Serial.println("Atomic Motion begin failed"); |
| 38 | + delay(1000); |
| 39 | + } |
| 40 | + AtomS3.Display.clear(); |
| 41 | + AtomS3.Display.drawString("Motion", AtomS3.Display.width() / 2, |
| 42 | + AtomS3.Display.height() / 2); |
| 43 | + |
| 44 | + Serial.println("Atomic Motion Test"); |
| 45 | +} |
| 46 | + |
| 47 | +void loop() { |
| 48 | + for (int ch = 0; ch < 2; ch++) { |
| 49 | + AtomicMotion.setMotorSpeed(ch, 127); |
| 50 | + Serial.printf("Motor Channel %d: %d \n", ch, |
| 51 | + AtomicMotion.getMotorSpeed(ch)); |
| 52 | + } |
| 53 | + delay(1000); |
| 54 | + for (int ch = 0; ch < 2; ch++) { |
| 55 | + AtomicMotion.setMotorSpeed(ch, -127); |
| 56 | + Serial.printf("Motor Channel %d: %d \n", ch, |
| 57 | + AtomicMotion.getMotorSpeed(ch)); |
| 58 | + } |
| 59 | + delay(1000); |
| 60 | + for (int ch = 0; ch < 2; ch++) { |
| 61 | + AtomicMotion.setMotorSpeed(ch, 0); |
| 62 | + Serial.printf("Motor Channel %d: %d \n", ch, |
| 63 | + AtomicMotion.getMotorSpeed(ch)); |
| 64 | + } |
| 65 | + delay(1000); |
| 66 | + for (int ch = 0; ch < 4; ch++) { |
| 67 | + AtomicMotion.setServoAngle(ch, 180); |
| 68 | + Serial.printf("Servo Channel %d: %d \n", ch, |
| 69 | + AtomicMotion.getServoAngle(ch)); |
| 70 | + } |
| 71 | + delay(1000); |
| 72 | + for (int ch = 0; ch < 4; ch++) { |
| 73 | + AtomicMotion.setServoAngle(ch, 0); |
| 74 | + Serial.printf("Servo Channel %d: %d \n", ch, |
| 75 | + AtomicMotion.getServoAngle(ch)); |
| 76 | + } |
| 77 | + delay(1000); |
| 78 | +} |
0 commit comments