Patrice HAESAERT / Mbed 2 deprecated lcd_nucleo

Dependencies:   mbed TextLCD

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "TextLCD.h"
00003 #define btnRIGHT  0
00004 #define btnUP     1
00005 #define btnDOWN   2
00006 #define btnLEFT   3
00007 #define btnSELECT 4
00008 #define btnNONE   5
00009 
00010 Serial pc (SERIAL_TX, SERIAL_RX);
00011 DigitalOut myled(LED1);
00012 AnalogIn analog_value(A0);
00013 TextLCD lcd(D8,D9,D4,D5,D6,D7);
00014 
00015  float meas;
00016 int read_LCD_buttons(){               
00017      meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00018         meas = meas * 3300; // Change the value to be in the 0 to 3300 range
00019         if (meas > 3300) return btnNONE; 
00020         if (meas < 50)   return btnRIGHT;  
00021         if ((meas > 900)&&( meas < 1300)) return btnUP; 
00022         if ((meas > 1800)&&( meas < 2200)) return btnDOWN; 
00023         if ((meas > 2800)&&( meas < 3200)) return btnLEFT; 
00024         return btnNONE;
00025     }
00026         
00027 int main()
00028 {
00029     int lcd_key;
00030     lcd.printf("NUCLEO F103RB");
00031     while(1) 
00032         {
00033          wait_ms(200);
00034          lcd_key = read_LCD_buttons();   // read the buttons
00035        switch (lcd_key){               // depending on which button was pushed, we perform an action
00036            case btnRIGHT:{             //  push button "RIGHT" and show the word on the screen
00037                 lcd.locate(4,1);
00038                 lcd.printf("RIGHT ");
00039            break;}
00040            case btnLEFT:{
00041              lcd.locate(4,1);
00042              lcd.printf("LEFT   "); //  push button "LEFT" and show the word on the screen
00043              break;}
00044           case btnUP:{
00045              lcd.locate(4,1);
00046              lcd.printf("UP    ");  //  push button "UP" and show the word on the screen
00047              break;}
00048          case btnDOWN:{
00049              lcd.locate(4,1);
00050              lcd.printf("DOWN  ");  //  push button "DOWN" and show the word on the screen
00051              break;}
00052          case btnSELECT:{
00053              lcd.locate(4,1);
00054              lcd.printf("SELECT");  //  push button "SELECT" and show the word on the screen
00055              break;}
00056         case btnNONE:{
00057              lcd.locate(4,1);
00058              lcd.printf("NONE  ");  //  No action  will show "None" on the screen
00059              break;}
00060        }
00061 }
00062 }
00063 
00064 
00065 
00066