![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Codeur2
main.cpp@0:0f28724debac, 2020-11-07 (annotated)
- Committer:
- gr66
- Date:
- Sat Nov 07 17:38:10 2020 +0000
- Revision:
- 0:0f28724debac
Codeur2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gr66 | 0:0f28724debac | 1 | /**********************************************************************/ |
gr66 | 0:0f28724debac | 2 | /* */ |
gr66 | 0:0f28724debac | 3 | /* Programme de test de l'extension codeur */ |
gr66 | 0:0f28724debac | 4 | /* pour la carte F446RE */ |
gr66 | 0:0f28724debac | 5 | /* */ |
gr66 | 0:0f28724debac | 6 | /* Sylvain CASTANET - Octobre 2019 */ |
gr66 | 0:0f28724debac | 7 | /* */ |
gr66 | 0:0f28724debac | 8 | /* ------ */ |
gr66 | 0:0f28724debac | 9 | /* */ |
gr66 | 0:0f28724debac | 10 | /* Test des différentes fonctions de la carte : */ |
gr66 | 0:0f28724debac | 11 | /* - codeur incrémental */ |
gr66 | 0:0f28724debac | 12 | /* - poussoir du codeur */ |
gr66 | 0:0f28724debac | 13 | /* - Led */ |
gr66 | 0:0f28724debac | 14 | /* */ |
gr66 | 0:0f28724debac | 15 | /**********************************************************************/ |
gr66 | 0:0f28724debac | 16 | |
gr66 | 0:0f28724debac | 17 | #include "mbed.h" |
gr66 | 0:0f28724debac | 18 | #include "C12832.h" |
gr66 | 0:0f28724debac | 19 | |
gr66 | 0:0f28724debac | 20 | // Using Arduino pin notation |
gr66 | 0:0f28724debac | 21 | C12832 lcd(D11, D13, D12, D7, D10); |
gr66 | 0:0f28724debac | 22 | |
gr66 | 0:0f28724debac | 23 | // Entrées numériques |
gr66 | 0:0f28724debac | 24 | //InterruptIn CodeurA(PA_15,PullUp); // Mode PullUp |
gr66 | 0:0f28724debac | 25 | //DigitalIn CodeurB(PA_14,PullUp); // Mode PullUp |
gr66 | 0:0f28724debac | 26 | InterruptIn BP(PC_12); // Mode PullUp |
gr66 | 0:0f28724debac | 27 | InterruptIn CodeurA(PA_15); //PB_7 |
gr66 | 0:0f28724debac | 28 | InterruptIn CodeurB(PB_7); //PA_15 |
gr66 | 0:0f28724debac | 29 | //InterruptIn BP(PC_12); |
gr66 | 0:0f28724debac | 30 | Serial pc(SERIAL_TX, SERIAL_RX); |
gr66 | 0:0f28724debac | 31 | |
gr66 | 0:0f28724debac | 32 | |
gr66 | 0:0f28724debac | 33 | // Leds |
gr66 | 0:0f28724debac | 34 | DigitalOut Led(PC_10); |
gr66 | 0:0f28724debac | 35 | |
gr66 | 0:0f28724debac | 36 | int counter=0; |
gr66 | 0:0f28724debac | 37 | |
gr66 | 0:0f28724debac | 38 | |
gr66 | 0:0f28724debac | 39 | // Sortie de test |
gr66 | 0:0f28724debac | 40 | |
gr66 | 0:0f28724debac | 41 | |
gr66 | 0:0f28724debac | 42 | void ca(){ |
gr66 | 0:0f28724debac | 43 | if(CodeurB==0)counter++; |
gr66 | 0:0f28724debac | 44 | } |
gr66 | 0:0f28724debac | 45 | void cb(){ |
gr66 | 0:0f28724debac | 46 | if(CodeurA==0)counter--; |
gr66 | 0:0f28724debac | 47 | } |
gr66 | 0:0f28724debac | 48 | |
gr66 | 0:0f28724debac | 49 | void clignot(){ |
gr66 | 0:0f28724debac | 50 | Led = !Led; |
gr66 | 0:0f28724debac | 51 | counter=0; |
gr66 | 0:0f28724debac | 52 | } |
gr66 | 0:0f28724debac | 53 | |
gr66 | 0:0f28724debac | 54 | int main() |
gr66 | 0:0f28724debac | 55 | { |
gr66 | 0:0f28724debac | 56 | lcd.cls(); // Clear screen |
gr66 | 0:0f28724debac | 57 | lcd.locate(0,3); // 1ere ligne |
gr66 | 0:0f28724debac | 58 | lcd.printf("Essai du module codeur"); |
gr66 | 0:0f28724debac | 59 | BP.mode(PullUp); |
gr66 | 0:0f28724debac | 60 | CodeurA.mode(PullUp); |
gr66 | 0:0f28724debac | 61 | CodeurB.mode(PullUp); |
gr66 | 0:0f28724debac | 62 | pc.printf("Hello world \n"); |
gr66 | 0:0f28724debac | 63 | Led = 1; |
gr66 | 0:0f28724debac | 64 | CodeurA.fall(&ca); |
gr66 | 0:0f28724debac | 65 | CodeurB.fall(&cb); |
gr66 | 0:0f28724debac | 66 | BP.fall(&clignot); |
gr66 | 0:0f28724debac | 67 | |
gr66 | 0:0f28724debac | 68 | while(1) { |
gr66 | 0:0f28724debac | 69 | |
gr66 | 0:0f28724debac | 70 | pc.printf("Compteur : %d \r\n",counter); |
gr66 | 0:0f28724debac | 71 | lcd.locate(0,15); |
gr66 | 0:0f28724debac | 72 | lcd.printf("Compteur : %d ",counter); |
gr66 | 0:0f28724debac | 73 | wait_ms(100); |
gr66 | 0:0f28724debac | 74 | |
gr66 | 0:0f28724debac | 75 | |
gr66 | 0:0f28724debac | 76 | |
gr66 | 0:0f28724debac | 77 | wait(0.1); |
gr66 | 0:0f28724debac | 78 | } |
gr66 | 0:0f28724debac | 79 | } |