Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. // ---------- hardware pin defines -----------
  4. int sensorPin = A0; // select the input pin for the potentiometer
  5.  
  6. // ---------- variable initialization -----------
  7. int sensorValue = 0; // variable to store the value coming from the sensor
  8. int delayTime = 0; //variable that holds the delay time in milliseconds
  9. int scaling = 1;
  10. int maxValue = 750;
  11. int minValue = 300;
  12.  
  13.  
  14. // ---------- library initialization -----------
  15. Servo myservo; // create servo object to control a servo a maximum of eight servo objects can be created
  16.  
  17. void setup() {
  18. Serial.begin(9600);
  19. // declare hardware connections
  20. myservo.attach(9); // attaches the servo on pin 9 to the servo object
  21. }
  22.  
  23. void loop() {
  24. // Input
  25. sensorValue = analogRead(sensorPin);
  26. // Debugging
  27. Serial.print("Sensor value: "); Serial.println(sensorValue);
  28.  
  29.  
  30. // Processing
  31. //Scaling
  32. delayTime = map (sensorValue, minValue, maxValue, 200, 1023);
  33. Serial.print ("Delay in milliseconds: "); Serial.println (delayTime);
  34. // Modes
  35. // None - put new modes here
  36.  
  37. // Output
  38. myservo.write(155);
  39. delay(delayTime);
  40. myservo.write(30);
  41. delay(delayTime);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement