Thursday, December 26, 2013
Arduinostepperproject1
/*
AdaFruit motor shield, 12v. motor, 2 buttons.
Motor moves counterclockwise when button1 is pressed (HIGH).
Motor moves clockwise when button2 is pressed.
If a button is not pressed motor is released.
*/
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *myMotor1 = AFMS.getStepper(200, 1);
const int buttonPin1 = 2; // the number of the pushbutton pin
const int buttonPin2 = 3;
// variables will change:
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0;
void setup() {
AFMS.begin(1600); // OR with a different frequency, say 1KHz
myMotor1->setSpeed(800);
pinMode(buttonPin1, INPUT); // initialize the pushbutton pin as an input:
}
void loop()
{
buttonState1 = digitalRead(buttonPin1); // read the state of the pushbutton value:
buttonState2 = digitalRead(buttonPin2);
// check if the pushbutton is pressed.
if (buttonState1 != 0) // if it is, the buttonState is HIGH:
{
myMotor1->step(HIGH, FORWARD, DOUBLE);//counterclockwise
}
if (buttonState2 != 0) {
myMotor1->step(HIGH, BACKWARD, DOUBLE);//clockwise
}
else( myMotor1-> release());
}
Subscribe to:
Post Comments
(
Atom
)





No comments :
Post a Comment