Advertisement
j0h

drawn2u.ino

j0h
Sep 28th, 2024
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Servo.h>
  2. Servo myservo;  // create servo object to control a servo
  3.            
  4. int pos = 0;    // variable to store the servo position
  5. int minx = 0;   //local minimum vertical hieght
  6. int trans = 180;  //var for changing position from A1 rheostat
  7. int lim = 25;   // the limit: varies based on physical factors
  8. int HOME = 100;
  9. void setup() {
  10.   //delay(5000);
  11.   Serial.begin(9600);
  12.   myservo.attach(9);       // attaches the servo on pin 9 to the servo object is pin9 ==A0?
  13.   pos = myservo.read();    // if the servo is high, or low set servo position to 0
  14.   if (pos > 0 || pos < 0){
  15.  // myservo.write(30);       //directdrive servo mech
  16.  myservo.write(HOME); //init position for rack and pinion
  17.  //delay(3000);
  18.   }
  19. }
  20.  
  21. void loop() {
  22. //int sensorValue = analogRead(A1); //resistors on PSU shouldnt change
  23. //Serial.println(sensorValue);
  24. int sv = analogRead(A0);      //sensor value
  25. int trans = analogRead(A1);
  26.  
  27. //Serial.println(sv);
  28.  //Serial.println(pos);
  29.  pos = trans / lim; //0 - 26
  30.   //myservo.write(pos+100);  
  31.  //Serial.println(trans);  //
  32. //myservo.write(-trans);
  33.  
  34. if(sv < 200){
  35.   myservo.write(HOME-pos);  
  36. } else{
  37.       //myservo.write(trans);
  38.       myservo.write(HOME);
  39.       }
  40. //if(sensorValue > 900){ // its done drawing, and out of range anyways
  41. if (sv > 600 ){
  42. myservo.write(HOME);       // go back to neutral position
  43. //delay(5);
  44.  }
  45. /* */
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement