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:capteur-distance-slideshow:accueil [2021/05/17 16:47] mathilde |
wiki:flossmanuals:capteur-distance-slideshow:accueil [2023/03/22 20:03] mathilde supprimée |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ====== | + | ====== |
* **Porteur(s) du projet** : Mathilde Verdu Ibañez, Ugo Berzal, Chloé Chapal (DSAA 1) & Damien MUTI (Prof. de Numérique) | * **Porteur(s) du projet** : Mathilde Verdu Ibañez, Ugo Berzal, Chloé Chapal (DSAA 1) & Damien MUTI (Prof. de Numérique) | ||
* **Date** : 03/2021 | * **Date** : 03/2021 | ||
- | | + | * **Capteurs/ |
- | * **Fichiers** : | + | |
- | * **Liens** : | + | |
- | | + | |
- | * Capteur de distance | + | |
---- | ---- | ||
Ligne 13: | Ligne 9: | ||
===== Intentions : explication du projet et objectifs ===== | ===== Intentions : explication du projet et objectifs ===== | ||
+ | Intentions Chloé : [[wiki: | ||
+ | Intentions Mathilde : [[wiki: | ||
===== Plans et schémas de fonctionnement ===== | ===== Plans et schémas de fonctionnement ===== | ||
+ | {{: | ||
+ | {{: | ||
+ | {{: | ||
===== Programmes ===== | ===== Programmes ===== | ||
+ | |||
+ | **ARDUINO** | ||
+ | |||
+ | |||
+ | #include " | ||
+ | |||
+ | Ultrasonic ultrasonic(7); | ||
+ | |||
+ | long distance=0; / variable qui stoke la valeur de la distance | ||
+ | |||
+ | 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 | ||
+ | } | ||
+ | establishContact(); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | // if we get a valid byte, read analog ins: | ||
+ | if (Serial.available() > 0) { | ||
+ | // get incoming byte: | ||
+ | inByte = Serial.read(); | ||
+ | |||
+ | // lecture de la distance | ||
+ | distance = ultrasonic.MeasureInCentimeters(); | ||
+ | // conversion de la valeur en un octet | ||
+ | firstSensor = map(distance, | ||
+ | | ||
+ | // send sensor values: | ||
+ | Serial.write(firstSensor); | ||
+ | delay(200); | ||
+ | |||
+ | } | ||
+ | } | ||
+ | |||
+ | void establishContact() { | ||
+ | while (Serial.available() <= 0) { | ||
+ | Serial.print(' | ||
+ | delay(300); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | **PROCESSING** | ||
+ | |||
+ | |||
+ | |||
+ | import processing.serial.*; | ||
+ | |||
+ | / graphisme | ||
+ | |||
+ | int bgcolor; | ||
+ | |||
+ | int fgcolor; | ||
+ | |||
+ | int xpos, ypos; / Starting position of the ball | ||
+ | |||
+ | int distance; | ||
+ | |||
+ | PImage[] tabImages; | ||
+ | |||
+ | int NImages = 3; | ||
+ | |||
+ | /port serie | ||
+ | |||
+ | Serial myPort; | ||
+ | |||
+ | int serialInArray; | ||
+ | |||
+ | int serialCount = 0; / A count of how many bytes we receive | ||
+ | |||
+ | boolean firstContact = false; | ||
+ | |||
+ | void setup() { | ||
+ | size(600, 485); // 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()[9]; | ||
+ | myPort = new Serial(this, | ||
+ | |||
+ | // espace HSB des couleurs | ||
+ | colorMode(HSB); | ||
+ | |||
+ | //creation tableau images | ||
+ | tabImages=new PImage[NImages]; | ||
+ | for (int i=0; i< | ||
+ | tabImages[i]= loadImage(" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void draw() { | ||
+ | background(bgcolor); | ||
+ | // test distance | ||
+ | if (distance >= 0 && distance < 50) { | ||
+ | image(tabImages[0], | ||
+ | } else if (distance >= 50 && distance < 100) { | ||
+ | image(tabImages[1], | ||
+ | } else if (distance >= 100 && distance < 150) { | ||
+ | image(tabImages[2], | ||
+ | } else { | ||
+ | image(tabImages[0], | ||
+ | //fill(0); | ||
+ | //rect(0, 0, width, height); | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | // | ||
+ | // Draw the shape | ||
+ | // | ||
+ | } | ||
+ | |||
+ | 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 { | ||
+ | // Add the latest byte from the serial port to array: | ||
+ | distance = (int) map(inByte, 0, 255, 0, 400); // remplir le donnée " | ||
+ | // print the values (for debugging purposes only): | ||
+ | println(" | ||
+ | |||
+ | // Send a capital A to request new sensor readings: | ||
+ | myPort.write(' | ||
+ | // Reset serialCount: | ||
+ | } | ||
+ | } | ||
- | ===== Réalisation de la maquette ===== |