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:a54463860e4e
- Parent:
- 1:95172f59262a
- Child:
- 3:c2c310607375
--- a/main.cpp Tue Jan 15 15:55:11 2019 +0000 +++ b/main.cpp Fri Dec 17 00:59:19 2021 +0000 @@ -1,145 +1,43 @@ -/*************************************/ -// 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 dec. 2021 +// TP 04 : Communication série avec le PC +// Faire varier la luminosité de la DEL par appui sur la touche 'p' ou 'm' +//============================================================================== +// Déclarations des ressources #include "mbed.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); - -DigitalIn BTN3(PC_6); -DigitalIn BTN4(PC_5); - -//DigitalOut BZ(PC_7); +//============================================================================== +// Déclaration des broches +PwmOut DEL(PA_11); // Ligne PA_11 en mode PWM +Serial pc(USBTX, USBRX); // Dialogue Série port USB à 9600 Baud -//uint8_t L[8] = {L0, L1, L2, L3, L4, L5, L6, L7}; - -void set_8Dels(uint8_t position) -{ - L0 = position & 0x01; - L1 = position & 0x02; - L2 = position & 0x04; - L3 = position & 0x08; - L4 = position & 0x10; - L5 = position & 0x20; - L6 = position & 0x40; - L7 = position & 0x80; -} +//============================================================================== +// Déclaration des variables +int8_t variable; // variable de type entier (0 à 255) +char c; // variable de type caractère -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 - - 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; - - if(!BTN4) - { - wait(0.2); - etat_BTN4 = 1; - } - return etat_BTN4; -} -/***********************************************/ -int main() +//============================================================================== +// Début du Programme +int main() // Fonction principale { + pc.printf("\r\nFabLab TP 4\r\n\n"); // Affiche un message sur le PC + pc.printf("p -> pour augmenter la luminosite\r\n"); + pc.printf("m -> pour diminuer la luminosite\r\n"); + + variable = 0; + DEL.period_ms(20); // Définit la période du signal +//============================================================================== +// 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 + DEL.pulsewidth_ms(variable); // Définit la durée du temps haut (en ms) - 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); - } -/***********************************************/ } // Fin du while(1) -} // Fin du main() -/***********************************************/ \ No newline at end of file +//============================================================================== +} // Fin du Programme +//============================================================================== \ No newline at end of file