Last active
September 24, 2018 17:37
-
-
Save branw/3d17b499a1015134a4a080b7f9221b5b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <Arduino.h> | |
#include <BasicStepperDriver.h> | |
// Accept a trigger of 's' over Serial1 or Serial2 | |
#define USE_SERIAL_TRIGGER true | |
// Enable the motors only when they are being moved | |
#define DISABLE_MOTORS false | |
const int EAR_LEFT_DIR = 48, EAR_LEFT_STEP = 46, EAR_LEFT_ENABLE = 62; // Z | |
const int EAR_RIGHT_DIR = A1, EAR_RIGHT_STEP = A0, EAR_RIGHT_ENABLE = 38; // X | |
const int NOSE_TOP_DIR = A7, NOSE_TOP_STEP = A6, NOSE_TOP_ENABLE = A2; // Y | |
const int NOSE_LEFT_DIR = 34, NOSE_LEFT_STEP = 36, NOSE_LEFT_ENABLE = 30; // E1 | |
const int NOSE_RIGHT_DIR = 28, NOSE_RIGHT_STEP = 26, NOSE_RIGHT_ENABLE = 24; // E0 | |
const int MOTOR_STEPS = 150; | |
const int RPM = 200; | |
const int MICROSTEPS = 5; | |
BasicStepperDriver ear_left(MOTOR_STEPS, EAR_LEFT_DIR, EAR_LEFT_STEP, EAR_LEFT_ENABLE); | |
BasicStepperDriver ear_right(MOTOR_STEPS, EAR_RIGHT_DIR, EAR_RIGHT_STEP, EAR_RIGHT_ENABLE); | |
BasicStepperDriver nose_top(MOTOR_STEPS, NOSE_TOP_DIR, NOSE_TOP_STEP, NOSE_TOP_ENABLE); | |
BasicStepperDriver nose_left(MOTOR_STEPS, NOSE_LEFT_DIR, NOSE_LEFT_STEP, NOSE_LEFT_ENABLE); | |
BasicStepperDriver nose_right(MOTOR_STEPS, NOSE_RIGHT_DIR, NOSE_RIGHT_STEP, NOSE_RIGHT_ENABLE); | |
void setup() { | |
#if USE_SERIAL_TRIGGER | |
Serial.begin(115200); | |
Serial2.begin(9600); // TX2 on D17 | |
#endif | |
ear_left.begin(RPM, MICROSTEPS); | |
ear_right.begin(RPM, MICROSTEPS); | |
nose_top.begin(150, MICROSTEPS); | |
nose_left.begin(150, MICROSTEPS); | |
nose_right.begin(150, MICROSTEPS); | |
} | |
void loop() { | |
#if USE_SERIAL_TRIGGER | |
if (!Serial2.available() && !Serial.available()) return; | |
if ((Serial2.available() && Serial2.read() != 's') || | |
(Serial.available() && Serial.read() != 's')) return; | |
Serial.println("!\n"); | |
Serial2.println("!\n"); | |
#endif | |
#if DISABLE_MOTORS | |
ear_left.enable(); | |
ear_right.enable(); | |
nose_top.enable(); | |
nose_left.enable(); | |
nose_right.enable(); | |
#endif | |
ear_left.rotate(-30); | |
ear_right.rotate(-30); | |
nose_top.rotate(180); | |
nose_left.rotate(-20); | |
nose_right.rotate(20); | |
delay(50); | |
ear_left.rotate(-30); | |
ear_right.rotate(-30); | |
nose_top.rotate(-180); | |
nose_left.rotate(20); | |
nose_right.rotate(-20); | |
#if DISABLE_MOTORS | |
ear_left.disable(); | |
ear_right.disable(); | |
nose_top.disable(); | |
nose_left.disable(); | |
nose_right.disable(); | |
#endif | |
delay(50); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment