menu projet

Dependencies:   SDFileSystem SPI_TFT_ILI9341 TFT_fonts mbed

Fork of TFT_banggood by Peter Drescher

Files at this revision

API Documentation at this revision

Comitter:
JoeJoe
Date:
Thu May 28 06:42:26 2015 +0000
Parent:
0:7c3b9bfd6ead
Child:
2:da6faa24e5b2
Commit message:
thanks to TFT_banggood

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Jan 26 20:55:50 2014 +0000
+++ b/main.cpp	Thu May 28 06:42:26 2015 +0000
@@ -1,8 +1,3 @@
-// example to test the TFT Display from banggood.com
-// Thanks to the GraphicsDisplay and TextDisplay classes
-// test.bmp has to be on the mbed file system
-// and on the sd-card
-
 #include "stdio.h"
 #include "mbed.h"
 #include "SPI_TFT_ILI9341.h"
@@ -12,127 +7,180 @@
 #include "Arial28x28.h"
 #include "font_big.h"
 #include "SDFileSystem.h"
- 
-// the SD-connector is connected to SPI pin 11-13 
-SDFileSystem sd(p11, p12, p13, p14, "sd"); // mosi,miso,sck,cs
 
-LocalFileSystem local("local");
-
-extern unsigned char p1[];  // the mbed logo graphic
-
-// the display has a backlight switch on board 
-DigitalOut LCD_LED(p21);       
-
-// the TFT is connected to SPI pin 5-7
-SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc
+InterruptIn BPlus(p21);
+InterruptIn BMoins(p22);    // Déclaration des Boutons poussoirs
+InterruptIn BValide(p23);
 
