Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //The first step was to initiallize my pins.
- //They are named, and are addressed to the pins which I use on the board
- const int switchPin = 2; // switch input, I am using a button
- const int motor1Pin = 3; // For the H-bridge first pin
- const int motor2Pin = 4; // For the H-bridge second pin
- const int enablePin = 9; // Enable pin
- void setup() {
- //The first step was to initialize which pins were inputs and
- //which were outputs.
- pinMode(switchPin, INPUT);//pin 2
- pinMode(motor1Pin, OUTPUT);//pin 3
- pinMode(motor2Pin, OUTPUT);//pin 4
- pinMode(enablePin, OUTPUT);// pin 9
- //Next, I want to set the enable pin, the on. This means, as soon as
- //I m connected to power, the motor will turn on, and spin in one
- //direction
- digitalWrite(enablePin, HIGH);
- }
- void loop() {
- //Now I want my board to read if the button is being pushed or not.
- // if it IS, then the switchpin is HIGH, and it will enter this loop
- if (digitalRead(switchPin) == HIGH) {
- //first I set the first H-bridge pin to HIGH, or sending power
- //to that side so it will spin in one direction
- digitalWrite(motor1Pin, HIGH);
- //Then I set the second H-bridge pin to LOW, so it will on spin
- //one way.
- digitalWrite(motor2Pin, LOW);
- }
- // if the button is not being pressed, I was the motor to spin the
- //opposite direction, So I just need to switch which H-bridge pin
- //is HIGH.
- else {
- digitalWrite(motor2Pin, HIGH);
- digitalWrite(motor1Pin, LOW);
- }
- }
Add Comment
Please, Sign In to add comment