Étape 3: Programmation traitement
Nous n’arrêterons pas à la vitesse de lecture juste. Nous voulons un soft qui va lire la sortie et l’afficher dans une unité différente. Il n’y a aucune manière plus facile qu’un simple programme de traitement. Vous pouvez le télécharger ici.
Juste copiez et collez ce code dans le traitement, connecter l’Arduino pour ordinateur, exécuter du code sur l’Arduino et appuyez sur le bouton Démarrer dans le traitement. Et entrez votre port.
import processing.serial.*; PFont f; float val = 0; Serial port; // The serial port object String Ardport = ""; //Enter the port on which Arduino is connected void setup() { size(200,200); f = createFont("Arial",16,true); // Arial, 16 point, anti-aliasing on // In case you want to see the list of available ports // println(Serial.list()); port = new Serial(this, Ardport, 9600); } void draw() { } // Called whenever there is something available to read void serialEvent(Serial port) { String inString = port.readStringUntil('\n'); if (inString != null) { // trim off any whitespace: inString = trim(inString); // convert to an float println(inString); float val = float(inString); float val1 = val * 3.6; background(255); textFont(f,16); fill(0); text("Speed : " + val + "M/s",10,50); text("Speed : " + val1 + "Km/h",10,75); println( "Raw Input:" + val); } }