-int main()
-{
-    int i;
-    LCD_LED = 1;            // backlite on
-   
-    TFT.claim(stdout);        // send stdout to the TFT display
-    TFT.set_orientation(1);
-    TFT.background(Black);    // set background to black
-    TFT.foreground(White);    // set chars to white
-    TFT.cls();                // clear the screen
+char PosMenu;               // Déclaration des menus
+bool MenuPrincipal;
+bool ecrire;
+Ticker heure;
+int flip = 0;
 
-    //first show the 4 directions
-    TFT.set_orientation(0);
-    TFT.background(Black);
-    TFT.cls();
+// Pin de connection de l'écran TFT
+SPI_TFT_ILI9341 TFT(p5, p6, p7, p25, p26, p27,"TFT"); //mosi,miso,sclk,cs,reset,dc
 
-    TFT.set_font((unsigned char*) Arial12x12);
-    TFT.locate(0,0);
-    printf("  Hello Mbed 0");
-    TFT.set_orientation(1);
-    TFT.locate(0,0);
-    printf("  Hello Mbed 1");
-    TFT.set_orientation(2);
-    TFT.locate(0,0);
-    printf("  Hello Mbed 2");
+void attime()
+{
+    flip = !flip;
+}
+void trigger1()     //Bouton poussoir de gauche
+{
+    ecrire=0;
+    if(MenuPrincipal==0) {
+        if(PosMenu>0) {
+            PosMenu=PosMenu-1;
+            wait_ms(50);
+        }
+    }
+}
+void trigger2()     //Bouton poussoir du milieu
+{
+    ecrire=0;
+    if(MenuPrincipal==0) {
+        if(PosMenu<=1) {
+            PosMenu=PosMenu+1;
+            wait_ms(50);
+        }
+    }
+}
+void trigger3()     //Bouton poussoir de droite
+{
+    ecrire=0;
+    if(MenuPrincipal==0) {
+        MenuPrincipal=1;
+    } else {
+        MenuPrincipal=0;
+        wait_ms(50);
+    }
+}
+int main ()
+{
+    heure.attach(&attime, 10);
+    MenuPrincipal=0;
+    PosMenu=0;
+    BPlus.rise(&trigger1);
+    BMoins.rise(&trigger2);
+    BValide.rise(&trigger3);
+    set_time(456771);
+    TFT.claim(stdout);        // send stdout to the TFT display
     TFT.set_orientation(3);
-    TFT.locate(0,0);
-    printf("  Hello Mbed 3");
-    TFT.set_orientation(1);
-    TFT.set_font((unsigned char*) Arial24x23);
-    TFT.locate(50,100);
-    TFT.printf("TFT orientation");
-
-    wait(5);        // wait two seconds
+    TFT.background(White);    // Applique le fond de l'écran en blanc
+    TFT.foreground(Black);    // Applique la police de caractère en noir
+    TFT.cls();                // Réinitialise l'écran
+    TFT.set_font((unsigned char*) Neu42x35);
+    TFT.locate(12,1);
+    TFT.printf("MENU");
+    TFT.rect(5,40,826,85,Black);        // Rectangles
+    TFT.rect(5,90,826,135,Black);
+    TFT.rect(5,140,826,185,Black);
+    TFT.rect(5,190,826,235,Black);
+    while(1) {
 
-    // draw some graphics
-    TFT.cls();
-    TFT.set_font((unsigned char*) Arial24x23);
-    TFT.locate(100,100);
-    TFT.printf("Graphic");
 
-    TFT.line(0,0,100,0,Green);
-    TFT.line(0,0,0,200,Green);
-    TFT.line(0,0,100,200,Green);
-
-    TFT.rect(100,50,150,100,Red);
-    TFT.fillrect(180,25,220,70,Blue);
+        if(flip == 0) {
+            TFT.set_font((unsigned char*) Arial28x28);
+            TFT.locate(220,10);
+            time_t heure=time(NULL);
+            char buffer[32];
+            strftime(buffer,32,"%Hh%M",localtime(&heure));
+            TFT.printf("%s",buffer);
 
-    TFT.circle(80,150,33,White);
-    TFT.fillcircle(160,190,20,Yellow);
-
-    double s;
-
-    for (i=0; i<320; i++) {
-        s =20 * sin((long double) i / 10 );
-        TFT.pixel(i,100 + (int)s ,Red);
-    }
-
- 
-    wait(5);        // wait two seconds
-
-    // bigger text
-    TFT.foreground(White);
-    TFT.background(Blue);
-    TFT.cls();
-    TFT.set_font((unsigned char*) Arial24x23);
-    TFT.locate(0,0);
-    TFT.printf("Different Fonts :");
+        }
+        TFT.set_font((unsigned char*) Neu42x35);
+        if(ecrire==0) {
+            if(MenuPrincipal==0) {
+                if(PosMenu==0) {             //Sélection sur CAPTEURS
+                    TFT.foreground(Red);
+                    TFT.locate(12,45);
+                    TFT.printf("Capteurs   ");
+                    TFT.foreground(Black);
+                    TFT.locate(12,95);
+                    TFT.printf("Mesures    ");
+                    TFT.foreground(Black);
+                    TFT.locate(12,145);
+                    TFT.printf("Horloge    ");
+                    TFT.locate(12,195);
+                    TFT.printf("          ");
+                }
+                if(PosMenu==1) {            //Sélection sur MESURES
+                    TFT.foreground(Black);
+                    TFT.locate(12,45);
+                    TFT.printf("Capteurs   ");
+                    TFT.foreground(Red);
+                    TFT.locate(12,95);
+                    TFT.printf("Mesures   ");
+                    TFT.foreground(Black);
+                    TFT.locate(12,145);
+                    TFT.printf("Horloge     ");
+                    TFT.locate(12,195);
+                    TFT.printf("          ");
+                }
+                if(PosMenu==2) {            //Sélection sur HORLOGE
+                    TFT.foreground(Black);
+                    TFT.locate(12,45);
+                    TFT.printf("Capteurs   ");
+                    TFT.foreground(Black);
+                    TFT.locate(12,95);
+                    TFT.printf("Mesures    ");
+                    TFT.foreground(Red);
+                    TFT.locate(12,145);
+                    TFT.printf("Horloge     ");
+                    TFT.foreground(Black);
+                    TFT.locate(12,195);
+                    TFT.printf("          ");
+                }
+            } else {
+                if(PosMenu==0) {            //Sous menu de CAPTEURS
+                    TFT.set_font((unsigned char*) Neu42x35);
+                    TFT.foreground(Black);
+                    TFT.locate(12,45);
+                    TFT.printf("C1   ");
+                    TFT.locate(109,45);
+                    TFT.printf("C2   ");
+                    TFT.locate(220,45);
+                    TFT.printf("C3");
+                    TFT.locate(12,95);
+                    TFT.printf("C4   ");
+                    TFT.locate(109,95);
+                    TFT.printf("C5   ");
+                    TFT.locate(220,95);
+                    TFT.printf("C6");
+                    TFT.locate(12,145);
+                    TFT.printf("C7   ");
+                    TFT.locate(109,145);
+                    TFT.printf("C8   ");
+                    TFT.locate(220,145);
+                    TFT.printf("C9");
+                    TFT.locate(12,195);
+                    TFT.printf("C10");
+                }
+                if(PosMenu==1) {            //Sous menu de MESURES
+                    TFT.foreground(Black);
+                    TFT.locate(12,45);
+                    TFT.printf("Temp :   ");
+                    TFT.foreground(Black);
+                    TFT.locate(12,95);
+                    TFT.printf("Forces :    ");
+                    TFT.foreground(Black);
+                    TFT.locate(12,145);
+                    TFT.printf("         ");
+                }
+                if(PosMenu==2) {            //Sous menu d'HORLOGE
+                    TFT.foreground(Black);
+                    TFT.locate(12,45);
+                    TFT.printf("Reglages Clk");
+                    TFT.foreground(Black);
+                    TFT.locate(12,95);
+                    TFT.printf("       ");
+                    TFT.foreground(Black);
+                    TFT.locate(12,145);
+                    TFT.printf("         ");
+                }
+            }
+            ecrire=1;
+        }
 
-    TFT.set_font((unsigned char*) Neu42x35);
-    TFT.locate(10,30);
-    TFT.printf("Hello Mbed 1");
-    TFT.set_font((unsigned char*) Arial24x23);
-    TFT.locate(20,80);
-    TFT.printf("Hello Mbed 2");
-    TFT.set_font((unsigned char*) Arial12x12);
-    TFT.locate(35,120);
-    TFT.printf("Hello Mbed 3");
-    wait(5);
-
-    TFT.background(Black);
-    TFT.cls();
-    TFT.locate(10,10);
-    TFT.printf("Graphic from Flash");
-    
-    // mbed logo
-    // defined in graphics.c
-    //__align(4)
-    //unsigned char p1[18920] = {
-    //0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, ....
-    // 
-    TFT.Bitmap(90,90,172,55,p1);
-
-    wait(5);
-    TFT.cls();
-    
-    // to compare the speed of the internal file system and a SD-card
-    TFT.locate(10,10);
-    TFT.printf("Graphic from internal File System");
-    TFT.locate(10,20);
-    TFT.printf("open test.bmp");
-    int err = TFT.BMP_16(1,50,"/local/test.bmp");
-    if (err != 1) TFT.printf(" - Err: %d",err);
-    
-    TFT.locate(10,110);
-    TFT.printf("Graphic from external SD-card");
-    TFT.locate(10,120);
-    err = TFT.BMP_16(1,140,"/sd/test.bmp");
-    if (err != 1) TFT.printf(" - Err: %d",err);
-}
+    }
+}
\ No newline at end of file