arduino processing radar screen

edited January 2014 in Arduino

hello,

I'm trying to make a radar screen with processing and an arduino. but I struggle with the communication between the arduino and processing. the goal is to display a radar line on my computer screen with match with the position of the servo. this is what I have got so far. can please somebody help me. (btw sorry for grammar and spelling, I'm dutch)

processing code: import cc.arduino.*; import processing.serial.*;

Arduino arduino;

color bgcolor = color (0,0,0);
color gridcolor = color (0,0,0);
color sweepercolor = color (102,250,81);
float s;
float rond;
float val;
int l;
void setup(){
  size(800, 640);
  arduino = new Arduino(this,"COM3" , 57600);
}

void draw(){
  background(bgcolor);
  grid(); 
  sweeper();
  circle();
  stipje();
}


 void circle(){
   fill(color (102,250,81,60));
   ellipse(400, 320, 600, 600);
 }

void grid(){
  stroke(#FAF7F7);
  strokeWeight(2);
    line(width/2, height/2, width/2,height/23);            //verticlal grid
    line(width/2, height/2, 700,height/2 );          //horizontal grid
     for(int i = 20; i <300; i+=20){
     line((width/2)+5,i,(width/2)-5,i);
   }
   for(int i = 700; i >400; i-=20){
     line(i, (height/2)+5,i,(height/2)-5 );
}}




void sweeper(){
  rond = map(millis(), 0, 2000, 0, PI);
  strokeWeight(7);
  float f = 0.01;
  for(int i = 38; i>=1; i--){
  stroke(sweepercolor, 2*i);
  line(width/2, height/2, (width/2 + cos(rond-f) * 300), (height/2 + sin(rond-f) * 300));
  f += 0.01; 
  }
}

void stipje(){
int n = 200;
  ellipse(n,n, 20, 20);
}

arduino code:

#include <Servo.h> 

Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 

int pos = 0;    // variable to store the servo position 

void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
  Serial.begin(57600);
} 


void loop() 
{ 
  for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15); 
Serial.println(pos);    

  } 
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
Serial.println(pos);    

} 
} 

Answers

  • Answer ✓

    There are two different ways for Processing and Arduino to communicate, and I think you're trying to mix them. To use Processing's Arduino library you can't use custom software in the Arduino; you must use the Firmata software and then control the Arduino directly from Processing. There's information at http://playground.arduino.cc/Interfacing/Processing

    On the other hand, to run custom software in the Arduino you have to use Processing's Serial library to do the communication. There are good examples in Processing at File->Examples->Libraries->serial.

  • bilmor, thank you for your quick response. i think your answer will help me out. I will let you know....

  • I loaded the processing code intro arduino and it wont compile it stops at stroke(FAF7F7); any thought why jerry

Sign In or Register to comment.