Affichage des articles dont le libellé est processing. Afficher tous les articles
Affichage des articles dont le libellé est processing. Afficher tous les articles
lundi 22 avril 2013
samedi 7 janvier 2012
processing -> web = processing.js
Je viens de découvrir que l'on peut incorporer dans un page web un code développé sous processing. le site http://processingjs.org/ propose de télécharger le script qui va bien à mettre dans la page web.
Coté +:
Plus besoin de s'embêter avec les mises à jour java.
coté -
probablement pas d'accès à certaines fonction. (serial..)
mardi 13 décembre 2011
processing -> arduino -> servo
But contrôler un servomoteur.
Code processing
import controlP5.*;
import processing.serial.*;
Serial myPort; // The serial port
ControlP5 controlP5;
public int myColorRect = 200;
public int myColorBackground = 100;
//variable global
int slide1;
void setup() {
size(400,400);
frameRate(25);
controlP5 = new ControlP5(this);
controlP5.addSlider("sliderA",63,118,100,100,260,100,14).setId(4);
controlP5.addTextfield("textA",100,290,100,20).setId(5);
println(Serial.list());
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}
void draw() {
background(myColorBackground);
fill(myColorRect);
rect(0,0,width,100);
myPort.write(slide1);
}
// a slider event will change the value of textfield textA
public void sliderA(int theValue) {
((Textfield)controlP5.controller("textA")).setValue(""+theValue);
}
// for every change in textfield textA, this function will be called
public void textA(String theValue) {
println("### got an event from textA : "+theValue);
slide1=int(theValue);
println("slide 1 : "+slide1);
}
public void controlEvent(ControlEvent theEvent) {
println("got a control event from controller with id "+theEvent.controller().id());
}
Code arduino
#include
Servo myservo;
int incomingByte = 0; // for incoming serial data
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
int pos;
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println((int)incomingByte, DEC);
pos=int(incomingByte);
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
}
}
Et voila ca marche
Il a juste fallut régler la plage de valeur du servo pour ne pas le mettre en buté. La consomation du servo est également à surveiller. Parfois il demande pas mal mais c'est surtout quand il arrive en butée. Généralement et en fonctionnement normal c'est de l'ordre de 0,10 à 0,30A max
Code processing
import controlP5.*;
import processing.serial.*;
Serial myPort; // The serial port
ControlP5 controlP5;
public int myColorRect = 200;
public int myColorBackground = 100;
//variable global
int slide1;
void setup() {
size(400,400);
frameRate(25);
controlP5 = new ControlP5(this);
controlP5.addSlider("sliderA",63,118,100,100,260,100,14).setId(4);
controlP5.addTextfield("textA",100,290,100,20).setId(5);
println(Serial.list());
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}
void draw() {
background(myColorBackground);
fill(myColorRect);
rect(0,0,width,100);
myPort.write(slide1);
}
// a slider event will change the value of textfield textA
public void sliderA(int theValue) {
((Textfield)controlP5.controller("textA")).setValue(""+theValue);
}
// for every change in textfield textA, this function will be called
public void textA(String theValue) {
println("### got an event from textA : "+theValue);
slide1=int(theValue);
println("slide 1 : "+slide1);
}
public void controlEvent(ControlEvent theEvent) {
println("got a control event from controller with id "+theEvent.controller().id());
}
Code arduino
#include
Servo myservo;
int incomingByte = 0; // for incoming serial data
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
int pos;
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println((int)incomingByte, DEC);
pos=int(incomingByte);
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
}
}
Et voila ca marche
Il a juste fallut régler la plage de valeur du servo pour ne pas le mettre en buté. La consomation du servo est également à surveiller. Parfois il demande pas mal mais c'est surtout quand il arrive en butée. Généralement et en fonctionnement normal c'est de l'ordre de 0,10 à 0,30A max
lundi 12 décembre 2011
Control P5
Comment contrôler de manière graphique des données numérique.
Beaucoup de choix sous processing.
ControlP5
proControl
Et bien plus encore
ControlP5 et proControl ont l'air assez similaire.
Je vais tenter controlP5.
1-/ L'installation.

Après avoir télécharger la librairie il faut l'installer. Il faut respecter la procédure. Sur un mac creer un repertoire libraries sous le repertoire Documents/Processing. Et copier la bibliothèque ici le répertoire controlP5 dans le répertoire librairies.
2-/ Programme de test.
la biliothèque à l'air assez étendue.

Le but est de créer une valeur numérique avec un slider
Code processing
import controlP5.*;
ControlP5 controlP5;
int Int; // Need here in this case.
void setup() {
controlP5 = new ControlP5(this);
controlP5.addSlider("Int",0,180,3,10,height/2,60,20);
}
void draw(){}
void controlEvent(ControlEvent theEvent) {
if(theEvent.controller().name()=="Int")
{
println((int)theEvent.controller().value());
}
}
et ca marche.

Pour aller plus loi sur controlP5
http://www.mon-club-elec.fr/pmwiki_reference_processing/pmwiki.php?n=Main.LibrairieGUIcontrolP5
La liste des commandes et leurs syntaxes
Beaucoup de choix sous processing.
ControlP5
proControl
Et bien plus encore
ControlP5 et proControl ont l'air assez similaire.
Je vais tenter controlP5.
1-/ L'installation.

Après avoir télécharger la librairie il faut l'installer. Il faut respecter la procédure. Sur un mac creer un repertoire libraries sous le repertoire Documents/Processing. Et copier la bibliothèque ici le répertoire controlP5 dans le répertoire librairies.
2-/ Programme de test.
la biliothèque à l'air assez étendue.

Le but est de créer une valeur numérique avec un slider
Code processing
import controlP5.*;
ControlP5 controlP5;
int Int; // Need here in this case.
void setup() {
controlP5 = new ControlP5(this);
controlP5.addSlider("Int",0,180,3,10,height/2,60,20);
}
void draw(){}
void controlEvent(ControlEvent theEvent) {
if(theEvent.controller().name()=="Int")
{
println((int)theEvent.controller().value());
}
}
et ca marche.

Pour aller plus loi sur controlP5
http://www.mon-club-elec.fr/pmwiki_reference_processing/pmwiki.php?n=Main.LibrairieGUIcontrolP5
La liste des commandes et leurs syntaxes
Inscription à :
Articles (Atom)
