final lab 6, écran lcd

Dependencies:   mbed-rtos mbed mlcd_32pt

Committer:
annicksenecal
Date:
Fri Dec 06 20:06:30 2013 +0000
Revision:
2:dfd0d133d964
Parent:
1:bbb636a6ce10
Child:
3:e3681694d955
thread transmission s?rie + lecture capteur fonctionne

Who changed what in which revision?

UserRevisionLine numberNew contents of line
annicksenecal 0:c44fd2014f2f 1 // Print messages when the AnalogIn is greater than 50%
annicksenecal 0:c44fd2014f2f 2
annicksenecal 0:c44fd2014f2f 3 #include "mbed.h"
annicksenecal 0:c44fd2014f2f 4 #include "mlcd_32pt.h" //Librairie pour l'écran LCD
annicksenecal 0:c44fd2014f2f 5 #include "Serial.h" //Librairie pour la communication série
annicksenecal 1:bbb636a6ce10 6 #include "rtos.h"
annicksenecal 0:c44fd2014f2f 7
annicksenecal 0:c44fd2014f2f 8
annicksenecal 0:c44fd2014f2f 9 AnalogIn ir(p19); //Initialisation de la pin qui reçoit la valeur du capteur infra-rouge
annicksenecal 0:c44fd2014f2f 10 DigitalOut myled(LED4); //Sert surtout au dépannage
annicksenecal 0:c44fd2014f2f 11 DigitalOut myled2(LED2); //Sert surtout au dépannage
annicksenecal 1:bbb636a6ce10 12 Serial terminal (USBTX,USBRX); //pour envoyer au port de communication
annicksenecal 0:c44fd2014f2f 13
annicksenecal 1:bbb636a6ce10 14 bool couleur;
annicksenecal 0:c44fd2014f2f 15
annicksenecal 1:bbb636a6ce10 16 void lectureCapteur (void const *args)
annicksenecal 1:bbb636a6ce10 17 {
annicksenecal 1:bbb636a6ce10 18 while(true)
annicksenecal 1:bbb636a6ce10 19 {
annicksenecal 1:bbb636a6ce10 20 if(ir < .6)
annicksenecal 1:bbb636a6ce10 21 {
annicksenecal 1:bbb636a6ce10 22 couleur = false;
annicksenecal 2:dfd0d133d964 23
annicksenecal 1:bbb636a6ce10 24 }
annicksenecal 1:bbb636a6ce10 25 else
annicksenecal 1:bbb636a6ce10 26 {
annicksenecal 1:bbb636a6ce10 27 couleur = true;
annicksenecal 2:dfd0d133d964 28
annicksenecal 1:bbb636a6ce10 29 }
annicksenecal 2:dfd0d133d964 30 Thread::wait(1000);
annicksenecal 1:bbb636a6ce10 31 }
annicksenecal 1:bbb636a6ce10 32 }
annicksenecal 0:c44fd2014f2f 33
annicksenecal 1:bbb636a6ce10 34 void envoiMessage (void const *args)
annicksenecal 1:bbb636a6ce10 35 {
annicksenecal 0:c44fd2014f2f 36
annicksenecal 1:bbb636a6ce10 37 while(1)
annicksenecal 1:bbb636a6ce10 38 {
annicksenecal 1:bbb636a6ce10 39 if (couleur == false)
annicksenecal 1:bbb636a6ce10 40 {
annicksenecal 2:dfd0d133d964 41 printf("c'est noir! (%f)\n \r", ir.read());
annicksenecal 1:bbb636a6ce10 42 myled = 1;
annicksenecal 2:dfd0d133d964 43 Thread::wait(500);
annicksenecal 1:bbb636a6ce10 44 myled = 0;
annicksenecal 2:dfd0d133d964 45 Thread::wait(500);
annicksenecal 1:bbb636a6ce10 46 }
annicksenecal 1:bbb636a6ce10 47 else
annicksenecal 1:bbb636a6ce10 48 {
annicksenecal 2:dfd0d133d964 49 printf("c'est blanc! (%f)\n \r", ir.read());
annicksenecal 1:bbb636a6ce10 50 myled2 = 1;
annicksenecal 2:dfd0d133d964 51 Thread::wait(500);
annicksenecal 1:bbb636a6ce10 52 myled2 = 0;
annicksenecal 2:dfd0d133d964 53 Thread::wait(500);
annicksenecal 1:bbb636a6ce10 54 }
annicksenecal 1:bbb636a6ce10 55 }
annicksenecal 1:bbb636a6ce10 56 }
annicksenecal 1:bbb636a6ce10 57
annicksenecal 1:bbb636a6ce10 58 int main()
annicksenecal 1:bbb636a6ce10 59 {
annicksenecal 1:bbb636a6ce10 60
annicksenecal 1:bbb636a6ce10 61 init_com(BAUD9600);
annicksenecal 2:dfd0d133d964 62
annicksenecal 1:bbb636a6ce10 63
annicksenecal 1:bbb636a6ce10 64 Thread thread(lectureCapteur);
annicksenecal 2:dfd0d133d964 65 Thread thread1(envoiMessage);
annicksenecal 1:bbb636a6ce10 66 while(true);
annicksenecal 1:bbb636a6ce10 67
annicksenecal 1:bbb636a6ce10 68
annicksenecal 1:bbb636a6ce10 69
annicksenecal 1:bbb636a6ce10 70 }
annicksenecal 0:c44fd2014f2f 71