soniamcangel
YaBB Newbies
Offline
Posts: 2
zoom in and out, help please!
Mar 17th , 2009, 8:20pm
Hey guys, I had to create a joystick and 2 buttons that would control google earth. Since it needs python our teacher said that to simulate google earth on processing. Put a picture from google earth and show the movement we want to do. So I had my joystick working to do left right up and down. I got two digital buttons which I want them to make the zoom in and out. I couldn't figure it out, really, I'm a beginner... I found on the reference of processing the scale code, didn t work. I ll post my code and u guys tell me what is wrong thanks Sonia //****************Arduino*********************** /* * Sample code to send multiple analog inputs to Processing * from Arduino */ int analogInput1 = 0; int analogInput2 = 1; int digitalInput3 = 2; int digitalInput4 = 3; int ledPin = 13; int val1 = 0; int val2 = 0; int val3 = 0; int val4 = 0; // an identifier for each value char label1 = 'A'; char label2 = 'B'; void setup() { Serial.begin(9600); //setup the serial port } void loop() { val1 = analogRead(analogInput1); //read pins ito variables val2 = analogRead(analogInput2); val3 = digitalRead(digitalInput3); val4 = digitalRead(digitalInput4); Serial.print (label1, BYTE); Serial.print (val1, DEC); Serial.print (10, BYTE); Serial.print(label2, BYTE); Serial.print (val2, DEC); Serial.print (10, BYTE); delay(300); // pause to prevent comm errors if (val3 & val4 == HIGH) { digitalWrite(ledPin, LOW); }else{ digitalWrite(ledPin, HIGH); delay(200); digitalWrite(ledPin, LOW); delay(300); } } _________________________________________________________ //**************** PROCESSING**************** /* * Processing code to receive multiple analog sensor readings * from Arduino * Uses string buffers to hold values larger than 0-255 (byte size) */ import processing.serial.*; Serial port; int val; //holds serial line data to send to parser String bufA=""; String bufB=""; //buffer strings for each value int inputFlag; // switches between sensor data for as many sensors as used int val1; //global variables to hold the analog sensor values int val2; int val3; int val4; PImage b; //float xCoordinate = 0; //float yCoordinate = 0; void setup(){ size(799,799); port = new Serial(this,Serial.list()[0],9600); //open serial port stroke(0); strokeWeight(4); b = loadImage("main.png"); } void draw (){ if(port.available() > 0){ val = port.read(); serialEvent(val); // send the port.read data to the serial parser function background(0); image(b, (val1/3-700),(val2/3-500)); /* if(val3==390) { image(b, (val1/3),(val2/3)); } else { image(b, (val1/3-700),(val2/3-500));//this the image of google earth //lower the code that I canceled is the one for zoomin that I tried. }*/ //image(b, (val3/3-700),(val4/3-500)); //ellipse (val1/3, val2/3, 30, 30); //smooth(); //line(20,40,80,40); //print ("A = " ); //println ( val1 ); //print ("B = " ); //println ( val2 ); } } void serialEvent(int serial){ if(serial!=10) { // 10 is the line end sent from Arduino if (serial=='A') { //check that buffer is at initial value inputFlag = 1; } if (serial=='B') { inputFlag = 2; } if (inputFlag == 1){ // fill data into buffer string if (serial!='A') { bufA += char(serial); } } if (inputFlag == 2){ if (serial!='B') { // fill data into buffer string bufB+= char(serial); } } } else { if (inputFlag == 1){ val1 = int(bufA); // load data into variable from the buffer bufA=""; //clear the buffer } if (inputFlag == 2) { val2 = int(bufB); // load data into variable from the buffer bufB=""; // clear the buffer } } }