|
bertolottipf
|
 |
« inserita:: Agosto 19, 2012, 02:06:56 pm » |
|
Scusate... ho un grosso problema con Arduino. Vorrei fare un gioco (già fatto in verità.... è o -) e vorrei farlo funzionare su TV.
Primo problema: come fare a far girare un qualcosa Processinghiano su un qualche cosa Arduiniano? Nel senso che non so come combinare i due codici. Attualmente ho questi due codici:
========================================================================================================= Arduino: ========================================================================================================= /* Circle-A-Sketch TAC Modified from BERTOLOTTI Paolo Francesco */ const int xPin = A0; // sensor to control x coordinates const int yPin = A1; // sensor to control y coordinates const int clearButton = 9; int clearButtonValue;
void setup() { Serial.begin(9600); //pinMode(10, OUTPUT); pinMode(clearButton, INPUT); }
void loop() { clearButtonValue = digitalRead(clearButton);
Serial.print(analogRead(xPin)); Serial.print(","); Serial.print(analogRead(yPin)); Serial.print(","); Serial.print(clearButtonValue); Serial.print("\n"); // per pilotare il led //digitalWrite(10,clearButtonValue); } =========================================================================================================
========================================================================================================= Processing ========================================================================================================= /* Circle-A-Sketch TAC Modified from BERTOLOTTI Paolo Francesco */ import processing.serial.*;
int windowHight = 600; int windowWidth = 800; float xValue = 0; float yValue = 0; float toneValue = 0; boolean pressed = false; Serial myPort;
void setup() { background(222); //creates a window windowWidth (px) x windowHight (px) size(windowWidth, windowHight); smooth(); println(Serial.list()); myPort = new Serial(this, Serial.list()[0], 9600); myPort.bufferUntil('\n'); }
void draw() { //Will fill based on the photoresistor's input fill(0); //creates an ellipse r = 30 w/ centerpoint at the x and y coordinates ellipse(xValue, yValue, 30, 30); }
void serialEvent(Serial myPort) { String inString = myPort.readStringUntil('\n'); float[] coordinates = float(split(inString, ",")); if (coordinates.length >= 3) { //maps the range of values of the potentiometer to the //values of the size of the screen. You //may wish to reverse the 0 and 500 to //get the knobs to go up and down according to a different //twisting direction. xValue = map(coordinates[0], 0, 1023, 0, windowWidth); yValue = map(coordinates[1], 0, 1023, 0, windowHight); if (coordinates[2] == 1) { background(222); } } }
=========================================================================================================
Il risultato è una lavagna magica con il puntatore XXL (probabilmente ci metterò un potenziometro per far selezionare la grandezza della linea)!
GRAZIE PER TUTTO!
|