Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 2:c1a4641eeacf
- Parent:
- 1:95172f59262a
- Child:
- 3:c75f8eddeaf4
--- a/main.cpp Tue Jan 15 15:55:11 2019 +0000 +++ b/main.cpp Thu Feb 17 18:16:35 2022 +0000 @@ -1,145 +1,52 @@ -/*************************************/ -// YNCREA ISEN Nîmes -// CSI3 Electronique Numérique -// -// Cours : Systèmes à microcontrôleur -// Prof : Frédéric Giamarchi -// -// Date : 15 janv 2019 -// Test TP 01 : Controle de 8 Dels par 2 Boutons poussoir -/*************************************/ +//============================================================================== +// FabLab Nîmes +// Initiation à la Programmation +// Auteur : Frédéric Giamarchi + +// Date : 3 fev. 2022 +// TP : Girouette +// Encodeur optique pour girouette +// Utilisation de fonctions décrites dans un fichier séparé +//============================================================================== +// Déclarations des ressources #include "mbed.h" +#include "fonctions.h" // Appel des fonctions du fichier : fonctions.h -DigitalOut L0(PB_1); -DigitalOut L1(PB_2); -DigitalOut L2(PB_10); -DigitalOut L3(PB_11); -DigitalOut L4(PB_12); -DigitalOut L5(PB_13); -DigitalOut L6(PB_14); -DigitalOut L7(PB_15); +//============================================================================== +// Déclaration des broches +DigitalOut DEL(PA_11); // Ligne PA_11 sur la carte Nucléo +Serial pc(USBTX, USBRX); // Dialogue Série port USB à 9600 Baud + +//============================================================================== +// Déclaration des variables -DigitalIn BTN3(PC_6); -DigitalIn BTN4(PC_5); +char c; // variable de type caractère +float temp; // variable de type réel +int16_t angle; -//DigitalOut BZ(PC_7); - -//uint8_t L[8] = {L0, L1, L2, L3, L4, L5, L6, L7}; - -void set_8Dels(uint8_t position) +//============================================================================== +// Début du Programme +int main() // Fonction principale { - L0 = position & 0x01; - L1 = position & 0x02; - L2 = position & 0x04; - L3 = position & 0x08; - L4 = position & 0x10; - L5 = position & 0x20; - L6 = position & 0x40; - L7 = position & 0x80; -} - -uint8_t ptr_3 = 0; -uint8_t ptr_4 = 0; -uint8_t pointeur = 1; -uint8_t compteur = 0; -uint8_t etat_del = 0; -/***********************************************/ -// Fonction Appui_BTN3 -// Renvoie l'état actif ou relaché du bouton poussoir BTN3 -uint8_t Appui_BTN3(void) -{ -uint8_t etat_BTN3 = 0; // variable état BTN3 à 0 par défaut + Init_Fonctions(); // Exécute cette fonction - if(!BTN3) // Test appui sur BTN3 - { - wait(0.2); // tempo d'anti rebond - etat_BTN3 = 1; // variable à 1 - } - return etat_BTN3; // La fonction renvoie la valeur 0 ou 1 -} -/***********************************************/ -// Fonction Appui_BTN4 -// Renvoie l'état actif ou relaché du bouton poussoir BTN4 -uint8_t Appui_BTN4(void) -{ -uint8_t etat_BTN4 = 0; + pc.printf("\r\nFabLab TP Girouette\r\n\n"); - if(!BTN4) - { - wait(0.2); - etat_BTN4 = 1; - } - return etat_BTN4; -} -/***********************************************/ -int main() -{ +//============================================================================== +// Boucle Infinie while(1) { -/******** Question 1 ****************/ -/* - L0 = Appui_BTN3(); // Contrôle L0 par BTN3 -*/ -/******** Question 2 ****************/ -/* - if(Appui_BTN3()) - { - pointeur <<=1; // Décalage vers la gauche - if(pointeur == 0) // Test Limite gauche - pointeur = 0x80; // Blocage - set_8Dels(pointeur); // Affichage - } -*/ -/******** Question 3 ****************/ -/* - if(Appui_BTN4()) - { - pointeur >>=1; // Décalage vers la droite - if(pointeur == 0) // Test Limite droite - pointeur = 1; // Blocage - set_8Dels(pointeur); - } -*/ -/******** Question 4 ****************/ - - wait_ms(10); // Execution toutes les 10 ms - compteur++; // Incrémente un compteur temps + wait(1.0); // Toutes les secondes - if(Appui_BTN3()) - { - ptr_3++; // incrémente un pointeur - compteur = 0; // RAZ compteur temps - } -/******** Question 5 ****************/ - - if(Appui_BTN4()) - { - ptr_4++; - compteur = 0; - } -/******** Question 4 et 5 ****************/ - - if(compteur == 100) // Est-ce que cela fait 1 sec - { - if(ptr_3 != 0) // Test pointeur 3 -> Question 4 - { - // Masque OU logique avec etat_Del - // Le masque est un décalage vers la gauche d'un 1 logique - // Le nombre de décalage est défini par le pointeur - etat_del = etat_del | 1<<(ptr_3 - 1); - ptr_3 = 0; // Pointeur à 0 - } - if(ptr_4 != 0) // Test pointeur 4 -> Question 5 - // Masque ET logique avec etat_Del - // Le masque est un décalage vers la gauche d'un 1 logique - // Le nombre de décalage est défini par le pointeur - // Ensuite le résultat du masque est inversé - etat_del = etat_del & ~(1<<ptr_4 - 1); - ptr_4 = 0; - - set_8Dels(etat_del); - } -/***********************************************/ + angle = Girouette(); // Lecture de la girouette + if(angle == 0) + DEL = 1; // La girouette pointe vers le Nord + else + DEL = 0; + + pc.printf("Dir Vent : %d\n",angle); // Affiche l'angle sur Putty + } // Fin du while(1) -} // Fin du main() -/***********************************************/ \ No newline at end of file +//============================================================================== +} // Fin du Programme +//============================================================================== \ No newline at end of file