1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| // CAPTEUR DE FLEXION 1 BRANCHE SUR L'ENTREE ANALOGIQUE 0
// CAPTEUR DE FLEXION 2 BRANCHE SUR L'ENTREE ANALOGIQUE 1
// POUR LE MOMENT DISONS QUE LE CDF EST PLIE SI degrees > 10
// PENSER A CHANGER 768 ET 853
void setup()
{
// initialize serial communications
Serial.begin(9600);
}
void loop()
{
int valeur(0);
do {int cdf1, degrees;
// read the voltage from the voltage divider (sensor plus resistor)
cdf1 = analogRead(0);
// convert the voltage reading to inches
// the first two numbers are the sensor values for straight (768) and bent (853)
// the second two numbers are the degree readings we'll map that to (0 to 90 degrees)
degrees = map(cdf1, 768, 853, 0, 90);
// note that the above numbers are ideal, your sensor's values will vary
// to improve the accuracy, run the program, note your sensor's analog values
// when it's straight and bent, and insert those values into the above function.
// print out the result
Serial.print("analog input: ");
Serial.print(cdf1,DEC);
Serial.print(" degrees: ");
Serial.println(degrees,DEC);
int cdf2, degrees;
// read the voltage from the voltage divider (sensor plus resistor)
cdf2 = analogRead(1);
// convert the voltage reading to inches
// the first two numbers are the sensor values for straight (768) and bent (853)
// the second two numbers are the degree readings we'll map that to (0 to 90 degrees)
degrees = map(cdf2, 768, 853, 0, 90);
// note that the above numbers are ideal, your sensor's values will vary
// to improve the accuracy, run the program, note your sensor's analog values
// when it's straight and bent, and insert those values into the above function.
// print out the result
Serial.print("analog input: ");
Serial.print(cdf2,DEC);
Serial.print(" degrees: ");
Serial.println(degrees,DEC);
// pause before taking the next reading
delay(100);
} while (cdf1 >=10 && cdf2 <=10); //si l'utilisteur ne fait ni feuille ni pierre ni ciseaux, répéter la question
if (cdf1 >= 3 && cdf2 >= 3) //l'utilisateur fait feuille
{
int valeur(3); // valeur 3 = le robot doit faire ciseaux
return valeur;
}
else if (cdf1 >= 10 && cdf2 >= 1O ) //l'utilisateur fait pierre
{
int valeur(2); // valeur 2 = le robot doit feuille
return valeur;
}
else if (cdf <= 10 && cdf2 >=10) //l'utilisateur fait ciseaux
{
int valeur(1); // valeur 1 = le robot doit faire pierre
return valeur;
}
} |
Partager