Main

Research & Learning

Class pages

Shop Admin

ITP Help Pages
Tom's pcomp site
DanO's pcomp site


L293arduinocode

/* simpleMotor

 * ---------------- 
 */

//the H bridge takes two inputs from the Arduino to control the motor.

int motorPin0 = 2; int motorPin1 = 3; // there is one switch int switchPin = 4; //declare the state variable int state = 0;

void setup() {

  //the motor control wires are outputs
  pinMode(motorPin0, OUTPUT);
  pinMode(motorPin1, OUTPUT);
  //the switch is an input
  pinMode(switchPin, INPUT);

}

void loop() {

  //read the switch
  state = digitalRead(switchPin);
  //based on the state of the switch alternate the control pins to change he direction of the motor.
  switch (state){
  case 0:
    digitalWrite(motorPin0, HIGH);
    digitalWrite(motorPin1, LOW);
    break;
  case 1:
    digitalWrite(motorPin0, LOW);
    digitalWrite(motorPin1, HIGH);
    break;
  }

}

  Edit | View | History | Print | Recent Changes | Search Page last modified on February 13, 2007, at 11:05 PM