Outils pour utilisateurs

Outils du site


wiki:flossmanuals:un-capteur-une-application:accueil

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
wiki:flossmanuals:un-capteur-une-application:accueil [2021/05/04 05:02]
damien.muti
wiki:flossmanuals:un-capteur-une-application:accueil [2021/05/04 05:29] (Version actuelle)
damien.muti
Ligne 24: Ligne 24:
 Nous proposons ici de mesurer une distance à l'aide d'un capteur de distance ultrason et de faire varier la couleur d'une forme sous Processing.  Nous proposons ici de mesurer une distance à l'aide d'un capteur de distance ultrason et de faire varier la couleur d'une forme sous Processing. 
  
-===== Circuit Arduino =====+===== Programme Arduino - Potentiomètre ===== 
 + 
 +On utilise un [[wiki:tutoriels:arduino-capteurs:arduino-capteurs#potentiometre|potentiomètre de 10kΩ]].  
 +Le schéma de câblage est le suivant :  
 + 
 + 
 +{{ :wiki:flossmanuals:un-capteur-une-application:potentiometre_a0_bb.png?400 |}} 
 + 
 +Le programme Arduino est le suivant : {{ :wiki:flossmanuals:un-capteur-une-application:un_potentiometre_une_application_arduino.zip |}} 
 + 
 +<code> 
 +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();  // 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(); 
 + 
 +    // lecture de la valeur du potentiometre branché sur A0  
 +    //et conversion de la valeur en un octet 
 +    firstSensor = analogRead(A0)/4; 
 +     
 +    // send sensor values: 
 +    Serial.write(firstSensor); 
 +    
 +  } 
 +
 + 
 +void establishContact() { 
 +  while (Serial.available() <= 0) { 
 +    Serial.print('A');   // send a capital A 
 +    delay(300); 
 +  } 
 +
 + 
 + 
 + 
 +</code> 
 + 
 +===== Programme Arduino - Ultrasonic =====
  
 On utilise un [[wiki:tutoriels:arduino-capteurs:arduino-capteurs#capteur_de_distance_ultrason_grove|capteur de distance Ultrason Ultrasonic en Grove]].  On utilise un [[wiki:tutoriels:arduino-capteurs:arduino-capteurs#capteur_de_distance_ultrason_grove|capteur de distance Ultrason Ultrasonic en Grove]]. 
Ligne 31: Ligne 81:
  
 Le capteur Ultrason est branché sur le "slot" D7. Le capteur Ultrason est branché sur le "slot" D7.
- 
-===== Programme Arduino ===== 
  
 Le programme Arduino est le suivant : {{ :wiki:flossmanuals:un-capteur-une-application:un_capteur_une_application_arduino.zip |}} Le programme Arduino est le suivant : {{ :wiki:flossmanuals:un-capteur-une-application:un_capteur_une_application_arduino.zip |}}
Ligne 81: Ligne 129:
  
  
 +===== Programme Processing =====
 +
 +**Quel que soit le capteur utilisé**, le programme Processing est le suivant : {{ :wiki:flossmanuals:un-capteur-une-application:un_capteur_une_application_processing.zip |}}. On modifie la couleur d'un cercle positionné au centre de la fenêtre d'affichage.
 +
 +<code>
 +import processing.serial.*;
 +
 +int bgcolor;      // Background color
 +int fgcolor;      // Fill color
 +Serial myPort;                       // The serial port
 +int serialInArray;    // Where we'll put what we receive
 +int serialCount = 0;                 // A count of how many bytes we receive
 +int xpos, ypos;              // Starting position of the ball
 +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
 +
 +  // 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, portName, 9600);
 +  
 +  // espace HSB des couleurs
 +  colorMode(HSB);
 +}
 +
 +void draw() {
 +  background(bgcolor);
 +  fill(fgcolor,255,255);
 +  // Draw the shape
 +  circle(xpos, ypos, 50);
 +}
 +
 +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 == 'A') { 
 +      myPort.clear();          // clear the serial port buffer
 +      firstContact = true;     // you've had first contact from the microcontroller
 +      myPort.write('A');       // ask for more
 +    }
 +  } else {
 +    // Add the latest byte from the serial port to array:
 +    fgcolor = inByte; // remplir la donnée "utile"
 +    // print the values (for debugging purposes only):
 +    println("valeur lue sur le port Série = " +  fgcolor);
 +
 +    // Send a capital A to request new sensor readings:
 +    myPort.write('A');
 +    // Reset serialCount:
 +  }
 +}
 +</code>
  
wiki/flossmanuals/un-capteur-une-application/accueil.1620097348.txt.gz · Dernière modification: 2021/05/04 05:02 de damien.muti