Skip to content

Instantly share code, notes, and snippets.

@houhr
Created March 12, 2015 02:56
Show Gist options
  • Save houhr/430ec758c22763d6b554 to your computer and use it in GitHub Desktop.
Save houhr/430ec758c22763d6b554 to your computer and use it in GitHub Desktop.
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);
int onOffSwitch = 8;
String currentTimeZone = "SF";
int switchState = 0;
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
pinMode(onOffSwitch, INPUT);
AFMS.begin(); // create with the default frequency 1.6KHz
myMotor->setSpeed(10); // 10 rpm
}
void loop() {
switchState = digitalRead(onOffSwitch);
// BJ time
if (switchState == 1 && currentTimeZone == "SF") {
currentTimeZone = "BJ";
myMotor->step(15/1.8*16, FORWARD, MICROSTEP);
}
// SF time
if (switchState == 0 && currentTimeZone == "BJ") {
currentTimeZone = "SF";
myMotor->step(15/1.8*16, BACKWARD, MICROSTEP);
}
Serial.println(currentTimeZone);
myMotor->step(15/1.8, FORWARD, MICROSTEP);
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment