Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente Dernière révision Les deux révisions suivantes | ||
logiciels:serial-processing:accueil [2016/05/25 10:14] resonance créée |
logiciels:serial-processing:accueil [2018/01/18 06:50] chenjianwei [2D et 3D PRIMITIVES] |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ====== Communication série Arduino/ | + | http:// |
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ===== 2D et 3D PRIMITIVES | ||
+ | Cercle, carré, rectangle, sphère, cylindre, tore, cone, ... | ||
+ | |||
+ | {{.: | ||
Ligne 18: | Ligne 224: | ||
void loop() { | void loop() { | ||
+ | |||
+ | // Update Data with linear values | ||
firstSensor += 1; | firstSensor += 1; | ||
secondSensor -= 1; | secondSensor -= 1; | ||
if (secondSensor < 0) secondSensor = 255; | if (secondSensor < 0) secondSensor = 255; | ||
if (firstSensor > 255) firstSensor = 0; | if (firstSensor > 255) firstSensor = 0; | ||
+ | | ||
+ | // Send Data | ||
Serial.print(firstSensor); | Serial.print(firstSensor); | ||
- | Serial.print("," | + | Serial.print("," |
- | Serial.println(secondSensor); | + | // Avec println on ferme le paquet de valeur, car " |
+ | Serial.println(secondSensor); | ||
+ | |||
+ | // Sampling rate | ||
delay(5); | delay(5); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Code Processing ===== | ||
+ | |||
+ | <code java> | ||
+ | // Get Serial Data from an Arduino | ||
+ | // Parse it with a separator caracter "," | ||
+ | |||
+ | // import the Processing serial library | ||
+ | import processing.serial.*; | ||
+ | Serial myPort; // The serial port | ||
+ | |||
+ | // Test values | ||
+ | int v1 =0; | ||
+ | int v2 = 255; | ||
+ | int x; | ||
+ | |||
+ | void setup() { | ||
+ | size(640, | ||
+ | // Open serial port | ||
+ | // | ||
+ | myPort = new Serial(this, | ||
+ | |||
+ | // Read bytes into a buffer until you get a linefeed (ASCII 10): | ||
+ | myPort.bufferUntil(' | ||
+ | |||
+ | //draw with smooth edges: | ||
+ | //smooth(); | ||
+ | background(255); | ||
+ | } | ||
+ | |||
+ | void draw() { | ||
+ | |||
+ | // Draw circles | ||
+ | fill(# | ||
+ | ellipse(x, v1, 5, 5); | ||
+ | fill(# | ||
+ | ellipse(x, v2, 5, 5); | ||
+ | |||
+ | // Update x position | ||
+ | x++; | ||
+ | | ||
+ | // Refresh screen | ||
+ | if (x > 600) { | ||
+ | background(255); | ||
+ | x = 0; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // serialEvent | ||
+ | // whenever the buffer reaches the byte value set in the bufferUntil() | ||
+ | // method in the setup(): | ||
+ | void serialEvent(Serial myPort) { | ||
+ | |||
+ | // read the serial buffer: | ||
+ | String myString = myPort.readStringUntil(' | ||
+ | | ||
+ | // if you got any bytes other than the linefeed: | ||
+ | myString = trim(myString); | ||
+ | | ||
+ | // split the string at the commas | ||
+ | // and convert the sections into integers: | ||
+ | int values[] = int(split(myString, | ||
+ | |||
+ | if (values.length > 0) { | ||
+ | v1 = values[0]; | ||
+ | v2 = values[1]; | ||
+ | // | ||
+ | } | ||
} | } | ||
</ | </ |