Skip to content

Instantly share code, notes, and snippets.

@EdwardReed
Created March 20, 2013 03:26
Show Gist options
  • Save EdwardReed/5202082 to your computer and use it in GitHub Desktop.
Save EdwardReed/5202082 to your computer and use it in GitHub Desktop.
Program that controls a hand with a glove.
#include <Servo.h>
Servo pink;
Servo ring;
Servo midd;
Servo indx;
Servo thmb;
#define pi A0
#define ri A1
#define mi A2
#define ix A3
#define th A4
int val = 0;
int inPin[] = {pi,ri,mi,ix,th}; //stores the pins for each finger
//0 - pinky | 1 - ring | 2 - middle | 3 - index | 4 - thumb
int pinMx[] = {646,810,764,642,260}; //410 -thumb
int pinMn[] = {319,560,0,290,410};//260 -thumb
int pnVal[5]; //stores the values recieved from each pin
void setup(){
Serial.begin(9600);
//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 < 5; i++){
//retrieves its input value
pnVal[i] = analogRead(inPin[i]);
//maps it to a servo output
pnVal[i] = constrain(map(pnVal[i],pinMn[i],pinMx[i],0,180),0,180);
}
// Serial.println();
pink.write(pnVal[0]);
ring.write(pnVal[1]);
midd.write(pnVal[2]);
indx.write(pnVal[3]);
thmb.write(pnVal[4]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment