Difference between revisions of "Processing"

From air
Jump to navigation Jump to search
Line 3: Line 3:
 
[http://processingjs.org Processing.JS] est l'adaptation en Javascript de Processing.
 
[http://processingjs.org Processing.JS] est l'adaptation en Javascript de Processing.
   
Un programme Processing et une application Web Processing.js peuvent échanger des informations avec des cartes Arduino connectées à l'hôte ([http://www.arduino.cc/playground/Interfacing/Processing plus...]).
 
   
  +
= Communication entre un programme Processing et une carte Arduino =
Exemple:
 
  +
  +
La communication entre un programme Processing et une carte Arduino s'effectue par l'intermédiaire la liaison série au-dessus de l'USB et s'effectue simplement au travers de l'utilisation de function série (voir les programmes Processing dans File/Examples/Libraries/Serial).
  +
Ci-dessous le programme SerialDuplex qui permet de tester l'envoi et la reception simple de caractère. '''A complete par un programme correspondant sur l'Arduino'''
   
 
<pre>
 
<pre>
  +
// Programme SerialDuplex
 
import processing.serial.*;
 
import processing.serial.*;
import cc.arduino.*;
 
   
  +
Serial myPort; // The serial port
Arduino arduino;
 
  +
int whichKey = -1; // Variable to hold keystoke values
int ledPin = 13;
 
  +
int inByte = -1; // Incoming serial data
   
void setup()
+
void setup() {
  +
size(400, 300);
{
 
  +
// create a font with the third font available to the system:
//println(Arduino.list());
 
arduino = new Arduino(this, Arduino.list()[0], 57600);
+
PFont myFont = createFont(PFont.list()[2], 14);
  +
textFont(myFont);
arduino.pinMode(ledPin, Arduino.OUTPUT);
 
  +
  +
// List all the available serial ports:
 
println(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].
  +
// In Windows, this usually opens COM1.
  +
// Open whatever port is the one you're using.
  +
String portName = Serial.list()[0];
  +
myPort = new Serial(this, portName, 9600);
 
}
 
}
   
void draw()
+
void draw() {
  +
background(0);
{
 
  +
text("Last Received: " + inByte, 10, 130);
arduino.digitalWrite(ledPin, Arduino.HIGH);
 
  +
text("Last Sent: " + whichKey, 10, 100);
delay(1000);
 
  +
}
arduino.digitalWrite(ledPin, Arduino.LOW);
 
  +
delay(1000);
 
  +
void serialEvent(Serial myPort) {
  +
inByte = myPort.read();
  +
}
  +
  +
void keyPressed() {
  +
// Send the keystroke out:
  +
myPort.write(key);
  +
whichKey = key;
 
}
 
}
   
 
 
</pre>
 
</pre>
  +
   
 
==Liens==
 
==Liens==

Revision as of 10:47, 26 October 2011

Processing est un environnement de développement d'animation en Java simple à mettre en oeuvre.

Processing.JS est l'adaptation en Javascript de Processing.


Communication entre un programme Processing et une carte Arduino

La communication entre un programme Processing et une carte Arduino s'effectue par l'intermédiaire la liaison série au-dessus de l'USB et s'effectue simplement au travers de l'utilisation de function série (voir les programmes Processing dans File/Examples/Libraries/Serial). Ci-dessous le programme SerialDuplex qui permet de tester l'envoi et la reception simple de caractère. A complete par un programme correspondant sur l'Arduino

// Programme SerialDuplex 
import processing.serial.*;

Serial myPort;      // The serial port
int whichKey = -1;  // Variable to hold keystoke values
int inByte = -1;    // Incoming serial data

void setup() {
  size(400, 300);
  // create a font with the third font available to the system:
  PFont myFont = createFont(PFont.list()[2], 14);
  textFont(myFont);

  // List all the available serial ports:
  println(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].
  // In Windows, this usually opens COM1.
  // Open whatever port is the one you're using.
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}

void draw() {
  background(0);
  text("Last Received: " + inByte, 10, 130);
  text("Last Sent: " + whichKey, 10, 100);
}

void serialEvent(Serial myPort) {
  inByte = myPort.read();
}

void keyPressed() {
  // Send the keystroke out:
  myPort.write(key);
  whichKey = key;
}


Liens

Livres