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-rtos mbed mlcd_32pt
testLab6.cpp
00001 // Print messages when the AnalogIn is greater than 50% 00002 00003 #include "mbed.h" 00004 #include "mlcd_32pt.h" //Librairie pour l'écran LCD 00005 #include "Serial.h" //Librairie pour la communication série 00006 #include "rtos.h" 00007 00008 #define ACK 0x06 00009 #define NAK 0x15 00010 #define ON 1 00011 #define OFF 0 00012 #define DEBUT_LIGNE 0 00013 #define BLANC 0xFFFF 00014 #define WIDTH 1 00015 #define HEIGHT 1 00016 #define LIGNE_SUIV 15 00017 00018 00019 AnalogIn ir(p19); //Initialisation de la pin qui reçoit la valeur du capteur infra-rouge 00020 DigitalOut myled(LED4); //Sert surtout au dépannage 00021 DigitalOut myled2(LED2); //Sert surtout au dépannage 00022 DigitalOut myled3(LED3); 00023 Serial terminal (USBTX,USBRX); //pour envoyer au port de communication 00024 00025 int lignes = 0; 00026 bool couleur; 00027 Mutex flag; 00028 unsigned char message[50]; 00029 00030 typedef struct { 00031 float gris; 00032 00033 } mail_t; 00034 00035 Mail<mail_t, 16> mail_box; 00036 00037 void lectureCapteur (void const *args) //Lecture du capteur infra-rouge 00038 { 00039 while(true) { 00040 if(ir < .6) { 00041 couleur = false; 00042 sprintf((char*)message,"c'est noir! (%f)\n \r", ir.read()); 00043 printf((char*)message); 00044 myled = 1; 00045 Thread::wait(500); 00046 myled = 0; 00047 Thread::wait(500); 00048 } else { 00049 couleur = true; 00050 sprintf((char*)message,"c'est blanc! (%f)\n \r", ir.read()); 00051 printf((char*)message); 00052 myled2 = 1; 00053 Thread::wait(500); 00054 myled2 = 0; 00055 Thread::wait(500); 00056 } 00057 00058 } 00059 } 00060 00061 void envoiMessage (void const *args) //Envoi du message sur l'écran avec le Mailbox 00062 { 00063 uint32_t i = 0; 00064 00065 while(1) { 00066 00067 i++; // fake data update 00068 mail_t *mail = mail_box.alloc(); 00069 mail->gris = i; 00070 mail_box.put(mail); 00071 00072 drawString(DEBUT_LIGNE, lignes, FONT_8_12, BLANC, WIDTH, HEIGHT, message); 00073 lignes += LIGNE_SUIV; 00074 00075 if (lignes >= 225) { 00076 copier_coller(); 00077 00078 lignes -= LIGNE_SUIV; 00079 } 00080 } ; 00081 } 00082 00083 /*void resetEcran (void const *args) 00084 { 00085 if (double_clic()) { 00086 flag.lock(); 00087 sprintf((char*)message,"Reset de l'ecran"); 00088 drawString(DEBUT_LIGNE, lignes, FONT_8_12, NOIR, WIDTH, HEIGHT, message); 00089 lignes = 0; 00090 } 00091 00092 } 00093 */ 00094 00095 int main() 00096 { 00097 int retour = 0; 00098 int bckground = 0; 00099 00100 // Initialisation de l'écran 00101 00102 init_lcd(); 00103 bckground = rgb(213,44,180); 00104 retour = setbgColor(bckground); 00105 00106 if (retour == NAK) { 00107 myled3 = ON; 00108 } else { 00109 sprintf((char*)message,"Lecture du capteur\n\r"); 00110 printf("%s", (char*)message); 00111 drawString(DEBUT_LIGNE, lignes, FONT_8_12, BLANC, WIDTH, HEIGHT, message); 00112 lignes += LIGNE_SUIV; 00113 } 00114 00115 00116 //boucle avec les threads 00117 00118 Thread thread(lectureCapteur); 00119 Thread thread1(envoiMessage); 00120 //Thread thread2(resetEcran); 00121 while(true) { 00122 osEvent evt = mail_box.get(); 00123 if (evt.status == osEventMail) { 00124 mail_t *mail = (mail_t*)evt.value.p; 00125 printf("Valeur du gris", mail->gris); 00126 00127 mail_box.free(mail); 00128 }; 00129 00130 00131 00132 } 00133 }
Generated on Mon Jul 25 2022 12:33:05 by
1.7.2