Advertisement
gabbyshimoni

stop DC motor in 2 ways

Feb 14th, 2019
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #define motorPin1 7
  2. #define motorPin2 8
  3. #define motorEnaPin 9
  4. #define pbPin1 3
  5. #define pbPin2 4
  6. int pbVal1 = 0, pbVal2 = 0;
  7.  
  8. void setup() {
  9.   pinMode(motorPin1, OUTPUT);
  10.   pinMode(motorPin2, OUTPUT);
  11.   pinMode(motorEnaPin, OUTPUT);
  12.  
  13.   pinMode(pbPin1, INPUT);
  14.   pinMode(pbPin2, INPUT);
  15.  
  16. }
  17.  
  18. void loop() {
  19.   // המנוע מתחיל בתנועה
  20.   digitalWrite(motorEnaPin, HIGH);
  21.   digitalWrite(motorPin1, HIGH);
  22.   digitalWrite(motorPin2, LOW);
  23.  
  24.   pbVal1 = digitalRead(pbPin1);
  25.   pbVal2 = digitalRead(pbPin2);
  26. // לחיצה על כפתור 1 יגרום לעצירה על ידי פין המהירות (פין 1 או 9)
  27.   if (pbVal1 == HIGH && pbVal2 == LOW) {
  28.     digitalWrite(motorEnaPin, LOW);
  29.   }
  30. // לחיצה על כפתור 2 יגרום לעצירה על ידי מיתוג שני הפינים המקושרים למנוע בדוחף הזרם
  31.   if (pbVal2 == HIGH && pbVal1 == LOW) {
  32.     digitalWrite(motorPin1, LOW);
  33.     digitalWrite(motorPin2, LOW);
  34.   }
  35. // לחיצה על שני הכפתורים יגרום להיפוך כיוון הסיבוב
  36.   if (pbVal2 == HIGH && pbVal1 == HIGH) {
  37.     digitalWrite(motorPin1, LOW);
  38.     digitalWrite(motorPin2, HIGH);
  39.   }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement