Projet

Général

Profil

Main Myoélectrqiue » final_hand.ino

Programme Arduino - Thomas Coment, 23/11/2020 17:35

 
#include <Servo.h>


//Settings
const boolean isRight = 1; // Right : 1, Left : 2
const int outThumbMin = 0; //Right:close, Left:open, = minimum thumb angle
const int outThumbMax = 30; //maximum thumb angle
const int outIndexMin = 54; //min index angle
const int outIndexMax = 142; //max index angle
const int outOtherMin = 60; //min otherfingers angle
const int outOtherMax = 140; //max otherfingers angle



int pinServoThumb = 6 ; //Pin servo is attached on
int pinServoIndex = 3 ;
int pinServoOther = 5 ;



int pinP1 = A0; //Pin Potentiometer 1
int pinP2 = A1; //Pin Potentiometer 2
int pinP3 = A2; //Pin Potentiometer 3



//Hardware Servo
Servo servoThumb; //ThumbFinger
Servo servoIndex; //IndexFinger
Servo servoOther; //OtherFingers
int posP1 = 0; //Potentiometer 1 value
int posP2 = 0;
int posP3 = 0;
int P1Min = 0; //Potentiometer 1 minimum value
int P1Max = 1023; //Potentiometer 1 maximum value
int P2Min = 0;
int P2Max = 1023;
int P3Min = 0;
int P3Max = 1023;


void setup() {
Serial.begin(9600);

servoIndex.attach(pinServoIndex);
servoOther.attach(pinServoOther);
servoThumb.attach(pinServoThumb);

while (millis() < 3000) { //First 3 seconds initialisation
// servoThumb.write(outThumbMin);
delay (100);
// servoIndex.write(outIndexMin);
delay (100);
// servoOther.write(outOtherMin);
delay (100);
}
delay (2000); // delay 2sec
}

void loop() {

posP1 = map(analogRead(A0),0,1023,outThumbMin, outThumbMax); //map potentiometer min and max value to min and max servomotor angle
servoThumb.write(posP1); //apply the angle

Serial.print (analogRead(A0)); Serial.print ("\t"); Serial.print (posP1); Serial.print ("\t"); //Write data in the monitor
delay (10);

posP2 = map(analogRead(A1),0,1023,outIndexMin, outIndexMax);
servoIndex.write(posP2);

Serial.print (analogRead(A1)); Serial.print ("\t"); Serial.print (posP2); Serial.print ("\t");
delay (10);

posP3 = map(analogRead(A2),0,1023,outOtherMax, outOtherMin);
servoOther.write(posP3);

Serial.print (analogRead(A2)); Serial.print ("\t"); Serial.print (posP3); Serial.println ("\t");
delay (10);
}
(2-2/20)