Aubin GOUHIER
/
clavier
Clavier
Diff: main.cpp
- Revision:
- 0:193510a931d2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri May 31 15:38:54 2019 +0000 @@ -0,0 +1,122 @@ +#include "mbed.h" +#include "USBKeyboard.h" +#include "tracteur.h" + +int main() +{ + keyboard.keyCode(KEY_CAPS_LOCK); + //InitRelais(); + x = 0; + while(1){ + + BpRead(); + if (jeu == val) + Jouer(); + if (game == val) + Play(); + if (stop == val) + Arret(); + + if (x==1){ + + PinRead(); + if (jeu == val) + Jouer(); + if (game == val) + Play(); + if (stop == val) + Arret(); + if (vg < val) + WriteVG(); + if (vd < val) + WriteVD(); + if (av == val) + WriteAV(); + if (ar == val) + WriteAR(); + if (jdroit == val) + WriteJD(); + if (jgauche == val) + WriteJG(); + wait(2*t/3); + //InitRelais(); + } + } +} + +void InitRelais(){ + R1.write(0); + R2.write(0); + R3.write(0); + R4.write(0); + R5.write(0); + R6.write(0); +} + +void Jouer(){ + keyboard.printf("1"); + x = 1; +} + +void Play(){ + keyboard.printf("2"); + x = 1; +} + +void Arret(){ + keyboard.printf("3"); + x = 0; + InitRelais(); +} + +void BpRead(){ + jeu = Jeu.read(); + game = Game.read(); + stop = Stop.read(); +} +void PinRead(){ + jeu = Jeu.read(); + game = Game.read(); + stop = Stop.read(); + av = Av.read(); + ar = Ar.read(); + jdroit = Jdroit.read(); + jgauche = Jgauche.read(); + vg = VG.read(); + vd = VD.read(); +} +void WriteAV(){ + keyboard.keyCode(UP_ARROW); + //R2=0; //jaune + //R1=1; //gris +} + +void WriteAR(){ + keyboard.keyCode(DOWN_ARROW); + //R1=0; //gris + //R2=1; //jaune +} + +void WriteJG(){ + keyboard.printf("w"); + //R4=0; //bleu + //R3=1; //vert +} + +void WriteJD(){ + keyboard.printf("x"); + //R3=0; //vert + //R4=1; //bleu +} + +void WriteVD(){ + keyboard.keyCode(RIGHT_ARROW); + //R6=0; //rouge + //R5=1; //blanc +} + +void WriteVG(){ + keyboard.keyCode(LEFT_ARROW); + //R5=0; //blanc + //R6=1; //rouge +}