Cette page vous donne les différences entre la révision choisie et la version actuelle de la page.
projets:arduino_et_processing [2017/06/17 17:24] thierry_dasse |
projets:arduino_et_processing [2019/08/13 14:55] (Version actuelle) thierry_dasse ancienne révision restaurée |
||
---|---|---|---|
Ligne 20: | Ligne 20: | ||
- | ===== Le firmware ===== | + | ==== Le firmware ==== |
<code C++> | <code C++> | ||
Ligne 231: | Ligne 231: | ||
- | ===== Exemples d'utilisation ===== | + | ==== Exemples d'utilisation ==== |
R A0 | R A0 | ||
Ligne 251: | Ligne 251: | ||
===== Applications avec Processing ===== | ===== Applications avec Processing ===== | ||
+ | |||
+ | |||
+ | ==== Lire un potentiometre en A0 ==== | ||
+ | |||
+ | <code java> | ||
+ | |||
+ | import processing.serial.*; | ||
+ | |||
+ | Serial port; | ||
+ | int potentiometre; | ||
+ | |||
+ | void setup() { | ||
+ | size(800,600); | ||
+ | fill(0); | ||
+ | String portName = Serial.list()[0]; | ||
+ | port = new Serial(this,portName,57600); | ||
+ | } | ||
+ | |||
+ | void draw() { | ||
+ | port.write("R A0\n"); | ||
+ | while (port.available() > 0) { | ||
+ | int c = port.read(); | ||
+ | print((char)c); | ||
+ | } | ||
+ | delay(500); | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ==== Blink ==== | ||
+ | |||
+ | <code java> | ||
+ | |||
+ | import processing.serial.*; | ||
+ | |||
+ | Serial port; | ||
+ | int potentiometre; | ||
+ | |||
+ | void setup() { | ||
+ | size(800,600); | ||
+ | fill(0); | ||
+ | String portName = Serial.list()[0]; | ||
+ | port = new Serial(this,portName,57600); | ||
+ | delay(2000); | ||
+ | port.write("M 8,O\n"); | ||
+ | } | ||
+ | |||
+ | void draw() { | ||
+ | |||
+ | delay(100); | ||
+ | port.write("W 8,1\n"); | ||
+ | delay(100); | ||
+ | port.write("W 8,0\n"); | ||
+ | delay(100); | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | ==== Led et souris ==== | ||
+ | |||
+ | <code java> | ||
+ | |||
+ | import processing.serial.*; | ||
+ | |||
+ | Serial port; | ||
+ | int potentiometre; | ||
+ | |||
+ | void setup() { | ||
+ | size(800,600); | ||
+ | fill(0); | ||
+ | String portName = Serial.list()[0]; | ||
+ | port = new Serial(this,portName,57600); | ||
+ | delay(2000); | ||
+ | port.write("M 8,O\n"); | ||
+ | } | ||
+ | |||
+ | void draw() { | ||
+ | |||
+ | if (mousePressed) { | ||
+ | port.write("W 8,1\n"); | ||
+ | } else { | ||
+ | port.write("W 8,0\n"); | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | ==== Background ==== | ||
+ | |||
+ | <code java> | ||
+ | |||
+ | import processing.serial.*; | ||
+ | |||
+ | Serial port; | ||
+ | int potentiometre; | ||
+ | String command = ""; | ||
+ | int value = 0; | ||
+ | |||
+ | void setup() { | ||
+ | size(800,600); | ||
+ | String portName = Serial.list()[0]; | ||
+ | port = new Serial(this,portName,57600); | ||
+ | delay(2000); | ||
+ | } | ||
+ | |||
+ | void draw() { | ||
+ | background(0,value,value); | ||
+ | port.write("R A0\n"); | ||
+ | while (port.available() > 0) { | ||
+ | int c = port.read(); | ||
+ | command = command + (char)c; | ||
+ | if (c == '\n') { | ||
+ | value = Integer.valueOf(command.split(",")[1].trim()); | ||
+ | value = value >> 2; | ||
+ | println(value); | ||
+ | command = ""; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | ==== Line ==== | ||
+ | |||
+ | <code java> | ||
+ | |||
+ | import processing.serial.*; | ||
+ | |||
+ | Serial port; | ||
+ | int potentiometre; | ||
+ | String command = ""; | ||
+ | int value; | ||
+ | |||
+ | void setup() { | ||
+ | size(800,600); | ||
+ | fill(0); | ||
+ | String portName = Serial.list()[0]; | ||
+ | port = new Serial(this,portName,57600); | ||
+ | delay(2000); | ||
+ | port.write("L A0\n"); | ||
+ | strokeWeight(2); | ||
+ | stroke(204, 102, 0); | ||
+ | } | ||
+ | |||
+ | void draw() { | ||
+ | background(255); | ||
+ | while (port.available() > 0) { | ||
+ | int c = port.read(); | ||
+ | command = command + (char)c; | ||
+ | if (c == '\n') { | ||
+ | value = Integer.valueOf(command.split(",")[1].trim()); | ||
+ | line(100,value+50,700,value+50); | ||
+ | command = ""; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | </code> | ||
+ | |||
+ | |||
+ | Et pour la prochaine fois : | ||
+ | |||
+ | une ardoise magique avec deux potentiomètres et un bouton poussoir | ||
+ | |||