Skip to content

Instantly share code, notes, and snippets.

@EdwardReed
Created March 14, 2013 08:30
Show Gist options
  • Save EdwardReed/5159780 to your computer and use it in GitHub Desktop.
Save EdwardReed/5159780 to your computer and use it in GitHub Desktop.
#include <Servo.h>
Servo pink;
Servo ring;
Servo midd;
Servo indx;
//Servo thmb;
//Servo wrst;
#define pi A0
#define ri A1
#define mi A2
#define ix A3
//int pinMax[] = {180,180,180,180,180,180};
int inPin[] = {pi,ri,mi,ix}; //stores the pins for each finger
//0 - pinky | 1 - ring | 2 - middle | 3 - index | 4 - thumb
int pnVal[5]; //stores the values recieved from each pin
void setup(){
//attachs each servo to a pin
pink.attach(3);
ring.attach(4);
midd.attach(5);
indx.attach(6);
//thmb.attach(7);
//wrst.attach(11);
}
void loop(){
//loops through each pin
for(int i = 0; i < 3; i++){
//retrieves its input value
pnVal[i] = analogRead(inPin[i]);
//maps it to a servo output
pnVal[i] = map(pnVal[i],0,1023,0,180);
}
//and then writes it to the servo
pink.write(pnVal[0]);
ring.write(pnVal[1]);
midd.write(pnVal[2]);
indx.write(pnVal[3]);
//thmb.write(pnVal[4]);
//wrst.write(pnVal[5]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment