Programmation arduino

Fermé
G1anT_KaKThuS Messages postés 14 Date d'inscription jeudi 2 avril 2015 Statut Membre Dernière intervention 28 juin 2017 - Modifié par G1anT_KaKThuS le 21/10/2015 à 12:03
mtR^ Messages postés 1211 Date d'inscription vendredi 17 juin 2011 Statut Membre Dernière intervention 3 juin 2023 - 21 oct. 2015 à 12:12
J'ai rentré ce code :

// 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;
    }
}

et j'ai ce message d'erreur :
Arduino : 1.6.5 (Windows 8.1), Carte : "Arduino/Genuino Uno"


calcul_du_degr__du_cdf.ino:65:36: error: invalid suffix "O" on integer constant
calcul_du_degr__du_cdf.ino: In function 'void loop()':
calcul_du_degr__du_cdf.ino:35:11: error: redeclaration of 'int degrees'
calcul_du_degr__du_cdf.ino:16:15: error: 'int degrees' previously declared here
calcul_du_degr__du_cdf.ino:58:18: error: 'cdf1' was not declared in this scope
calcul_du_degr__du_cdf.ino:58:31: error: 'cdf2' was not declared in this scope
calcul_du_degr__du_cdf.ino:63:16: error: return-statement with a value, in function returning 'void' [-fpermissive]
calcul_du_degr__du_cdf.ino:68:16: error: return-statement with a value, in function returning 'void' [-fpermissive]
calcul_du_degr__du_cdf.ino:70:14: error: 'cdf' was not declared in this scope
calcul_du_degr__du_cdf.ino:73:16: error: return-statement with a value, in function returning 'void' [-fpermissive]
invalid suffix "O" on integer constant


Je veux que ma carte arduino sache si le gant avec le capteur de flexion fait pierre, feuille, ou ciseaux

si il fait pierre, il ressort la valeur 2
si il fait feuille, il ressort la valeur 3
si il fait ciseaux, il ressort la valeur 1

pour le moment c'est ce que j'essaie de programmer

ensuite la carte envoi par bluetooth à une autre carte arduino la valeur 1,2 ou 3
selon les valeurs, la carte arduino fait fonctionner 2 servos moteurs pour faire bouger une main robotisée

si elle reçoit la valeur 1, elle fait pierre
valeur 2 -> feuille
valeur 3 ciseaux

Merci pour l'aide !

1 réponse

mtR^ Messages postés 1211 Date d'inscription vendredi 17 juin 2011 Statut Membre Dernière intervention 3 juin 2023 168
21 oct. 2015 à 12:12
Salut !

Quel est le problème ? Le compilateur t'as ressorti toutes les erreurs, ya plus qu'à corriger.

Pour les deux première par exemple :

alcul_du_degr__du_cdf.ino:65:36: error: invalid suffix "O" on integer constant

Il te parle d'un O, tu va voir ligne 65-66, et on voit que tu à mis un O à la place d'un 0, sur le 10.

calcul_du_degr__du_cdf.ino:35:11: error: redeclaration of 'int degrees'

Effectivement, tu déclare "degrees" l.35 alors qu'il est déjà déclaré l.16.

Bref, je te laisse continuer :)
0