Pong Game Tea Term

Dependencies:   HCSR04 mbed

Fork of contest_IOT2 by Contest IOT GSE5

Committer:
Mickado
Date:
Sun Oct 11 11:18:29 2015 +0000
Revision:
2:35466dfc81fe
Parent:
1:e9d1c42a73ae
Child:
3:6bcdaa2636ec
Premi?re version projet

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:028fac66239d 1 #include "mbed.h"
Mickado 2:35466dfc81fe 2 #include "hcsr04.h"
Mickado 2:35466dfc81fe 3 #include "contest.h"
Mickado 2:35466dfc81fe 4 #include <math.h>
Mickado 2:35466dfc81fe 5
Mickado 2:35466dfc81fe 6 #define ECHO_1 PB_9
Mickado 2:35466dfc81fe 7 #define ECHO_2 PA_5
Mickado 2:35466dfc81fe 8 #define TRIG_1 PB_8
Mickado 2:35466dfc81fe 9 #define TX PA_2
Mickado 2:35466dfc81fe 10 #define RX PA_3
Mickado 2:35466dfc81fe 11 #define PUSH USER_BUTTON //PC_13
Mickado 2:35466dfc81fe 12 #define LED_1 LED1
bcostm 1:e9d1c42a73ae 13
bcostm 1:e9d1c42a73ae 14 //------------------------------------
bcostm 1:e9d1c42a73ae 15 // Hyperterminal configuration
bcostm 1:e9d1c42a73ae 16 // 9600 bauds, 8-bit data, no parity
bcostm 1:e9d1c42a73ae 17 //------------------------------------
bcostm 1:e9d1c42a73ae 18
Mickado 2:35466dfc81fe 19
Mickado 2:35466dfc81fe 20 Serial pc(TX, RX); //UART
Mickado 2:35466dfc81fe 21 DigitalOut led(LED_1); //Led d'état
Mickado 2:35466dfc81fe 22 InterruptIn button(PUSH); //Bouton d'interruption
Mickado 2:35466dfc81fe 23
Mickado 2:35466dfc81fe 24 HCSR04 sensor(TRIG_1, ECHO_1);
Mickado 2:35466dfc81fe 25 Control ctrl;
Mickado 2:35466dfc81fe 26
Mickado 2:35466dfc81fe 27 void changeEtat(){
Mickado 2:35466dfc81fe 28 pc.printf("\033[2J"); //Efface la console
Mickado 2:35466dfc81fe 29 ctrl.marcheArret();
Mickado 2:35466dfc81fe 30 }
Mickado 2:35466dfc81fe 31 float distancePrec=0;
Mickado 2:35466dfc81fe 32
Mickado 2:35466dfc81fe 33
Mickado 2:35466dfc81fe 34
bcostm 0:028fac66239d 35 int main() {
Mickado 2:35466dfc81fe 36 float distance;
Mickado 2:35466dfc81fe 37 pc.printf("\033[2J"); //Efface la console
Mickado 2:35466dfc81fe 38 pc.printf("\033[0;0H"); //Place le curseur à 0:0
Mickado 2:35466dfc81fe 39 pc.printf("\033[?25l"); //Cache le curseur
Mickado 2:35466dfc81fe 40 //pc.printf("\033[?25h"); //Affiche le curseur
Mickado 2:35466dfc81fe 41 pc.printf("Initialisation... ");
Mickado 2:35466dfc81fe 42
Mickado 2:35466dfc81fe 43 //Initialisation de l'interruption : en appuyant sur le bouton bleu de la carte, le programme change d'état
Mickado 2:35466dfc81fe 44 button.fall(&changeEtat);
Mickado 2:35466dfc81fe 45
Mickado 2:35466dfc81fe 46 pc.printf("Ready !\n\r");
Mickado 2:35466dfc81fe 47
Mickado 2:35466dfc81fe 48 //Boucle d'exécution du programme
Mickado 2:35466dfc81fe 49 while(1) {
Mickado 2:35466dfc81fe 50 if(ctrl.isActive()){
Mickado 2:35466dfc81fe 51 led=1;
Mickado 2:35466dfc81fe 52 distance = sensor.distance(); //Mesure de la distance
Mickado 2:35466dfc81fe 53 print_distance(distance, distancePrec); //Affichage à l'écran
Mickado 2:35466dfc81fe 54 distancePrec=distance; //Mise en mémoire
Mickado 2:35466dfc81fe 55 }else{
Mickado 2:35466dfc81fe 56 led=0;
Mickado 2:35466dfc81fe 57 }
Mickado 2:35466dfc81fe 58 wait(0.001);
Mickado 2:35466dfc81fe 59 }
bcostm 0:028fac66239d 60 }
bcostm 0:028fac66239d 61