Programme RC test publication
Dependencies: mbed SimpleBLE X_NUCLEO_IDB0XA1 LIS3DH_spi
main.cpp@11:72c976e0d889, 2020-01-26 (annotated)
- Committer:
- MaxenceGalopin
- Date:
- Sun Jan 26 10:37:54 2020 +0000
- Revision:
- 11:72c976e0d889
- Parent:
- 10:a15e07c7ad61
Copie programme Envoi final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jimbaud | 6:1670244c4eb4 | 1 | //Includes |
jimbaud | 6:1670244c4eb4 | 2 | |
janjongboom | 0:ba1c49874d3c | 3 | #include "mbed.h" |
janjongboom | 0:ba1c49874d3c | 4 | #include "SimpleBLE.h" |
jimbaud | 6:1670244c4eb4 | 5 | #include "LIS3DH.h" |
Nthnthj | 9:3d83d0b410b8 | 6 | #include "stdlib.h" |
janjongboom | 0:ba1c49874d3c | 7 | |
jimbaud | 6:1670244c4eb4 | 8 | |
Nthnthj | 9:3d83d0b410b8 | 9 | //Bluetooth hc05-6 |
Nthnthj | 9:3d83d0b410b8 | 10 | |
Nthnthj | 10:a15e07c7ad61 | 11 | #define TX D0 |
Nthnthj | 10:a15e07c7ad61 | 12 | #define RX D1 |
Nthnthj | 9:3d83d0b410b8 | 13 | |
jimbaud | 6:1670244c4eb4 | 14 | |
jimbaud | 6:1670244c4eb4 | 15 | |
jimbaud | 6:1670244c4eb4 | 16 | |
jimbaud | 6:1670244c4eb4 | 17 | // GPIO set |
jimbaud | 6:1670244c4eb4 | 18 | |
jimbaud | 6:1670244c4eb4 | 19 | //Interrupt input |
jimbaud | 6:1670244c4eb4 | 20 | |
jimbaud | 6:1670244c4eb4 | 21 | InterruptIn user1(PC_13); //User1 |
Nthnthj | 9:3d83d0b410b8 | 22 | InterruptIn boutton1(D3); |
Nthnthj | 9:3d83d0b410b8 | 23 | InterruptIn boutton2(D4); |
Nthnthj | 9:3d83d0b410b8 | 24 | InterruptIn event(A0); |
Nthnthj | 9:3d83d0b410b8 | 25 | |
Nthnthj | 9:3d83d0b410b8 | 26 | Timer timer; |
Nthnthj | 9:3d83d0b410b8 | 27 | |
Nthnthj | 9:3d83d0b410b8 | 28 | DigitalOut led1(D14); |
Nthnthj | 9:3d83d0b410b8 | 29 | DigitalOut transistor(D6); |
jimbaud | 6:1670244c4eb4 | 30 | |
jimbaud | 6:1670244c4eb4 | 31 | //PWM output |
jimbaud | 6:1670244c4eb4 | 32 | |
jimbaud | 6:1670244c4eb4 | 33 | PwmOut PWMoutput(PB_1); //Main PWM output |
jimbaud | 6:1670244c4eb4 | 34 | PwmOut Green(PC_8); //PWM Red LED |
jimbaud | 6:1670244c4eb4 | 35 | PwmOut Red(PC_6); //PWM Green LED |
jimbaud | 6:1670244c4eb4 | 36 | PwmOut Blue(PC_9); //PWM Blue LED |
jimbaud | 6:1670244c4eb4 | 37 | |
Nthnthj | 9:3d83d0b410b8 | 38 | |
Nthnthj | 10:a15e07c7ad61 | 39 | Serial BT(USBTX,USBRX); |
Nthnthj | 10:a15e07c7ad61 | 40 | //Serial pc(USBTX, USBRX); |
Nthnthj | 9:3d83d0b410b8 | 41 | |
Nthnthj | 9:3d83d0b410b8 | 42 | int compteur; |
Nthnthj | 9:3d83d0b410b8 | 43 | bool flag = false; |
Nthnthj | 9:3d83d0b410b8 | 44 | float end,begin; |
Nthnthj | 10:a15e07c7ad61 | 45 | int message = 0; |
Nthnthj | 10:a15e07c7ad61 | 46 | int temps1 = 0; |
Nthnthj | 10:a15e07c7ad61 | 47 | string course; |
Nthnthj | 10:a15e07c7ad61 | 48 | char Buffer[10]; |
Nthnthj | 10:a15e07c7ad61 | 49 | int i = 0; |
Nthnthj | 10:a15e07c7ad61 | 50 | int begin2 = 0; |
Nthnthj | 10:a15e07c7ad61 | 51 | |
Nthnthj | 10:a15e07c7ad61 | 52 | void envoi(int message){ |
Nthnthj | 10:a15e07c7ad61 | 53 | BT.printf("%i\n", message); |
Nthnthj | 10:a15e07c7ad61 | 54 | } |
Nthnthj | 10:a15e07c7ad61 | 55 | |
Nthnthj | 9:3d83d0b410b8 | 56 | |
Nthnthj | 9:3d83d0b410b8 | 57 | void pressed(){ |
Nthnthj | 10:a15e07c7ad61 | 58 | led1 = !led1; |
Nthnthj | 10:a15e07c7ad61 | 59 | temps1 = timer.read_ms(); |
Nthnthj | 10:a15e07c7ad61 | 60 | message = temps1; |
Nthnthj | 10:a15e07c7ad61 | 61 | envoi(message); |
Nthnthj | 9:3d83d0b410b8 | 62 | } |
Nthnthj | 9:3d83d0b410b8 | 63 | |
Nthnthj | 9:3d83d0b410b8 | 64 | |
Nthnthj | 9:3d83d0b410b8 | 65 | void skater_d() |
Nthnthj | 9:3d83d0b410b8 | 66 | { |
Nthnthj | 9:3d83d0b410b8 | 67 | if(flag==false) { |
Nthnthj | 10:a15e07c7ad61 | 68 | // pc.printf("Ligne de depart coupee solo \n"); |
Nthnthj | 9:3d83d0b410b8 | 69 | if( flag == false) { |
Nthnthj | 9:3d83d0b410b8 | 70 | //printf("Depart skate \n"); |
Nthnthj | 9:3d83d0b410b8 | 71 | begin = timer.read_ms(); |
Nthnthj | 9:3d83d0b410b8 | 72 | compteur=100; |
Nthnthj | 9:3d83d0b410b8 | 73 | //pc.printf(" skater lance %.0f \n", begin); |
Nthnthj | 9:3d83d0b410b8 | 74 | flag = true; |
Nthnthj | 9:3d83d0b410b8 | 75 | } else if(flag == true) { |
Nthnthj | 9:3d83d0b410b8 | 76 | //printf("erreur \n"); |
Nthnthj | 9:3d83d0b410b8 | 77 | //pc.printf(" Temps du skater : %.0f \n", end-begin); |
Nthnthj | 9:3d83d0b410b8 | 78 | flag = false; |
Nthnthj | 9:3d83d0b410b8 | 79 | } |
Nthnthj | 9:3d83d0b410b8 | 80 | } |
Nthnthj | 9:3d83d0b410b8 | 81 | else if(flag==true) { |
Nthnthj | 9:3d83d0b410b8 | 82 | //printf("Ligne d'arrivee coupee \n"); |
Nthnthj | 9:3d83d0b410b8 | 83 | if( flag == false ) { |
Nthnthj | 9:3d83d0b410b8 | 84 | //printf("arrivee coupe sans depart\n"); |
Nthnthj | 9:3d83d0b410b8 | 85 | flag = true; |
Nthnthj | 9:3d83d0b410b8 | 86 | } else if(flag == true ) { |
Nthnthj | 9:3d83d0b410b8 | 87 | //printf("Arrivee skate \n"); |
Nthnthj | 9:3d83d0b410b8 | 88 | end = timer.read_ms(); |
Nthnthj | 9:3d83d0b410b8 | 89 | //Temps = end-begin; |
Nthnthj | 9:3d83d0b410b8 | 90 | compteur=200; |
Nthnthj | 9:3d83d0b410b8 | 91 | //wait(1); |
Nthnthj | 9:3d83d0b410b8 | 92 | //pc.printf(" Temps du skater : %.0f \n", end-begin); |
Nthnthj | 9:3d83d0b410b8 | 93 | flag = false; |
Nthnthj | 9:3d83d0b410b8 | 94 | } |
Nthnthj | 9:3d83d0b410b8 | 95 | } |
Nthnthj | 9:3d83d0b410b8 | 96 | } |
jimbaud | 6:1670244c4eb4 | 97 | |
Nthnthj | 10:a15e07c7ad61 | 98 | void test_mode(char Buffer[10]){ |
Nthnthj | 10:a15e07c7ad61 | 99 | if(Buffer[0] == 'S'){ |
Nthnthj | 10:a15e07c7ad61 | 100 | // pc.printf("mode solo \n"); |
Nthnthj | 10:a15e07c7ad61 | 101 | timer.reset(); |
Nthnthj | 10:a15e07c7ad61 | 102 | flag = false; |
Nthnthj | 10:a15e07c7ad61 | 103 | }else if(Buffer[0]=='D'){ |
Nthnthj | 10:a15e07c7ad61 | 104 | // pc.printf("mode duo \n"); |
Nthnthj | 10:a15e07c7ad61 | 105 | flag=true; |
Nthnthj | 10:a15e07c7ad61 | 106 | timer.reset(); |
Nthnthj | 10:a15e07c7ad61 | 107 | } |
Nthnthj | 10:a15e07c7ad61 | 108 | else if (Buffer[0] == 'R'){ |
Nthnthj | 10:a15e07c7ad61 | 109 | // pc.printf("Reset timer \n "); |
Nthnthj | 10:a15e07c7ad61 | 110 | timer.reset(); |
Nthnthj | 10:a15e07c7ad61 | 111 | //wait(1); |
Nthnthj | 10:a15e07c7ad61 | 112 | //timer.start(); |
Nthnthj | 10:a15e07c7ad61 | 113 | } |
Nthnthj | 10:a15e07c7ad61 | 114 | // pc.printf(" Test \n"); |
Nthnthj | 10:a15e07c7ad61 | 115 | } |
Nthnthj | 10:a15e07c7ad61 | 116 | |
Nthnthj | 10:a15e07c7ad61 | 117 | |
Nthnthj | 10:a15e07c7ad61 | 118 | void RXevent (){ |
Nthnthj | 10:a15e07c7ad61 | 119 | if(BT.readable()){ |
Nthnthj | 10:a15e07c7ad61 | 120 | BT.scanf("%s", &Buffer); |
Nthnthj | 10:a15e07c7ad61 | 121 | wait(1); |
Nthnthj | 10:a15e07c7ad61 | 122 | } |
Nthnthj | 10:a15e07c7ad61 | 123 | |
Nthnthj | 10:a15e07c7ad61 | 124 | if (Buffer[0] == 'R'){ |
Nthnthj | 10:a15e07c7ad61 | 125 | timer.reset(); |
Nthnthj | 10:a15e07c7ad61 | 126 | } |
Nthnthj | 10:a15e07c7ad61 | 127 | return; |
Nthnthj | 10:a15e07c7ad61 | 128 | } |
Nthnthj | 10:a15e07c7ad61 | 129 | |
Nthnthj | 10:a15e07c7ad61 | 130 | |
Nthnthj | 10:a15e07c7ad61 | 131 | |
jimbaud | 6:1670244c4eb4 | 132 | //Main program |
jimbaud | 6:1670244c4eb4 | 133 | |
jimbaud | 6:1670244c4eb4 | 134 | int main(int, char**) |
jimbaud | 6:1670244c4eb4 | 135 | { |
Nthnthj | 9:3d83d0b410b8 | 136 | transistor=1; |
Nthnthj | 9:3d83d0b410b8 | 137 | timer.start(); |
Nthnthj | 10:a15e07c7ad61 | 138 | BT.attach(&RXevent); |
Nthnthj | 9:3d83d0b410b8 | 139 | user1.fall(&pressed); |
Nthnthj | 10:a15e07c7ad61 | 140 | event.fall(&pressed); |
MaxenceGalopin | 11:72c976e0d889 | 141 | |
jimbaud | 6:1670244c4eb4 | 142 | while (1) { |
Nthnthj | 9:3d83d0b410b8 | 143 | |
Nthnthj | 10:a15e07c7ad61 | 144 | |
Nthnthj | 10:a15e07c7ad61 | 145 | Green = 0.001; |
Nthnthj | 10:a15e07c7ad61 | 146 | wait(1); |
Nthnthj | 10:a15e07c7ad61 | 147 | Green = 0; |
Nthnthj | 10:a15e07c7ad61 | 148 | wait(1); |
Nthnthj | 9:3d83d0b410b8 | 149 | //} |
jimbaud | 6:1670244c4eb4 | 150 | |
janjongboom | 0:ba1c49874d3c | 151 | } |
janjongboom | 0:ba1c49874d3c | 152 | } |
Nthnthj | 9:3d83d0b410b8 | 153 |