- List des partie utilisée dans le projet:
Une plaque d'essaie
Des fils électrique mâle mâle &mâle femelle
Du contre plaqué pour l’assemblage
Des vis pour l'attachement
- Schéma de principe:
- Code pour Arduino et pour processing:
- Code arduino:(ci-dessous )
- Code pour Arduino et pour processing:
- Code arduino:(ci-dessous )
#define ECHOPIN 7 // Pin pour recevoir impulsion d'écho
#define TRIGPIN 8
#include <Servo.h>
Servo myservo; // Créer un objet d'asservissement pour contrôler un servomoteur
int pos = 0; /
void setup() {
Serial.begin(9600);
myservo.attach(9);
pinMode(3,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,INPUT);
pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
}
void Print (int R , int T)
{
Serial.print(R);Serial.print(", ");
Serial.print(T);Serial.println(".");
delay(100);
}
float Distance () {
digitalWrite(TRIGPIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGPIN, LOW);
// Distance Calculation
float distance = pulseIn(ECHOPIN, HIGH);
distance= distance/58;
return(distance);
}
void loop() {
myservo.write(45);
delay(2000);
for(pos = 45; pos <= 135; pos += 3)
{ // in steps of 1 degree
myservo.write(pos);
Print(Distance() , pos);
delay(10);
}
delay(1000);
for(pos = 135; pos>=45; pos-=3)
{
myservo.write(pos);
Print(Distance() , pos);
delay(10); // waits 15ms for the servo to reach the position
}
}
- Code processing:(ci-dessous)
import processing.serial.*; Serial port; Serial port2; String data = ""; String Radius = ""; String Theta = ""; int index = 0; float distance = 0; float angle = 0; float pi = 22.0/7; void setup() { size(1000,1000); background(255,255,255); ellipse(500,500,1000,1000); line(500,0,500,1000); line(0,500,1000,500); line(500,500,1000,0); line(500,500,0,0); port = new Serial(this, "COM6", 9600);
port.bufferUntil('.');
}
void draw()
{
}
void serialEvent(Serial port)
{
data = port.readStringUntil('.');
data = data.substring(0, data.length() - 1);
index = data.indexOf(",");
Radius = data.substring(0, index);
Theta = data.substring (index+1 , data.length());
translate(500,500);
point (0,0);
distance = float(Radius);
angle = float(Theta) /180 * pi;
fill(30,200,30);
ellipse(distance * cos(angle) , -1 * distance * sin(angle) , 5,5);
}