====== Apparition de balles par boutons ====== État : en cours (problème avec l'apparition de trop de balles) * **Porteur(s) du projet** : Dufossé Martin (DSAA1 DG), Damien MUTI (Prof. de Numérique) * **Date** : 05/2021 * **Contexte** : Recherches "mémoire" * **Fichiers** : * **Liens** : * **Capteurs/Actionneurs** : * ARDUINO UNO * BOUTON POUSSOIR ---- ===== Intentions : explication du projet et objectifs ===== On apprend à compter à partir de 3 boutons poussoir qui vont faire apparaitre des balles sur l'écran. Le premier bouton fera apparaître 1 balle, le second 2 et le troisième 3. L'enfant aura alors une prémisse au calcule car il pourra compter le nombre total de balles visible sur l'écran. Ainsi si il appuie 2 fois sur le troisième bouton, il pourra compter 6 balles à l'écran. ===== Le matériel ===== 3 boutons poussoir Carte seeeduino lotus ==== carte seeeduino lotus ==== {{:wiki:flossmanuals:boutonajoutdeballes:ori-carte-seeeduino-lotus-1-1-102010168-26688.jpg?400|}} La documentation sur cette carte est la suivante : * Carte Seeduino : [[https://wiki.seeedstudio.com/Seeeduino_Lotus/]]. ==== Boutons Poussoir ==== {{:wiki:flossmanuals:boutonajoutdeballes:ar-module-bouton-grove-111020000-19010.jpg?400|}} ===== Plans et schémas de fonctionnement ===== Le câblage sur la carte Arduino est le suivant : {{:wiki:flossmanuals:boutonajoutdeballes:img_2203.jpg|}} ==== Câblage du circuit==== * Les modules Boutons sont branché respectivement sur le connecteur D2, D6 et D3 de la Carte [[https://wiki.seeedstudio.com/Seeeduino_Lotus/|Seeeduino Lotus]] ou du [[https://wiki.seeedstudio.com/Base_Shield_V2/|Shield Grove]]. ===== Programmes ===== ==== Arduino ==== Le code permettant de contrôler les boutons à partir d'une pression d'être détecté. int inByte = 0; // incoming serial byte byte bouton[] = {2, 3, 6}; int valBouton[] = {0, 0, 0}; byte Nbouton = 3; void setup() { // start serial port at 9600 bps: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } for (byte i = 0; i < Nbouton; i++) { pinMode(bouton[i], INPUT); // digital sensor is on digital pin 2 } establishContact(); // send a byte to establish contact until receiver responds } void loop() { // if we get a valid byte, read analog ins: if (Serial.available() > 0) { // get incoming byte: inByte = Serial.read(); // read first analog input, divide by 4 to make the range 0-255: // lire la valeur de chaque bouton for (byte i = 0; i < Nbouton; i++) { valBouton[i] = map(digitalRead(bouton[i]), 0, 1, 0, 255);; // digital sensor is on digital pin 2 } // send sensor values: for (byte i = 0; i < Nbouton; i++) { Serial.write(valBouton[i] ); } } } void establishContact() { while (Serial.available() <= 0) { Serial.print('A'); // send a capital A delay(300); } } ==== Processing ==== /** * Serial Call-Response * by Tom Igoe. * * Sends a byte out the serial port, and reads 3 bytes in. * Sets foregound color, xpos, and ypos of a circle onstage * using the values returned from the serial port. * Thanks to Daniel Shiffman and Greg Shakar for the improvements. * * Note: This sketch assumes that the device on the other end of the serial * port is going to send a single byte of value 65 (ASCII A) on startup. * The sketch waits for that byte, then sends an ASCII A whenever * it wants more data. */ import processing.serial.*; int bgcolor; // Background color int fgcolor; // Fill color Serial myPort; // The serial port // balles int xpos, ypos; // Starting position of the ball int d = 20; // diamètre des balles // boutons via port série int[] valBouton; boolean[] ancienEtatBouton; int Nboutons =3; int[] serialInArray = new int[3]; // Where we'll put what we receive int serialCount = 0; // A count of how many bytes we receive boolean firstContact = false; // Whether we've heard from the microcontroller void setup() { size(256, 256); // Stage size noStroke(); // No border on the next thing drawn background(0); // Set the starting position of the ball (middle of the stage) xpos = width/2; ypos = height/2; // création et init du tableau de valeur des boutons valBouton = new int[Nboutons]; ancienEtatBouton = new boolean[Nboutons]; for (int i=0; i 2 ) { for (int i=0; i