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);
}
}