Clavier

Dependencies:   mbed USBDevice

Files at this revision

API Documentation at this revision

Comitter:
AubinGOUHIER
Date:
Fri May 31 15:38:54 2019 +0000
Commit message:
Clavier;

Changed in this revision

USBDevice.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
tracteur.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 193510a931d2 USBDevice.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Fri May 31 15:38:54 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/AubinGOUHIER/code/USBDevice/#8a9c969eb0f6
diff -r 000000000000 -r 193510a931d2 main.cpp
--- /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
+}
diff -r 000000000000 -r 193510a931d2 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri May 31 15:38:54 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file
diff -r 000000000000 -r 193510a931d2 tracteur.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tracteur.h	Fri May 31 15:38:54 2019 +0000
@@ -0,0 +1,68 @@
+#include "mbed.h"
+#include "USBKeyboard.h"
+
+USBKeyboard keyboard; // Clavier branchement : bleu D+ blanc D-
+
+//Fonction
+void BpRead(); // Lecture des 3 boutons pour lancer le jeu
+void InitRelais(); // Met les Pins des relais à l'état bas  
+void Jouer(); // Envoi de la touche 1 au PC
+void Play(); // Envoi de la touche 2 au PC
+void Arret(); // Envoi de la touche 3 au PC
+void PinRead(); // Lecture des pins du Joystick et du volant
+void WriteAV(); // Envoi de la touche Flèche Avant au PC + activation du relai 1
+void WriteAR(); // Envoi de la touche Flèche Arrière au PC + activation du relai 2
+void WriteJD(); // Envoi de la touche X au PC + activation du relai 3
+void WriteJG(); // Envoi de la touche W au PC + activation du relai 4
+void WriteVG(); // Envoi de la touche Flèche Gauche au PC + activation du relai 5
+void WriteVD(); // Envoi de l atouche Flèche Droite au PC + activation du relai 6
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+//Variables et Constantes
+
+ const unsigned int t = 1; // Temps en s
+ 
+ //Val dépend du banchement des boutons 
+ const unsigned int val = 1;
+ 
+ unsigned int x = 0;
+  
+ //Relais
+ DigitalOut R1(p5);//relai 1
+ DigitalOut R2(p6);//relai 2
+ DigitalOut R3(p7);//relai 3
+ DigitalOut R4(p8);//relai 4
+ DigitalOut R5(p9);//relai 5
+ DigitalOut R6(p10);//relai 6
+ 
+//Boutons contact normalement fermé
+//bouton "Démarrer Jeu" envoyé 1
+DigitalIn Jeu(p21); //vert bleu
+unsigned int jeu;
+//bouton "Start Game" envoyé 2
+DigitalIn Game(p22); //jaune bleu
+unsigned int game;
+//bouton "Stop" envoyé 3
+DigitalIn Stop(p23); //rouge bleu
+unsigned int stop;
+
+//Joystick contact normalement ouvert
+//bouton "Joystick Avant" envoyé flèche haut
+DigitalIn Av(p29); //vert
+unsigned int av;
+//bouton "Joystick Arrière" envoyé flèche bas
+DigitalIn Ar(p25);//rouge
+unsigned int ar;
+//bouton "Joystick Droit" envoyé W
+DigitalIn Jdroit(p26); //jaune
+unsigned int jdroit;
+//bouton "Joystick Gauche" envoyé X
+DigitalIn Jgauche(p27); //orange
+unsigned int jgauche;
+
+//Volant contact normalement ouvert
+DigitalIn VD(p24); //bleu
+unsigned int vd;
+DigitalIn VG(p28); //gris
+unsigned int vg;