Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
|
wiki:flossmanuals:livre-enfant-interactif-pression:accueil [2021/05/02 15:08] vincent |
wiki:flossmanuals:livre-enfant-interactif-pression:accueil [2021/06/01 17:33] (Version actuelle) damien.muti |
||
|---|---|---|---|
| Ligne 5: | Ligne 5: | ||
| * **Contexte** : Micro-projet de cours | * **Contexte** : Micro-projet de cours | ||
| * **Fichiers** : | * **Fichiers** : | ||
| - | * **Liens** : | + | * **Liens** : https:// |
| * **Capteurs/ | * **Capteurs/ | ||
| * Carte Arduino Uno /Seeduino | * Carte Arduino Uno /Seeduino | ||
| Ligne 14: | Ligne 14: | ||
| ===== Intentions : explication du projet et objectifs ===== | ===== Intentions : explication du projet et objectifs ===== | ||
| - | Dans le cadre d'une édition jeunesse, l' | + | Dans le cadre d'une édition jeunesse, l' |
| {{ : | {{ : | ||
| Ligne 21: | Ligne 21: | ||
| ===== Plans et schémas de fonctionnement ===== | ===== Plans et schémas de fonctionnement ===== | ||
| - | . **Faire varier l' | + | . **Faire varier l' |
| {{ : | {{ : | ||
| - | ===== Programmes ===== | + | ===== Programmes |
| - | + | ==== Programme | |
| - | . Programme | + | < |
| int fsrAnalogPin = 0; / FSR connecté a A0 | int fsrAnalogPin = 0; / FSR connecté a A0 | ||
| Ligne 56: | Ligne 55: | ||
| delay(100); | delay(100); | ||
| } | } | ||
| + | </ | ||
| + | ==== Programme pour envoyer UNE donnée via le port série ==== | ||
| + | < | ||
| + | int firstSensor = 0; / first analog sensor | ||
| + | int inByte = 0; / incoming serial byte | ||
| + | |||
| + | 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 | ||
| + | } | ||
| + | |||
| + | pinMode(2, INPUT); | ||
| + | establishContact(); | ||
| + | } | ||
| + | |||
| + | 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: | ||
| + | firstSensor = analogRead(A0)/ | ||
| + | |||
| + | // send sensor values: | ||
| + | Serial.write(firstSensor); | ||
| + | delay(10); // patienter 10ms (à voir...) | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void establishContact() { | ||
| + | while (Serial.available() <= 0) { | ||
| + | Serial.print(' | ||
| + | delay(300); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | ==== Programme final : mélange des deux programmes précédents | ||
| + | A COMPLETER | ||
| + | |||
| + | ===== Programme PROCESSING ===== | ||
| + | |||
| + | ==== Variation forme graphique ==== | ||
| + | < | ||
| + | import processing.serial.*; | ||
| + | |||
| + | int bgcolor[] = {255, 255, 255}; | ||
| + | |||
| + | int fgcolor =255; | ||
| + | |||
| + | int xpos, ypos; / Starting position of the ball | ||
| + | |||
| + | int rayon = 20; | ||
| + | |||
| + | Serial myPort; | ||
| + | |||
| + | int serialInArray; | ||
| + | |||
| + | int serialCount = 0; / A count of how many bytes we receive | ||
| + | |||
| + | boolean firstContact = false; | ||
| + | |||
| + | |||
| + | void setup() { | ||
| + | size(500, 500); // Stage size | ||
| + | noStroke(); | ||
| + | |||
| + | // Set the starting position of the ball (middle of the stage) | ||
| + | xpos = width/2; | ||
| + | ypos = height/2; | ||
| + | |||
| + | // Print a list of the serial ports, for debugging purposes: | ||
| + | printArray(Serial.list()); | ||
| + | |||
| + | // I know that the first port in the serial list on my mac | ||
| + | // is always my FTDI adaptor, so I open Serial.list()[0]. | ||
| + | // On Windows machines, this generally opens COM1. | ||
| + | // Open whatever port is the one you're using. | ||
| + | String portName = Serial.list()[0]; | ||
| + | myPort = new Serial(this, | ||
| + | |||
| + | // espace HSB des couleurs | ||
| + | colorMode(HSB); | ||
| + | } | ||
| + | |||
| + | void draw() { | ||
| + | rectMode(CENTER); | ||
| + | background(0); | ||
| + | fill (255, 255, 200); | ||
| + | circle(xpos, | ||
| + | } | ||
| + | |||
| + | |||
| + | void serialEvent(Serial myPort) { | ||
| + | // read a byte from the serial port: | ||
| + | int inByte = myPort.read();//////////////////////////////////////// | ||
| + | // if this is the first byte received, and it's an A, | ||
| + | // clear the serial buffer and note that you've | ||
| + | // had first contact from the microcontroller. | ||
| + | // Otherwise, add the incoming byte to the array: | ||
| + | if (firstContact == false) { | ||
| + | if (inByte == ' | ||
| + | myPort.clear(); | ||
| + | firstContact = true; // you've had first contact from the microcontroller | ||
| + | myPort.write(' | ||
| + | } | ||
| + | } else { | ||
| + | rayon= (int)map(inByte, | ||
| + | // print the values (for debugging purposes only): | ||
| + | println(" | ||
| + | |||
| + | // Send a capital A to request new sensor readings: | ||
| + | myPort.write(' | ||
| + | | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| ===== Réalisation de la maquette ===== | ===== Réalisation de la maquette ===== | ||
| + | ==== Images ==== | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | ==== Vidéos ==== | ||
| + | * Faire varier l' | ||
| + | * Faire varier une forme graphique sur Processing : https:// | ||