Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- Servo myservo; // create servo object to control a servo
- int pos = 0; // variable to store the servo position
- int minx = 0; //local minimum vertical hieght
- int trans = 180; //var for changing position from A1 rheostat
- int lim = 25; // the limit: varies based on physical factors
- int HOME = 100;
- void setup() {
- //delay(5000);
- Serial.begin(9600);
- myservo.attach(9); // attaches the servo on pin 9 to the servo object is pin9 ==A0?
- pos = myservo.read(); // if the servo is high, or low set servo position to 0
- if (pos > 0 || pos < 0){
- // myservo.write(30); //directdrive servo mech
- myservo.write(HOME); //init position for rack and pinion
- //delay(3000);
- }
- }
- void loop() {
- //int sensorValue = analogRead(A1); //resistors on PSU shouldnt change
- //Serial.println(sensorValue);
- int sv = analogRead(A0); //sensor value
- int trans = analogRead(A1);
- //Serial.println(sv);
- //Serial.println(pos);
- pos = trans / lim; //0 - 26
- //myservo.write(pos+100);
- //Serial.println(trans); //
- //myservo.write(-trans);
- if(sv < 200){
- myservo.write(HOME-pos);
- } else{
- //myservo.write(trans);
- myservo.write(HOME);
- }
- //if(sensorValue > 900){ // its done drawing, and out of range anyways
- if (sv > 600 ){
- myservo.write(HOME); // go back to neutral position
- //delay(5);
- }
- /* */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement