Created
April 13, 2014 19:31
-
-
Save maykonchagas/10598794 to your computer and use it in GitHub Desktop.
motor-passo na mão
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
/* | |
Stepper Motor Controller | |
language: Wiring/Arduino | |
This program drives a unipolar or bipolar stepper motor. | |
The motor is attached to digital pins 8 and 9 of the Arduino. | |
The motor moves 100 steps in one direction, then 100 in the other. | |
Created 11 Mar. 2007 | |
Modified 7 Apr. 2007 | |
by Tom Igoe | |
*/ | |
// define the pins that the motor is attached to. You can use | |
// any digital I/O pins. | |
#define motorPin1 9 | |
#define motorPin2 10 | |
#define motorPin3 9 | |
#define motorPin4 10 | |
#define ledPin 13 | |
void setup() { | |
// set the motor speed at 60 RPMS: | |
pinMode(motorPin1, OUTPUT); | |
pinMode(motorPin2, OUTPUT); | |
pinMode(motorPin3, OUTPUT); | |
pinMode(motorPin4, OUTPUT); | |
// Initialize the Serial port: | |
Serial.begin(9600); | |
// set up the LED pin: | |
pinMode(ledPin, OUTPUT); | |
// blink the LED: | |
blink(3); | |
} | |
void loop() { | |
// Step forward 100 steps: | |
digitalWrite(motorPin1, HIGH); | |
delay(10); | |
digitalWrite(motorPin1, LOW); | |
delay(10); | |
Serial.println("Forward"); | |
digitalWrite(motorPin2, HIGH); | |
delay(10); | |
digitalWrite(motorPin2, LOW); | |
delay(10); | |
Serial.println("Forward"); | |
digitalWrite(motorPin3, HIGH); | |
delay(10); | |
digitalWrite(motorPin3, LOW); | |
delay(10); | |
Serial.println("Forward"); | |
digitalWrite(motorPin4, HIGH); | |
delay(10); | |
digitalWrite(motorPin4, LOW); | |
delay(10); | |
Serial.println("Forward"); | |
/* | |
// Step backward 100 steps: | |
Serial.println("Backward"); | |
myStepper.step(-100); | |
delay(50); | |
*/ | |
} | |
// Blink the reset LED: | |
void blink(int howManyTimes) { | |
int i; | |
for (i=0; i< howManyTimes; i++) { | |
digitalWrite(ledPin, HIGH); | |
delay(200); | |
digitalWrite(ledPin, LOW); | |
delay(200); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment