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.
Diff: main.cpp
- Revision:
- 1:331b2ab21c68
- Parent:
- 0:53ef7654cca2
- Child:
- 2:2992ec32f76f
--- a/main.cpp Mon Apr 26 14:13:39 2021 +0000
+++ b/main.cpp Mon Apr 26 14:28:00 2021 +0000
@@ -1,24 +1,16 @@
-// EXERCICE N°1 : CHANGEMENT DE COULEUR DE LA LED A INTERVALE REGULIER. (Utilisation d'un bus "leds")
+// EXERCICE N°2 : CHANGEMENT DE COULEUR DE LA LED EN FONCTION DE LA POSITION DU POTENTIOMETRE.
// Diagrame :
-// START
-// |<--|
-// VERT |
-// | |
-// 0.4s |
-// | |
-// JAUNE |
-// | |
-// 0.4s |
-// | |
-// ROUGE |
-// | |
-// 0.4s |
-// | |
-// NOIR |
-// | |
-// 0.4s |
-// |---|
-
+// START
+// |<-----------------------|
+// valA2 = lire A2 |
+// | |
+// |- if valA2<0.15 o-| |
+// | | |
+// VERT |- if valA2<0.3 o-| |
+// | | | |
+// | BLEU ROUGE |
+// | | | |
+// ----------------------------------|
#include "mbed.h"
enum COULEUR{
@@ -33,17 +25,29 @@
};
BusOut leds(LED3,LED2,LED1);
+AnalogIn pot(A2);
int main() {
+ // Déclaration des variables local.
+ float valA2;
while(true)
{
- leds.write(VERT);
- wait(0.4);
- leds.write(JAUNE);
- wait(0.4);
- leds.write(ROUGE);
- wait(0.4);
- leds.write(NOIR);
- wait(0.4);
+ // Lecture des entrées.
+ valA2 = pot;
+
+ // Algorithme.
+ if(valA2<0.15) {
+ leds.write(VERT);
+ }
+ else {
+ if(valA2<0.3) {
+ leds.write(BLEU);
+ }
+ else {
+ leds.write(ROUGE);
+ }
+ }
+ // Fin algo.
+
}
-}
+}
\ No newline at end of file