Examples - Sensorboard - StepMotor
Step Motor
This Example shows the use of a Step Motor.
/************************************************************************************************** * * Step Motor * * Version: 1.0.0 - Januar 2009 * Author: Etienne Ribeiro / tutorial assistant caad / eribeiro[at]ethz.ch * Supervisor: Christoph Wartmann / chair for caad - ETH Zürich / wartmann[at].arch.ethz.ch * * Desc: Shows the use of a Step Motor on digital pin. * ***************************************************************************************************/ // Const static int digitalButtonPin[] = {8, 9}; static int digitalOutPin[] = {12, 13, 14, 15}; static boolean enableSerial = false; // Setup void setup() { pinMode(48, OUTPUT); digitalWrite(48, HIGH); delay(200); digitalWrite(48, LOW); delay(200); digitalWrite(48, HIGH); // Serial if (enableSerial == true) Serial.begin(9600); // pinMode pinMode(digitalButtonPin[0], INPUT); pinMode(digitalButtonPin[1], INPUT); for (int i=0; i<3; i++) { pinMode(i, OUTPUT); } } // Loop void loop() { // Foreward if (digitalRead(digitalButtonPin[0]) == LOW) { if (enableSerial == true) Serial.println(" Stepmotor forward"); stepforward(); } // Backward if (digitalRead(digitalButtonPin[1]) == LOW) { if (enableSerial == true) Serial.println(" Stepmotor backward"); stepbackward(); } // Serial if (enableSerial == true) { Serial.print(" Stepmotor "); Serial.println(""); } } // Stepforward void stepforward() { digitalWrite(digitalOutPin[0], HIGH); digitalWrite(digitalOutPin[1], LOW); digitalWrite(digitalOutPin[2], LOW); digitalWrite(digitalOutPin[3], LOW); delay(30); digitalWrite(digitalOutPin[0], LOW); digitalWrite(digitalOutPin[1], HIGH); digitalWrite(digitalOutPin[2], LOW); digitalWrite(digitalOutPin[3], LOW); delay(30); digitalWrite(digitalOutPin[0], LOW); digitalWrite(digitalOutPin[1], LOW); digitalWrite(digitalOutPin[2], HIGH); digitalWrite(digitalOutPin[3], LOW); delay(30); digitalWrite(digitalOutPin[0], LOW); digitalWrite(digitalOutPin[1], LOW); digitalWrite(digitalOutPin[2], LOW); digitalWrite(digitalOutPin[3], HIGH); delay(30); } // Stepbackward void stepbackward() { digitalWrite(digitalOutPin[0], LOW); digitalWrite(digitalOutPin[1], LOW); digitalWrite(digitalOutPin[2], LOW); digitalWrite(digitalOutPin[3], HIGH); delay(30); digitalWrite(digitalOutPin[0], LOW); digitalWrite(digitalOutPin[1], LOW); digitalWrite(digitalOutPin[2], HIGH); digitalWrite(digitalOutPin[3], LOW); delay(30); digitalWrite(digitalOutPin[0], LOW); digitalWrite(digitalOutPin[1], HIGH); digitalWrite(digitalOutPin[2], LOW); digitalWrite(digitalOutPin[3], LOW); delay(30); digitalWrite(digitalOutPin[0], HIGH); digitalWrite(digitalOutPin[1], LOW); digitalWrite(digitalOutPin[2], LOW); digitalWrite(digitalOutPin[3], LOW); delay(30); }