Advertisement
j0h

Servo Draw arduino Code

j0h
Feb 18th, 2020
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <Servo.h>
  2.  /*
  3. //arduino code for controling server that drives drawing machine
  4.  A0 is the servo
  5.  A1 is the potentiometer for fine turning height
  6.  
  7.  */
  8. Servo myservo;  // create servo object to control a servo
  9.            
  10. int pos = 0;    // variable to store the servo position
  11. int minx = 0;
  12. int trans = 0; //var for changing var from A1
  13. int lim = 25;
  14. void setup() {
  15.   //delay(5000);
  16.   Serial.begin(9600);
  17.   myservo.attach(9);       // attaches the servo on pin 9 to the servo object is pin9 ==A0?
  18.   pos = myservo.read();    // if the servo is high, or low set servo position to 0
  19.   if (pos > 0 || pos < 0){
  20.   myservo.write(30);
  21.   }
  22. }
  23.  
  24. void loop() {
  25. int sensorValue = analogRead(A0); //resistors on PSU shouldnt change
  26. Serial.println(sensorValue);
  27. int sv = analogRead(A1);      
  28.     trans = (lim - (sv/40));    
  29. if(sensorValue < 100){
  30.   myservo.write(minx);
  31. } else{
  32.       myservo.write(trans);
  33.       }
  34. if(sensorValue > 1000){ // its done drawing, and out of range anyways
  35. myservo.write(30);       // go back to neutral position
  36. delay(300);
  37.  }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement