PFont myFont; import processing.serial.*; Serial monport; String port1=Serial.list()[0]; int variable=0; boolean etat1, etat2, etat3, etat4; int temps=millis(); int e1=0; int e2=0; int e3=0; int e4=0; int e5=0; int e6=0; int e7=0; //--------------------------------------------- void setup() { monport=new Serial(this, port1, 9600); println(Serial.list()); size(970, 300); myFont=loadFont("ArialMT-48.vlw"); background(255); strokeWeight(4); stroke(255, 0, 0, 127);//rouge smooth(); frameRate(60); // temps=millis(); mise au point // println(temps); mise au point //ag1droit();//positionne l'aiguillage etat1=true;//mémorise sa position etat2=true;//mémorise sa position etat3=true;//mémorise sa position gare etat4=true;// tempo(2000); //ag2droit(); // temps=millis(); mise au point // println(temps); mise au point etat2=true; //stroke (0,0,0,0); canton(300, 120, 700, 120, 30, 0, 0, 0, 255); //arret(12); flechegauchegris(125); flechedroitegris(125); c1carrevert(); c1carrerouge(); c2carrevert(); c2carrerouge(); c3carrerouge(); c3carrevert(); c4carrerouge(); c4carrevert(); canton(10, 50, 230, 50, 30, 255, 0, 0, 255); //canton1on(); //affichage portion de rail rail sup ,rail inf ,hauteur //orig x,orig y,orig x1 fin,orig y1,hauteur,couleur trait canton(10, 50, 250, 50, 30, 0, 0, 0, 255);//cote droit c1 canton(750, 50, 950, 50, 30, 0, 0, 0, 255);//cotegauche C2 canton(300, 50, 700, 50, 30, 0, 0, 0, 255);//railavant c3 canton(300, 120, 700, 120, 30, 0, 0, 0, 255);//gare c4 //canton1off(); //canton2off(); //canton2on(); //canton3off(); //canton3off(); //canton4off(); //canton4on(); } //---------------------------------------------- void draw () { //afficheaig(); //affichsouris(); // commande par bouton ag1vert(); ag1rouge(); ag2vert(); ag2rouge(); canton1rouge(); canton1vert(); canton2rouge(); canton2vert(); canton3vert(); canton3rouge(); canton4vert(); canton4rouge(); sensdroit(); sensdgauche(); // canton1on(); ag1();//bouton commande aiguillage ag2();//bouton commande aiguillage // garerouge(); //garevert(); } //------------------------------------------------------- void canton1off() { //rouge strokeWeight(4); canton(10, 50, 250, 50, 30, 255, 0, 0, 255); } void canton1on() { //rouge strokeWeight(4); canton(10, 50, 250, 50, 30, 0, 0, 0, 255); } void canton2off() { //rouge strokeWeight(4); canton(345, 50, 640, 50, 30, 255, 0, 0, 255); } void canton2on() { //rouge strokeWeight(4); canton(345, 50, 640, 50, 30, 0, 0, 0, 255); } void canton3off() { //rouge strokeWeight(4); canton(795, 50, 950, 50, 30, 255, 0, 0, 255); } void canton3on() { //rouge strokeWeight(4); canton(795, 50, 950, 50, 30, 0, 0, 0, 255); } void canton4on() { //noir strokeWeight(4); canton(360, 120, 640, 120, 30, 0, 0, 0, 255); } void canton4off() { //rouge strokeWeight(4); canton(360, 120, 640, 120, 30, 255, 0, 0, 255); } //ccommande aiguillage1 droit void ag1vert() { if ( mouseX >250 && mouseX <300 && mouseY >10 && mouseY<40) { cursor(HAND); tempo(100); if (mousePressed == true) { println ("action1droit"); ag1droit(); } else { println ("pointer1"); } cursor(ARROW); // tempo(500); println ("pointer2"); } } //ccommande aiguillage1 dévié void ag1rouge() { if (mouseX >230 && mouseX <270 && mouseY >80 && mouseY<140) { cursor(HAND); tempo(100); if ( (mousePressed == true)) { println ("action1ddevie"); ag1devie(); } else cursor(ARROW); } } //ccommande aiguillage2 droit *************************** void ag2vert() { if ( mouseX >700 && mouseX <760 && mouseY >10 && mouseY<40) { cursor(HAND); tempo(100); if (mousePressed == true) { println ("action1droit"); ag2droit(); } else { println ("pointer1"); } cursor(ARROW); // tempo(500); println ("pointer2"); } } //ccommande aiguillage2 dévié **************************** void ag2rouge() { if (mouseX >740 && mouseX <800 && mouseY >100 && mouseY<150) { cursor(HAND); tempo(100); if ( (mousePressed == true)) { println ("action1ddevie"); ag2devie(); } else cursor(ARROW); } } //commande canton rouge ***************** void canton1rouge() { if (mouseX >65 && mouseX <90 && mouseY >5 && mouseY<40) { cursor(HAND); tempo(100); if ( (mousePressed == true)) { println ("canton1off"); strokeWeight (4); monport.write(2); monport.write(0); canton1off(); tempo(1000); } else cursor(ARROW); } } void canton1vert() { if (mouseX >120 && mouseX <155 && mouseY >5 && mouseY<40) { cursor(HAND); tempo(100); if ( (mousePressed == true)) { println ("canton1on"); monport.write(1); monport.write(0); strokeWeight (4); canton1on(); tempo(1000); } else cursor(ARROW); } } void canton2rouge() { if (mouseX >400 && mouseX <430 && mouseY >5 && mouseY<40) { cursor(HAND); tempo(100); if ( (mousePressed == true)) { println ("canton2off"); strokeWeight (4); monport.write(4); monport.write(0); canton2off(); tempo(1000); } else cursor(ARROW); } } void canton2vert() { if (mouseX >500 && mouseX <530 && mouseY >5 && mouseY<40) { cursor(HAND); tempo(100); if ( (mousePressed == true)) { println ("canton2on"); strokeWeight (4); monport.write(3); monport.write(0); canton2on(); tempo(1000); } else cursor(ARROW); } } void canton3rouge() { if (mouseX >815 && mouseX <850 && mouseY >5 && mouseY<40) { cursor(HAND); tempo(100); if ( (mousePressed == true)) { println ("canton3off"); strokeWeight (4); monport.write(6); monport.write(0); canton3off(); tempo(1000); } else cursor(ARROW); } } void canton3vert() { if (mouseX >875 && mouseX <910 && mouseY >5 && mouseY<40) { cursor(HAND); tempo(100); if ( (mousePressed == true)) { println ("canton4on"); strokeWeight (4); monport.write(5); monport.write(0); canton3on(); tempo(1000); } else cursor(ARROW); } } void canton4rouge() { if (mouseX >440 && mouseX <480 && mouseY >180 && mouseY<200) { cursor(HAND); tempo(100); if ( (mousePressed == true)) { println ("canton4off"); strokeWeight (4); monport.write(8); monport.write(0); canton4off(); tempo(1000); } else cursor(ARROW); } } void canton4vert() { if (mouseX >545 && mouseX <560 && mouseY >180 && mouseY<200) { cursor(HAND); tempo(100); if ( (mousePressed == true)) { println ("canton4on"); strokeWeight (4); monport.write(7); monport.write(0); canton4on(); tempo(1000); } else cursor(ARROW); } } void sensdroit() { if (mouseX >400 && mouseX <480 && mouseY >220 && mouseY<260) { cursor(HAND); tempo(100); if ( (mousePressed == true)) { println ("sens droit"); flechedroitenoir(0); flechegauchegris(200); strokeWeight (4); monport.write(20); monport.write(0); tempo(1000); } else cursor(ARROW); } } void sensdgauche() { if (mouseX >530 && mouseX <620 && mouseY >220 && mouseY<260) { cursor(HAND); tempo(100); if ( (mousePressed == true)) { println ("sens gauche"); flechedroitegris(200); flechegauchenoir(0); strokeWeight (4); monport.write(21); monport.write(0); tempo(1000); } else cursor(ARROW); } } void flechedroitegris(int coul) { strokeWeight(6); stroke(coul); line (420, 240, 470, 240); line (450, 230, 470, 240); line (450, 250, 470, 240); } void flechegauchegris(int coul) { strokeWeight(6); stroke(coul); line (550, 240, 600, 240); line (550, 240, 570, 230); line (550, 240, 570, 250); } void flechedroitenoir(int coul) { strokeWeight(6); stroke(coul); line (420, 240, 470, 240); line (450, 230, 470, 240); line (450, 250, 470, 240); } void flechegauchenoir(int coul) { strokeWeight(6); stroke(coul); line (550, 240, 600, 240); line (550, 240, 570, 230); line (550, 240, 570, 250); } void arret(int coul) { fill (coul); rect(500, 230, 20, 20); } void ag1devie()//affichage aiguillage { strokeWeight(4); stroke (255); line (250, 50, 298, 50); line (250, 80, 298, 80); strokeWeight(2); stroke (0); line (250, 50, 300, 120); line (250, 80, 300, 150); monport.write(17); monport.write(0); tempo(1000); } void ag1droit()//affichage aiguillage { strokeWeight(4); stroke (255); line (250, 50, 298, 120); line (250, 80, 298, 150); strokeWeight(2); stroke (0); line (250, 50, 300, 50); line (250, 80, 300, 80); monport.write(16); monport.write(0); tempo(1000); } void ag2droit()//affichage aiguillage { strokeWeight(4); stroke (255); line (700, 120, 750, 50); line (700, 150, 750, 80); strokeWeight(2); stroke (0); line (700, 50, 750, 50); line (700, 80, 750, 80); monport.write(18); monport.write(0); tempo(1000); } void ag2devie()//affichage aiguillage { strokeWeight(4); stroke (255); line (700, 50, 750, 50); line (700, 80, 750, 80); strokeWeight(2); stroke (0); line (700, 120, 750, 50); line (700, 150, 750, 80); monport.write(19); monport.write(0); tempo(1000); } void canton(int x0, int y0, int x1, int y1, int h1, int c1, int c2, int c3, int c0 )//afichage des cantons { // int x0=1,y0=0, nb=0,h1=0, lg1=0 ,ecart=0 ,x1=0 ,y1=0,nbr; //background(255); stroke (c1, c2, c3, c0);// couleur du trait strokeWeight(3);//epaisseur du trait //x0=20;y0=100;x1=250;y1=100; line(x0, y0, x1, y1); //affichage rail line(x0, y0+h1, x1, y0+h1);//affichage rail int nb=4; int nbr=(x1-x0)/3; for (nb=0; nb