summaryrefslogtreecommitdiff
path: root/trunk/darwin/electronics/Arduino-Sanguino/dc-motor-driver/exerciser/stepper_driver/stepper_driver.pde
blob: 666b9e3fcef97c4e18216777023b0b8ad457bc48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 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 by Tom Igoe
 Modified 7 Apr. 2007 by Tom Igoe
 Modified 25 Oct. 2007 by Zach Smith

*/

#include <Stepper.h>

// change this depending on the number of steps per revolution of your motor
#define motorSteps 200

// define the pins that the motor is attached to. You can use any digital I/O pins.
#define motorPin1 8
#define motorPin2 9

// initialize of the Stepper library:
Stepper myStepper(motorSteps, motorPin1, motorPin2); 

void setup()
{
	Serial.begin(9600);
	Serial.println('Starting stepper exerciser.');
}

void loop()
{
	int i;

	for (i=25; i<=60; i+=5)
	{
		//set our new motor speed
		Serial.print("Speed ");
		Serial.println(i);
		myStepper.setSpeed(i);

		// Step forward 200 steps:
		Serial.println("Forward");
		myStepper.step(200);
		delay(500);

		// Step backward 200 steps:
		Serial.println("Backward");
		myStepper.step(-200);
		delay(500); 

	}

	for (i=60; i>=; i-=5)
	{
		//set our new motor speed
		Serial.print("Speed ");
		Serial.println(i);
		myStepper.setSpeed(i);

		// Step forward 200 steps:
		Serial.println("Forward");
		myStepper.step(200);
		delay(500);

		// Step backward 200 steps:
		Serial.println("Backward");
		myStepper.step(-200);
		delay(500); 
	}
}