
Pour les potos en galère tmtc
main.cpp@7:1cced6852c01, 2021-03-31 (annotated)
- Committer:
- lauric
- Date:
- Wed Mar 31 13:29:12 2021 +0000
- Revision:
- 7:1cced6852c01
- Parent:
- 6:f8cb706c480c
ZZZZZZ; Z; Z; ZZ; Z; ; Z; Z; Z; Z; Z; Z;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lauric | 7:1cced6852c01 | 1 | #include "mbed.h" //Définition Mbde |
lauric | 7:1cced6852c01 | 2 | #include "C12832.h" //Librairie du LCD |
dreschpe | 0:f6a57b843f79 | 3 | |
lauric | 7:1cced6852c01 | 4 | //InterruptIn fire_event(D4); |
lauric | 7:1cced6852c01 | 5 | DigitalIn fire(D4); |
lauric | 7:1cced6852c01 | 6 | Timer timer; |
lauric | 7:1cced6852c01 | 7 | C12832 lcd(D11, D13, D12, D7, D10); //Broches pour LCD définies par la librairie C12832 |
lauric | 7:1cced6852c01 | 8 | |
lauric | 7:1cced6852c01 | 9 | int etat = 0; |
lauric | 7:1cced6852c01 | 10 | int last_time, last_time2; |
lauric | 7:1cced6852c01 | 11 | int elapsed_time, elapsed_time2; |
lauric | 7:1cced6852c01 | 12 | int last_state; |
lauric | 7:1cced6852c01 | 13 | |
lauric | 7:1cced6852c01 | 14 | void changerEtat(void); |
dreschpe | 1:1c6a9eaf55b5 | 15 | |
dreschpe | 0:f6a57b843f79 | 16 | int main() |
dreschpe | 0:f6a57b843f79 | 17 | { |
chris | 2:a87e255a8f3a | 18 | lcd.cls(); |
lauric | 7:1cced6852c01 | 19 | lcd.locate(20,20); |
lauric | 7:1cced6852c01 | 20 | |
lauric | 7:1cced6852c01 | 21 | //fire_event.rise(&changerEtat); |
lauric | 7:1cced6852c01 | 22 | timer.start(); |
lauric | 7:1cced6852c01 | 23 | |
lauric | 7:1cced6852c01 | 24 | while(true) { |
dreschpe | 0:f6a57b843f79 | 25 | |
lauric | 7:1cced6852c01 | 26 | int etat_fire = fire.read(); |
lauric | 7:1cced6852c01 | 27 | if(etat_fire > last_state) { // Front montant |
lauric | 7:1cced6852c01 | 28 | changerEtat(); |
lauric | 7:1cced6852c01 | 29 | last_time2 = timer.read(); |
lauric | 7:1cced6852c01 | 30 | } else if(last_state < etat_fire) { |
lauric | 7:1cced6852c01 | 31 | elapsed_time2 = timer.read() - last_time2; |
lauric | 7:1cced6852c01 | 32 | if(elapsed_time2 >= 2) |
lauric | 7:1cced6852c01 | 33 | etat = 3; |
lauric | 7:1cced6852c01 | 34 | } |
lauric | 7:1cced6852c01 | 35 | |
lauric | 7:1cced6852c01 | 36 | last_state = etat_fire; |
lauric | 7:1cced6852c01 | 37 | |
lauric | 7:1cced6852c01 | 38 | lcd.locate(0, 0); |
lauric | 7:1cced6852c01 | 39 | lcd.printf("ETAT: %d \nDernier Appui: %d", etat, elapsed_time); |
lauric | 7:1cced6852c01 | 40 | lcd.locate(0, 20); |
lauric | 7:1cced6852c01 | 41 | lcd.printf("Temps appuye: %d", elapsed_time2); |
lauric | 7:1cced6852c01 | 42 | |
lauric | 7:1cced6852c01 | 43 | wait(0.1); |
lauric | 7:1cced6852c01 | 44 | lcd.cls(); |
dreschpe | 0:f6a57b843f79 | 45 | } |
lauric | 7:1cced6852c01 | 46 | |
dreschpe | 0:f6a57b843f79 | 47 | } |
lauric | 7:1cced6852c01 | 48 | |
lauric | 7:1cced6852c01 | 49 | void changerEtat(void) |
lauric | 7:1cced6852c01 | 50 | { |
lauric | 7:1cced6852c01 | 51 | elapsed_time = timer.read() - last_time; |
lauric | 7:1cced6852c01 | 52 | last_time = timer.read(); |
lauric | 7:1cced6852c01 | 53 | etat = etat == 1 ? 2 : 1; |
lauric | 7:1cced6852c01 | 54 | } |