Advertisement
Vendrick-Xander

board comp bridge code

Jan 24th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. const int onOffB = 2;
  2. const int rotateB = 3;
  3. const int potIn = A0;
  4. const int speedOutPin = 6;
  5. const int directionPinOut = 4;
  6. const int onOffOut = 5;
  7. bool onOff = false;
  8. bool CW_CCW = true;
  9. void setup() {
  10. pinMode(onOffB, INPUT);
  11. pinMode(rotateB, INPUT);
  12. pinMode(potIn, INPUT);
  13. pinMode(speedOutPin, OUTPUT);
  14. pinMode(directionPinOut, OUTPUT);
  15. pinMode(onOffOut, OUTPUT);
  16. Serial.begin(9600);
  17. do
  18. {
  19. Serial.println("Direction true is CW");
  20. }
  21. while(!Serial);
  22. }
  23.  
  24. void loop() {
  25. onOff = debounce(onOff, onOffB);
  26. CW_CCW = debounce(CW_CCW, rotateB);
  27. int speedVal = analogRead(potIn);
  28. if(onOff)
  29. {
  30. motorRun(CW_CCW, speedVal);
  31. Serial.println("Entered IF");
  32. }
  33. }
  34. void motorRun(bool dir, int speedVal)
  35. {
  36. speedVal = map(speedVal, 0, 1023, 0 , 255);
  37. digitalWrite(directionPinOut, dir);
  38. analogWrite(speedOutPin, speedVal);
  39. Serial.println(dir);
  40. Serial.println(speedVal);
  41. }
  42. bool debounce(bool prev, int pin)
  43. {
  44. bool current = digitalRead(pin);
  45. delay(10);
  46. if(current != prev)
  47. {
  48. current = digitalRead(pin);
  49. }
  50. return current;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement