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
Revision 4:dc6faeb6d336, committed 2021-12-02
- Comitter:
- Giamarchi
- Date:
- Thu Dec 02 18:40:28 2021 +0000
- Parent:
- 3:eeb7bfd5f25e
- Commit message:
- TP 02 Solution
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Nov 19 17:52:44 2021 +0000
+++ b/main.cpp Thu Dec 02 18:40:28 2021 +0000
@@ -19,22 +19,61 @@
DigitalIn BP(PA_1); // Ligne PA_1
//==============================================================================
+// Déclaration des variables
+uint8_t etat; // variable de type entier non signé
+uint8_t compteur;
+
+//==============================================================================
// Début du Programme
int main() // Fonction principale
{
- BP.mode(PullUp); // Activation de la résistance interne vers le +
+ BP.mode(PullUp); // Activation de la résistance interne vers le +
+
+ etat = 0; // Initialisation de la variable
+ compteur = 0;
//==============================================================================
while(1) // Boucle Infinie
{
- if(BP == 1)
- DEL_VE = 1; // Broche à 1 (DEL allumée)
- else
- DEL_VE = 0; // Broche à 0 (DEL éteinte)
-
- /* wait_ms(100); // Temporisation de 100ms (0.1s)
- DEL_VE = 0; // Broche à 0 (DEL éteinte)
- wait_ms(900);
- */
+ wait_ms(100); // Temporisation de 100ms (0.1s)
+ compteur++; // variable représentant un multiple de 100ms
+
+ switch(etat) // Structure pour plusieurs états du système
+ {
+ case 0: // Etat "Feu Vert"
+ DEL_RO = 0;
+ DEL_VE = 1; // Actions visibles (éteindre et allumer)
+
+ if(compteur == 50 || BP == 0) // Test d'une condition
+ {
+ compteur = 0;
+ etat = 1; // Changement d'état pour la prochaine boucle
+ }
+ break;
+ case 1: // Etat "Feu Orange"
+ DEL_VE = 0;
+ DEL_OR = 1; // Actions visibles
+
+ if(compteur == 20)
+ {
+ compteur = 0;
+ etat = 2;
+ }
+ break;
+ case 2: // Etat "Feu Rouge"
+ DEL_OR = 0;
+ DEL_RO = 1; // Actions visibles
+
+ if(compteur == 30)
+ {
+ compteur = 0;
+ etat = 0;
+ }
+ break;
+ default: // En cas de plantage du programme
+ etat = 0;
+ break;
+ }
+
} // Fin du while(1)
//==============================================================================
} // Fin du Programme