11.07.2015 Views

Step 1: Hardware Introduction - CooCox

Step 1: Hardware Introduction - CooCox

Step 1: Hardware Introduction - CooCox

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

$sudo ./Motor<strong>Step</strong>perMotor Shield Demo -- <strong>Step</strong>permain.c:#include "arduPi.h"#include "<strong>Step</strong>per.h"const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution// for your motor// initialize the stepper library on pins 8 through 13:<strong>Step</strong>per my<strong>Step</strong>per(stepsPerRevolution, 8,9,12,13);int stepCount = 0;unsigned char str[20];void setup() {Serial.begin(115200);}void loop() {my<strong>Step</strong>per.step(1);Serial.print("steps:" );myitoa(stepCount, str)Serial.println(str);stepCount++;delay(50);}// number of steps the motor has taken// initialize the serial port:// step one step://print the stepsint main (){setup();while(1){loop();}return (0);}You can see the stepper motor rotates when the program is running, you will see the serial outputeffect. Diagram as follow:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!