Skip to content
Browse files

initial add

  • Loading branch information...
0 parents commit 227f16d09c0826bfb41acb2d90ca52f5cfd57232 @orlandov committed Nov 9, 2008
Showing with 44 additions and 0 deletions.
  1. +1 −0 Makefile
  2. +43 −0 motor.pde
1 Makefile
43 motor.pde
@@ -0,0 +1,43 @@
+// vim:ft=c
+//the H bridge takes two outputs from the Arduino to control the motor.
+byte pwm_pin = 9;
+byte motor_pin0 = 2;
+byte motor_pin1 = 3;
+
+// potentiometer
+byte pot_pin = 4;
+
+// direction switch
+byte switch_pin = 4;
+
+//declare the state variable
+byte state = 0;
+
+void setup() {
+ // setup the motor control pins as outputs
+ pinMode(motor_pin0, OUTPUT);
+ pinMode(motor_pin1, OUTPUT);
+ pinMode(pwm_pin, OUTPUT);
+ pinMode(switch_pin, INPUT);
+ pinMode(pot_pin, INPUT);
+ analogWrite(pwm_pin, 255);
+}
+
+void loop() {
+ // read the pot
+ byte duty_cycle = analogRead(pot_pin) / 4;
+ int direction = digitalRead(switch_pin);
+ analogWrite(pwm_pin, duty_cycle);
+ if (direction) {
+ digitalWrite(motor_pin0, LOW);
+ digitalWrite(motor_pin1, HIGH);
+ }
+ else {
+ digitalWrite(motor_pin0, HIGH);
+ digitalWrite(motor_pin1, LOW);
+ }
+}
+
+
+
+

0 comments on commit 227f16d

Please sign in to comment.
Something went wrong with that request. Please try again.