Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- uint8_t X_potPin = A0;
- uint8_t X_servoPin = 9;
- int X_ledPin = 3;
- uint8_t Y_potPin = A1;
- uint8_t Y_servoPin = 10;
- int Y_ledPin = 5;
- int X_potVal;
- int OLD_X_potVal;
- int Y_potVal;
- int OLD_Y_potVal;
- boolean usePot = true;
- boolean sendValues = true;
- Servo X_servo;
- Servo Y_servo;
- void setup() {
- Serial.begin(9600);
- Serial.println("CameraOperator 2.0");
- X_servo.attach(X_servoPin);
- Y_servo.attach(Y_servoPin);
- }
- void loop() {
- if (usePot == true) {
- X_potVal = analogRead(X_potPin);
- X_potVal = map(X_potVal, 0, 1023,0,180);
- X_servo.write(X_potVal);
- Y_potVal = analogRead(Y_potPin);
- Y_potVal = map(Y_potVal, 0, 1023,0,180);
- Y_servo.write(Y_potVal);
- }
- if (sendValues == true) {
- if (OLD_X_potVal != X_potVal) {
- Serial.print("X: ");
- Serial.println(X_potVal);
- }
- OLD_X_potVal = X_potVal;
- if (OLD_Y_potVal != Y_potVal) {
- Serial.print(" Y: ");
- Serial.println(Y_potVal);
- }
- OLD_Y_potVal = Y_potVal;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement