sto giocando a fare interfacce il più possibile reali senza immagini importate
mettendo ombre, un po si rallenta comunque credo venga fuori qualcosa di carino , se interessa poi sharo su openprocessing
Ciao,
complimenti per il lavoro davvero.
Vorrei provare anche io a fare delle cose simile per comandare arduino con processing; da dove posso cominciare secondo te?
ciao
fiodavid
Ciao,
anche io ho utilizzato Processing per delle interessanti interfacce grafiche,
è davvero un gran software, in questo caso l'area bianca legge gli eventi della keyboard per poter scrivere
ed ogni carattere va a formare una stringa mentre gli eventi del mouse provocano la selezione dei pulsanti
e diversi eventi, il progetto completo è ActivityProgrammer
fiodavid@
per iniziare basta scaricare processing, ed eseguire gli esempi processing che stanno negli esempi di arduino,
file-->esempi-->communication, prova con dimmer.
bello arduinomatteo, mi hai dato una idea ;D
per chi vuol provare un led che lampeggia in processing comandato da arduino
arduino Blink without Delay con l'aggiunta di invio sulla seriale
int ledPin = 13;
int state = 0;
unsigned long b = 0;
const long c = 2000;
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
digitalWrite(13, LOW);
}
void loop() {
unsigned long a = millis();
if (a - b >= c) {
b = a;
if (state == LOW) {
state = HIGH;
}
else {
state = LOW;
}
digitalWrite(ledPin, state);
Serial.write (state);
}
}
processing riceve
import processing.serial.*;
Serial myPort;
int val=0;
void setup() {
size (300, 200);
myPort = new Serial(this, "COM5", 9600);
}
void draw() {
background(170, 170, 180);
smooth(2);
noStroke();
if ( myPort.available()>0 ) {
val = myPort.read();
}
led1();
led2();
}
////////////////////////////////////////////////////////
void led1() {
if (val==0) { //variabile
fill(255, 20, 20);
}
else if (val==1) { //variabile
fill(0);
}
ellipse (100, 100, 20, 20);
}
/////////////////////////////////////////////////////////
void led2() {
translate (100, 100);
fill (255, 255, 255);
ellipse (50, 0, 40, 40);
for (int i=0; i<10; i++) {
fill(70, 70, 74, 30-i);
arc(50, 0, 40, 40, radians(-73+5*i), radians(222+5*i));
}
fill (100, 0, 0) ;
ellipse (50, 0, 20, 20);
for (int i=0; i<5; i++) {
if (val==0) { //variabile
fill (255, 120, 120, 100-i) ;
ellipse (50, -1, 5+4*i, 3+4*i);
}
else if (val==1) { //variabile
fill (255, 255, 255, 25-i) ;
arc(50, 0+i, 18, 20+i, radians(200-3*i), radians(340+3*i));
ellipse (50, -5, 4+i, 2+i);
}
}
noFill();
stroke (0);
strokeWeight(1);
ellipse (50, 0, 21, 21);
}
foto led1 semplice raffigurazione e led2 tuning
Ciao Camperos,
se davvero ti piace il progetto visita pure il mio blog
Sappi che il progetto ActivityProgrammer è già stato inviato sia al blog che al sito facebook di Arduino,
e mi hanno già dato risposta, spero di vederlo a breve...
Grazie
uno slider per variare il led 13, codice piu stringato possibile ma funzionante
arduino:
int Pin = 13;
int val = 0;
void setup() {
Serial.begin(9600);
pinMode(Pin, OUTPUT);
analogWrite(Pin, LOW);
}
void loop() {
if (Serial.available() > 0) {
int r = Serial.parseInt();
analogWrite(Pin, r);
}
}
processing:
import processing.serial.*;
Serial myPort;
float ardu=0;
float slider=0;
float sliderr = 15;
int val=11;
float rectY = 60;
void setup() {
size (600, 300);
myPort = new Serial(this, "COM3", 9600);
delay (2000);
}
void draw() {
background(133);
strokeCap(SQUARE);
strokeWeight(1);
stroke (50, 30);
fill (200, 220, 240);
rect (10, 100, 520, 40, 3);
for (int i =0;i<6;i++) {
fill (40, 50, 60, 50-i);
rect (10, 100, 520, 25+2*i, 3);
}
fill (0);
rect (13, 103, 515, 33, 3);
strokeWeight(18);
stroke (255, 169);
line (13, 119, 527, 119);
fill(255);
for (int i =0;i<6;i++) {
val = 0+50*i;
fill(0);
text(val, 6+100*i, 70);
fill(255);
text(val, 7+100*i, 70);
strokeWeight(1);
stroke(255);
line (15+100*i, 70, 15+100*i, 88 );
}
for (int t =0;t<26;t++) {
line (15+20*t, 80, 15+20*t, 88 );
}
for (int t =0;t<256;t++) {
line (15+2*t, 86, 15+2*t, 88 );
}
strokeWeight(1);
stroke (50, 30);
fill (200, 220, 240);
rect (540, 100, 45, 39, 3);
for (int i =0;i<6;i++) {
fill (40, 50, 60, 50-i);
rect (540, 100, 45, 22+2*i, 3);
}
fill (0);
rect (542, 103, 42, 33, 3);
strokeWeight(18);
stroke (255, 169);
line (13, 119, 527, 119);
update(mouseX, mouseY);
strokeWeight(10);
stroke(255, 0, 0);
line (sliderr, 95, sliderr, 145);
stroke(160, 0, 0, 80);
line (sliderr-5, 102, sliderr-5, 150);
strokeWeight(2);
stroke(233, 233, 230, 150);
line (sliderr+3, 94, sliderr+3, 143);
}
void update(int x, int y) {
if ( (overRect(slider-120, rectY, 440, 120))&& mousePressed ) {
slider = mouseX-0;
if (sliderr < slider-1 ) {
if (mouseX/sliderr<1.1 ) {
sliderr = sliderr+ 1;
}
else {
sliderr = sliderr+ 6;
}
}
if (sliderr > slider+1 ) {
if (sliderr/mouseX<1.3 ) {
sliderr = sliderr- 1;
}
else {
sliderr = sliderr- 6;
}
}
if (slider < 15) {
sliderr = 15;
}
if (slider > 530) {
sliderr = 530;
}
ardu = map(sliderr, 15, 530, 0, 255);
}
fill(255, 100, 100, 205);
int xx =0;
if (ardu>100) {
xx =-7;
}
if (ardu<10) {
xx =7;
}
text((int)ardu, xx+560, 125);
//println ((int)ardu);
myPort.write ((int)ardu +";"); //invio ad arduino
}
boolean overRect(float x, float y, float width, float height) {
if (mouseX >= x && mouseX <= x+width &&
mouseY >= y && mouseY <= y+height) {
return true;
}
else {
return false;
}
}
interessante