Advertisement
marquessamackenzie

DIGF 2002 - Arduino Motor and Button Assignment 10/08/19

Oct 8th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. /*
  2. Project Name: Week 5 In Class Assignment
  3. Goal: Program DC Motor to Switch Directions After Pressing Button
  4. Name: Marquessa MacKenzie
  5. Date: October 8th, 2019
  6. Resources: http://www.arduino.cc/en/Tutorial/Button
  7. http://www.arduino.cc/en/Tutorial/DigitalReadSerial
  8. */
  9.  
  10.  
  11. void setup() {
  12. // put your setup code here, to run once:
  13. pinMode(11, OUTPUT); //Setting Pin 11 to Output for Motor
  14. pinMode(12, OUTPUT); //Setting Pin 12 to Output for Motor
  15. pinMode(8, INPUT); // Setting Pin 8 to Input for Button
  16. Serial.begin(9600); // Ensuring Troubleshooting Readout Is Set Up on Serial Monitor
  17. }
  18.  
  19. void loop() {
  20. // put your main code here, to run repeatedly:
  21. if (digitalRead(8) == HIGH) { //If the button is pressed then do the following:
  22. digitalWrite (11, HIGH); // Turn the motor forward
  23. digitalWrite (12, LOW);
  24. Serial.println("The button is pressed!"); // Readout on monitor will read "The button is pressed!"
  25. } else if (digitalRead(8) == LOW) { //If the button is not pressed then do the following:
  26. digitalWrite (11, LOW); // Turn the motor backward
  27. digitalWrite (12, HIGH);
  28. Serial.println("Not Pressed"); // Readout on monitor will read "Not Pressed"
  29.  
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement