Skip to content

Instantly share code, notes, and snippets.

@kirkjoserey
Created April 3, 2013 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirkjoserey/5306529 to your computer and use it in GitHub Desktop.
Save kirkjoserey/5306529 to your computer and use it in GitHub Desktop.
Joystick Shield Itead Studio + 2 Servos
#include <Servo.h>
Servo Aservo;
Servo Bservo;
const byte PIN_ANALOG_X = 0;
const byte PIN_ANALOG_Y = 1;
const byte PIN_BUTTON_E = 3;
const byte PIN_BUTTON_D = 4;
const byte PIN_BUTTON_SELECT = 5; // Joy Click
const byte PIN_BUTTON_B = 6;
const byte PIN_BUTTON_A = 7;
const byte PIN_BUTTON_F = 8;
const byte PIN_BUTTON_G = 9;
const byte PIN_SERVO_A = 10;
const byte PIN_SERVO_B = 11;
int sensorX = 0; // variable to store the value coming from the sensor X
int sensorY = 0; // variable to store the value coming from the sensor Y
int sensorXant = 0;
int sensorYant = 0;
int aPos = 0;
int bPos = 0;
// variable for reading the pushbutton status
int buttonStateF = 0;
int buttonStateG = 0;
int buttonStateJoy = 0;
void setup() {
Aservo.attach(PIN_SERVO_A);
Aservo.write(aPos);
Bservo.attach(PIN_SERVO_B);
Bservo.write(bPos);
// initialize the pushbutton pin as an input:
pinMode(PIN_BUTTON_F, INPUT);
digitalWrite(PIN_BUTTON_F, HIGH);
pinMode(PIN_BUTTON_G, INPUT);
digitalWrite(PIN_BUTTON_G, HIGH);
}
void loop() {
// read the value from the sensor:
sensorX = analogRead(PIN_ANALOG_X);
sensorY = analogRead(PIN_ANALOG_Y);
// read the state of the pushbutton value:
buttonStateF = digitalRead(PIN_BUTTON_F);
if (buttonStateF == LOW) {
sensorXant = sensorX;
aPos = map(sensorXant, 0, 1023, 0, 179);
}
buttonStateG = digitalRead(PIN_BUTTON_G);
if (buttonStateG == LOW) {
sensorYant = sensorY;
bPos = map(sensorYant, 0, 1023, 0, 179);
}
Aservo.write(aPos);
Bservo.write(bPos);
delay(90);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment