Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- #include<robotarm.h>
- //Define variables
- //Servos
- #define servoClawPin 8
- #define handPin 9
- #define elbowPin 10
- #define shoulderPanPin 11
- #define shoulderTiltPin 12
- #define buttonPin 5
- Servo clawServo;
- Servo handServo;
- Servo elbowServo;
- Servo shoulderPanServo;
- Servo shoulderTiltServo;
- byte clawPosition;
- byte clawPrevPos=144;
- byte handPosition;
- byte handPrevPos=90;
- byte elbowPosition;
- byte elbowPrevPos=90;
- byte shoulderPanPosition;
- byte shoulderPanPrevPos=90;
- byte shoulderTiltPosition;
- byte shoulderTiltPrevPos=90;
- byte hundredByte;
- byte tenByte;
- byte oneByte;
- char hundredChar='0';
- char tenChar='0';
- char oneChar='0';
- byte serialPos;
- char serialServo;
- void setup()
- {
- pinMode(servoClawPin, OUTPUT);
- pinMode(handPin, OUTPUT);
- pinMode(elbowPin, OUTPUT);
- pinMode(shoulderPanPin, OUTPUT);
- pinMode(shoulderTiltPin, OUTPUT);
- Serial.begin(9600);
- clawServo.attach(8);
- handServo.attach(9);
- elbowServo.attach(10);
- shoulderPanServo.attach(11);
- shoulderTiltServo.attach(12);
- pinMode(buttonPin, INPUT);
- elbowPosition = constrain(elbowPosition, 0, 145);
- }
- void loop()
- {
- delay(200);
- if(Serial.available())
- {
- serialServo=Serial.read();
- Serial.println(serialServo);
- }
- if(Serial.available())
- {
- hundredChar=Serial.read();
- Serial.println(hundredChar-'0');
- }
- if(Serial.available())
- {
- tenChar=Serial.read();
- Serial.println(tenChar-'0');
- }
- if (Serial.available())
- {
- oneChar=Serial.read();
- Serial.println(oneChar-'0');
- }
- hundredByte=hundredChar-'0';
- tenByte=tenChar-'0';
- oneByte=oneChar-'0';
- hundredByte=hundredByte*100;
- tenByte=tenByte*10;
- serialPos=hundredByte+tenByte+oneByte;
- Serial.println(serialPos);
- if(serialServo=='c')//claw
- {
- Serial.println("Claw");
- serialPos = constrain(serialPos, 116, 180);
- clawServo.write(serialPos);
- clawPrevPos=serialPos;
- serialServo=' ';
- }
- else if(serialServo=='h')//hand
- {
- Serial.println("hand");
- migrate(handServo,serialPos, 30, handPrevPos);
- //handServo.write(serialPos);
- handPrevPos=serialPos;
- serialServo=' ';
- }
- else if(serialServo=='e')//elbow
- {
- Serial.println("elbow");
- elbowPosition = constrain(serialPos, 0, 145);
- migrate(elbowServo,elbowPosition, 30,elbowPrevPos);
- //elbowServo.write(elbowPosition);
- elbowPrevPos=elbowPosition;
- serialServo=' ';
- }
- else if(serialServo=='p')//shoulderPan
- {
- Serial.println("shoulderPan");
- migrate(shoulderPanServo,serialPos, 30, shoulderPanPrevPos);
- //shoulderPanServo.write(serialPos);
- shoulderPanPrevPos=serialPos;
- serialServo=' ';
- }
- else if(serialServo=='t')//shoulderTilt
- {
- Serial.println("shoulderTilt");
- migrate(shoulderTiltServo,serialPos, 30,shoulderTiltPrevPos);
- //shoulderTiltServo.write(serialPos);
- shoulderTiltPrevPos=serialPos;
- serialServo=' ';
- }
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment