Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Project Name: Week 5 In Class Assignment
- Goal: Program DC Motor to Switch Directions After Pressing Button
- Name: Marquessa MacKenzie
- Date: October 8th, 2019
- Resources: http://www.arduino.cc/en/Tutorial/Button
- http://www.arduino.cc/en/Tutorial/DigitalReadSerial
- */
- void setup() {
- // put your setup code here, to run once:
- pinMode(11, OUTPUT); //Setting Pin 11 to Output for Motor
- pinMode(12, OUTPUT); //Setting Pin 12 to Output for Motor
- pinMode(8, INPUT); // Setting Pin 8 to Input for Button
- Serial.begin(9600); // Ensuring Troubleshooting Readout Is Set Up on Serial Monitor
- }
- void loop() {
- // put your main code here, to run repeatedly:
- if (digitalRead(8) == HIGH) { //If the button is pressed then do the following:
- digitalWrite (11, HIGH); // Turn the motor forward
- digitalWrite (12, LOW);
- Serial.println("The button is pressed!"); // Readout on monitor will read "The button is pressed!"
- } else if (digitalRead(8) == LOW) { //If the button is not pressed then do the following:
- digitalWrite (11, LOW); // Turn the motor backward
- digitalWrite (12, HIGH);
- Serial.println("Not Pressed"); // Readout on monitor will read "Not Pressed"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement