Advertisement
CA99

TestRig

Oct 19th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. // A test rig for Project Tagbot's brushless flywheel system.
  2.  
  3. //#include <Serial.h>
  4. # include <Servo.h>
  5.  
  6. const int escPin = A0;
  7. const int potPin = A1;
  8. const int minSpeed = 1000;
  9. const int maxSpeed = 2000;
  10. const int inThreshold = 10;
  11.  
  12. int currentSpeed;
  13.  
  14. Servo esc;
  15.  
  16. void setup() {
  17. pinMode(potPin, INPUT);
  18. esc.attach(escPin);
  19. //esc.writeMicroseconds(1000);
  20. Serial.begin(9600);
  21. Serial.println("start");
  22. }
  23.  
  24. /**/
  25.  
  26. void loop() {
  27.  
  28. currentSpeed = getOutputSpeed(analogRead(potPin));
  29.  
  30. Serial.println(currentSpeed);
  31. esc.writeMicroseconds(currentSpeed);
  32.  
  33. /*if (Serial.available()) {
  34. currentSpeed = Serial.parseInt();
  35. }*/
  36. }
  37.  
  38. int getOutputSpeed(int inVal) {
  39. /*if (inVal < inThreshold) {
  40. return 0;
  41. }
  42. else {
  43. return map(inVal, inThreshold, 1023, minSpeed, maxSpeed);
  44. }*/
  45.  
  46. return map(inVal, 0, 1023, minSpeed, maxSpeed);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement