safwan092

Untitled

Jan 10th, 2024
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. int buttonPin1 = 3;
  2. int buttonPin2 = 4;
  3. int motorPin1 = 5; //PWM ~
  4. int motorPin2 = 6; //PWM ~
  5.  
  6. int buttonState1 = 0;
  7. int buttonState2 = 0;
  8.  
  9. void setup() {
  10. Serial.begin(9600);
  11. pinMode(buttonPin1, INPUT_PULLUP);
  12. pinMode(buttonPin2, INPUT_PULLUP);
  13. pinMode(motorPin1, OUTPUT);
  14. pinMode(motorPin2, OUTPUT);
  15. digitalWrite(motorPin1, LOW);
  16. digitalWrite(motorPin2, LOW);
  17.  
  18. }
  19.  
  20. void loop() {
  21.  
  22. buttonState1 = digitalRead(buttonPin1);
  23. buttonState2 = digitalRead(buttonPin2);
  24. Serial.print(buttonState1);
  25. Serial.print(" ");
  26. Serial.println(buttonState2);
  27. if (buttonState1 == 0) {
  28. Serial.println("UP");
  29. digitalWrite(motorPin1, LOW);
  30. digitalWrite(motorPin2, HIGH);
  31. delay(60000);
  32. }
  33. if (buttonState2 == 0) {
  34. Serial.println("DOWN");
  35. digitalWrite(motorPin2, LOW);
  36. digitalWrite(motorPin1, HIGH);
  37. delay(60000);
  38. }
  39. else {
  40. Serial.println("Stop");
  41. digitalWrite(motorPin1, HIGH);
  42. digitalWrite(motorPin2, HIGH);
  43. }
  44. }
Add Comment
Please, Sign In to add comment