final lab 6, écran lcd

Dependencies:   mbed-rtos mbed mlcd_32pt

Committer:
annicksenecal
Date:
Mon Dec 09 20:46:01 2013 +0000
Revision:
3:e3681694d955
Parent:
2:dfd0d133d964
Child:
4:cb1507dc9dd9
reste a terminer copier coller et double clic

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 3:e3681694d955 8 #define ACK 0x06
annicksenecal 3:e3681694d955 9 #define NAK 0x15
annicksenecal 3:e3681694d955 10 #define ON 1
annicksenecal 3:e3681694d955 11 #define OFF 0
annicksenecal 3:e3681694d955 12 #define DEBUT_LIGNE 0
annicksenecal 3:e3681694d955 13 #define NOIR 0xFFFF
annicksenecal 3:e3681694d955 14 #define WIDTH 1
annicksenecal 3:e3681694d955 15 #define HEIGHT 1
annicksenecal 3:e3681694d955 16 #define LIGNE_SUIV 15
annicksenecal 3:e3681694d955 17
annicksenecal 0:c44fd2014f2f 18
annicksenecal 0:c44fd2014f2f 19 AnalogIn ir(p19); //Initialisation de la pin qui reçoit la valeur du capteur infra-rouge
annicksenecal 0:c44fd2014f2f 20 DigitalOut myled(LED4); //Sert surtout au dépannage
annicksenecal 0:c44fd2014f2f 21 DigitalOut myled2(LED2); //Sert surtout au dépannage
annicksenecal 3:e3681694d955 22 DigitalOut myled3(LED3);
annicksenecal 1:bbb636a6ce10 23 Serial terminal (USBTX,USBRX); //pour envoyer au port de communication
annicksenecal 0:c44fd2014f2f 24
annicksenecal 3:e3681694d955 25 int lignes = 0;
annicksenecal 1:bbb636a6ce10 26 bool couleur;
annicksenecal 3:e3681694d955 27 Mutex flag;
annicksenecal 3:e3681694d955 28 unsigned char message[50];
annicksenecal 0:c44fd2014f2f 29
annicksenecal 1:bbb636a6ce10 30 void lectureCapteur (void const *args)
annicksenecal 1:bbb636a6ce10 31 {
annicksenecal 1:bbb636a6ce10 32 while(true)
annicksenecal 1:bbb636a6ce10 33 {
annicksenecal 1:bbb636a6ce10 34 if(ir < .6)
annicksenecal 1:bbb636a6ce10 35 {
annicksenecal 1:bbb636a6ce10 36 couleur = false;
annicksenecal 3:e3681694d955 37 sprintf((char*)message,"c'est noir! (%f)\n \r", ir.read());
annicksenecal 3:e3681694d955 38 printf((char*)message);
annicksenecal 1:bbb636a6ce10 39 myled = 1;
annicksenecal 2:dfd0d133d964 40 Thread::wait(500);
annicksenecal 1:bbb636a6ce10 41 myled = 0;
annicksenecal 2:dfd0d133d964 42 Thread::wait(500);
annicksenecal 1:bbb636a6ce10 43 }
annicksenecal 1:bbb636a6ce10 44 else
annicksenecal 1:bbb636a6ce10 45 {
annicksenecal 3:e3681694d955 46 couleur = true;
annicksenecal 3:e3681694d955 47 sprintf((char*)message,"c'est blanc! (%f)\n \r", ir.read());
annicksenecal 3:e3681694d955 48 printf((char*)message);
annicksenecal 1:bbb636a6ce10 49 myled2 = 1;
annicksenecal 2:dfd0d133d964 50 Thread::wait(500);
annicksenecal 1:bbb636a6ce10 51 myled2 = 0;
annicksenecal 3:e3681694d955 52 Thread::wait(500);
annicksenecal 3:e3681694d955 53 }
annicksenecal 3:e3681694d955 54
annicksenecal 3:e3681694d955 55 }
annicksenecal 1:bbb636a6ce10 56 }
annicksenecal 1:bbb636a6ce10 57
annicksenecal 3:e3681694d955 58 void envoiMessage (void const *args)
annicksenecal 3:e3681694d955 59 {
annicksenecal 3:e3681694d955 60 while(1)
annicksenecal 3:e3681694d955 61 {
annicksenecal 3:e3681694d955 62 if (couleur == false)
annicksenecal 3:e3681694d955 63 {
annicksenecal 3:e3681694d955 64 drawString(DEBUT_LIGNE, lignes, FONT_8_12, NOIR, WIDTH, HEIGHT, message);
annicksenecal 3:e3681694d955 65 lignes += LIGNE_SUIV;
annicksenecal 3:e3681694d955 66 Thread::wait(1000);
annicksenecal 3:e3681694d955 67 }
annicksenecal 3:e3681694d955 68 else
annicksenecal 3:e3681694d955 69 {
annicksenecal 3:e3681694d955 70 drawString(DEBUT_LIGNE, lignes, FONT_8_12, NOIR, WIDTH, HEIGHT, message);
annicksenecal 3:e3681694d955 71 lignes += LIGNE_SUIV;
annicksenecal 3:e3681694d955 72 Thread::wait(1000);
annicksenecal 3:e3681694d955 73 }
annicksenecal 3:e3681694d955 74
annicksenecal 3:e3681694d955 75 if (lignes >= 225)
annicksenecal 3:e3681694d955 76 {
annicksenecal 3:e3681694d955 77 copier_coller();
annicksenecal 3:e3681694d955 78
annicksenecal 3:e3681694d955 79 lignes -= LIGNE_SUIV;
annicksenecal 3:e3681694d955 80 }
annicksenecal 3:e3681694d955 81 }
annicksenecal 3:e3681694d955 82 }
annicksenecal 3:e3681694d955 83
annicksenecal 3:e3681694d955 84 /*void resetEcran (void const *args)
annicksenecal 3:e3681694d955 85 {
annicksenecal 3:e3681694d955 86 if (double_clic()) {
annicksenecal 3:e3681694d955 87 flag.lock();
annicksenecal 3:e3681694d955 88 sprintf((char*)message,"Reset de l'ecran");
annicksenecal 3:e3681694d955 89 drawString(DEBUT_LIGNE, lignes, FONT_8_12, NOIR, WIDTH, HEIGHT, message);
annicksenecal 3:e3681694d955 90 lignes = 0;
annicksenecal 3:e3681694d955 91 }
annicksenecal 3:e3681694d955 92
annicksenecal 3:e3681694d955 93 }
annicksenecal 3:e3681694d955 94 */
annicksenecal 3:e3681694d955 95
annicksenecal 1:bbb636a6ce10 96 int main()
annicksenecal 1:bbb636a6ce10 97 {
annicksenecal 3:e3681694d955 98 int retour = 0;
annicksenecal 3:e3681694d955 99 int bckground = 0;
annicksenecal 3:e3681694d955 100
annicksenecal 3:e3681694d955 101 init_lcd();
annicksenecal 3:e3681694d955 102 //bckground = rgb(0,255,0);//213,44,180
annicksenecal 3:e3681694d955 103 //retour = setbgColor(bckground);
annicksenecal 1:bbb636a6ce10 104
annicksenecal 3:e3681694d955 105 if (retour == NAK)
annicksenecal 3:e3681694d955 106 {
annicksenecal 3:e3681694d955 107 myled3 = ON;
annicksenecal 3:e3681694d955 108 }
annicksenecal 3:e3681694d955 109 else
annicksenecal 3:e3681694d955 110 {
annicksenecal 3:e3681694d955 111 sprintf((char*)message,"Lecture du capteur\n\r");
annicksenecal 3:e3681694d955 112 printf("%s", (char*)message);
annicksenecal 3:e3681694d955 113 drawString(DEBUT_LIGNE, lignes, FONT_8_12, NOIR, WIDTH, HEIGHT, message);
annicksenecal 3:e3681694d955 114 lignes += LIGNE_SUIV;
annicksenecal 3:e3681694d955 115 }
annicksenecal 3:e3681694d955 116
annicksenecal 3:e3681694d955 117
annicksenecal 1:bbb636a6ce10 118
annicksenecal 1:bbb636a6ce10 119 Thread thread(lectureCapteur);
annicksenecal 3:e3681694d955 120 Thread thread1(envoiMessage);
annicksenecal 3:e3681694d955 121 //Thread thread2(resetEcran);
annicksenecal 1:bbb636a6ce10 122 while(true);
annicksenecal 1:bbb636a6ce10 123
annicksenecal 1:bbb636a6ce10 124
annicksenecal 1:bbb636a6ce10 125
annicksenecal 1:bbb636a6ce10 126 }
annicksenecal 0:c44fd2014f2f 127