le code complet de l'arduino:
#include #include
Servo mservo;
int angle = 90;
int MDAV = 2;
int MDAR = 3;
int MGAV = 4;
int MGAR = 5;
int L = 7;
int V = 8;
int BA = 9;
int BB = 10;
int Tension = 0;
int TBA = 0;
int TBB = 0;
int Move = 0;
int Cam = 0;
void setup() {
Serial.begin(115200);
MsTimer2::set(10 , serie);
MsTimer2::start();
pinMode(MDAV,OUTPUT);
pinMode(MDAR,OUTPUT);
pinMode(MGAV,OUTPUT);
pinMode(MGAR,OUTPUT);
pinMode(L,OUTPUT);
pinMode(V,OUTPUT);
pinMode(BA,OUTPUT);
pinMode(BB,OUTPUT);
mservo.attach(6);
mservo.write(angle);
digitalWrite(BA, HIGH);
delay(100);
TBA = (int) ((analogRead(Tension)*5./1024.)*2000.);
Serial.println(TBA);
delay(10);
digitalWrite(BA, LOW);
digitalWrite(BB, HIGH);
delay(100);
TBB = (int) ((analogRead(Tension)*5./1024.)*200.);
Serial.println(TBB);
delay(10);
digitalWrite(BB, LOW);
digitalWrite(BA, HIGH);
}
void loop() {
move();
cam();
Batt();
}
void cam() {
switch(Cam) {
case 1:
angle = angle + 1;
if(angle > 180)
{
angle = 180;
}
mservo.write(angle);
delay(25);
break;
case 2:
angle = angle - 1;
if(angle < 0)
{
angle = 0;
}
mservo.write(angle);
delay(25);
break;
}
}
void move() {
switch(Move) {
case 1:
digitalWrite(MDAV,HIGH);
digitalWrite(MDAR,LOW);
digitalWrite(MGAV,HIGH);
digitalWrite(MGAR,LOW);
break;
case 2:
digitalWrite(MDAV,LOW);
digitalWrite(MDAR,HIGH);
digitalWrite(MGAV,LOW);
digitalWrite(MGAR,HIGH);
break;
case 3:
digitalWrite(MDAV,LOW);
digitalWrite(MDAR,HIGH);
digitalWrite(MGAV,HIGH);
digitalWrite(MGAR,LOW);
break;
case 4:
digitalWrite(MDAV,HIGH);
digitalWrite(MDAR,LOW);
digitalWrite(MGAV,LOW);
digitalWrite(MGAR,HIGH);
break;
case 0:
ini();
break;
}
}
void ini() {
digitalWrite(MDAV,LOW);
digitalWrite(MDAR,LOW);
digitalWrite(MGAV,LOW);
digitalWrite(MGAR,LOW);
}
void Batt () {
if (TBA < 5600 && digitalRead(BA) == HIGH) {
digitalWrite(BA, LOW);
digitalWrite(BB, HIGH);
}
else if (TBB < 560 && digitalRead(BB) == HIGH) {
digitalWrite(BB, LOW);
digitalWrite(BA, HIGH);
}
else if (digitalRead(BA) == HIGH) {
TBA = (int) ((analogRead(Tension)*5./1024.)*2000.);
}
else if (digitalRead(BB) == HIGH) {
TBB = (int) ((analogRead(Tension)*5./1024.)*200.);
}
Serial.println(TBA);
delay(10);
Serial.println(TBB);
delay(10);
}
void serie () {
if (Serial.available() > 0) {
switch (Serial.read()) {
case 'd':
Move = 3;
break;
case 'q':
Move = 4;
break;
case 'z':
Move = 1;
break;
case 's':
Move = 2;
break;
case 'p':
Cam = 1;
break;
case 'm':
Cam = 2;
break;
case 'l':
digitalWrite(L,HIGH);
break;
case 0:
Move = 0;
break;
case 1:
Cam = 0;
break;
case 2:
digitalWrite(L,LOW);
break;
case 'v':
digitalWrite(V,HIGH);
break;
case 3:
digitalWrite(V,LOW);
break;
}
}
}
[/code]
le code complet processing (c'est un programme test) :
import processing.serial.*;
import processing.video.*;
Serial MySerialPort;
int[] touche = new int[10];
float[] batt = new float[4];
int x = 65;
int y = 110;
void setup() {
println(Serial.list());
MySerialPort = new Serial(this, Serial.list()[0], 115200);
size (1350, 690);
background(0, 0, 0);
PImage robot;
robot = loadImage("DSC02788.JPG");
image(robot,230,10,890,670);
rectMode(CENTER);
fill(127);
rect(x + 50, y + 50, 50, 50);
rect(x , y + 100, 50, 50);
rect(x + 50, y + 100, 50, 50);
rect(x + 100, y + 100, 50, 50);
rect(x , y + 250, 50, 50);
rect(x, y + 300, 50, 50);
rect(x , y + 450, 50, 50);
rect(x, y + 500, 50, 50);
fill(255);
text("Interface de controle", x - 5 , y - 85);
text("DELTA 1715", x + 20 , y - 65);
text("Commande Mouvement", x - 15 , y - 5);
text("Commande Camera", x - 10, y + 195);
text("Commande Fonction", x - 15, y + 395);
text("Haut", x + 50, y + 250);
text("Bas", x + 50, y + 300);
text("Eclairage", x + 50, y + 450);
text("Viseur", x + 50, y + 500);
serie();
}
void draw() {
if (MySerialPort.available() != 0) {
println(MySerialPort.read());
}
}
void keyPressed() {
switch (key) {
case 'p':
touche[4] = 'p';
break;
case 'm':
touche[5] = 'm';
break;
case 'd':
touche[0] = 'd';
break;
case 'q':
touche[1] = 'q';
break;
case 'z':
touche[2] = 'z';
break;
case 's':
touche[3] = 's';
break;
case 'l':
if (touche[6] == 'l') {
touche[6] = 2;
}
else {
touche[6] = 'l';
}
break;
case 'v':
if (touche[7] == 'v') {
touche[7] = 3;
}
else {
touche[7] = 'v';
}
break;
}
serie();
}
void keyReleased() {
switch (key) {
case 'p':
touche[4] = 1;
break;
case 'm':
touche[5] = 1;
break;
case 'd':
touche[0] = 0;
break;
case 'q':
touche[1] = 0;
break;
case 'z':
touche[2] = 0;
break;
case 's':
touche[3] = 0;
break;
}
serie();
}
void Batt () {
if (MySerialPort.read() > 100 && MySerialPort.read() < 200) {
batt[0] = (MySerialPort.read() - 105.6) * 100. / 1.5;
}
if (MySerialPort.read() > 300 && MySerialPort.read() < 400) {
batt[1] = (MySerialPort.read() - 305.6) * 100. / 1.5;
}
println(batt[0]);
println(batt[1]);
}
void serie () {
fill(225);
rect(x + 50, y + 50, 40, 40);
rect(x , y + 100, 40, 40);
rect(x + 50, y + 100, 40, 40);
rect(x + 100, y + 100, 40, 40);
rect(x , y + 250, 40, 40);
rect(x , y + 300, 40, 40);
fill(127);
if (touche[0] == 'd') {
MySerialPort.write('d');
rect(x + 100, y + 100, 40, 40);
}
else if (touche[1] == 'q') {
MySerialPort.write('q');
rect(x , y + 100, 40, 40);
}
else if (touche[2] == 'z') {
MySerialPort.write('z');
rect(x + 50, y + 50, 40, 40);
}
else if (touche[3] == 's') {
MySerialPort.write('s');
rect(x + 50, y + 100, 40, 40);
}
else {
MySerialPort.write(0);
}
if (touche[4] == 'p') {
MySerialPort.write('p');
rect(x , y + 250, 40, 40);
}
else if (touche[5] == 'm') {
MySerialPort.write('m');
rect(x , y + 300, 40, 40);
}
else {
MySerialPort.write(1);
}
if (touche[6] == 'l') {
MySerialPort.write('l');
rect(x , y + 450, 40, 40);
}
else {
fill(225);
MySerialPort.write(2);
rect(x , y + 450, 40, 40);
}
if (touche[7] == 'v') {
fill(127);
MySerialPort.write('v');
rect(x , y + 500, 40, 40);
}
else {
fill(225);
MySerialPort.write(3);
rect(x , y + 500, 40, 40);
}
fill(0);
text("Z", x + 45, y + 55);
text("Q", x - 5, y + 105);
text("S", x + 45, y + 105);
text("D", x + 95, y + 105);
text("P", x - 5 , y + 255);
text("M", x - 5, y + 305);
text("L", x - 5 , y + 455);
text("V", x - 5, y + 505);
}
[/code]