Example program that uses the color LED of the mbed application shield with ST Nucleo board
Revision 3:efff8b39e765, committed 2020-11-10
- Comitter:
- pathae
- Date:
- Tue Nov 10 14:10:47 2020 +0000
- Parent:
- 2:0bc5af6c7ebf
- Commit message:
- lcd
Changed in this revision
| TextLCD.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Tue Nov 10 14:10:47 2020 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/TextLCD/#308d188a2d3a
--- a/main.cpp Wed Aug 17 09:58:13 2016 +0000
+++ b/main.cpp Tue Nov 10 14:10:47 2020 +0000
@@ -1,17 +1,66 @@
#include "mbed.h"
+#include "TextLCD.h"
+#define btnRIGHT 0
+#define btnUP 1
+#define btnDOWN 2
+#define btnLEFT 3
+#define btnSELECT 4
+#define btnNONE 5
-DigitalOut red(LED1);
-DigitalOut blue(LED2);
-DigitalOut green(LED3);
-int i;
+Serial pc (SERIAL_TX, SERIAL_RX);
+DigitalOut myled(LED1);
+AnalogIn analog_value(A0);
+TextLCD lcd(D8,D9,D4,D5,D6,D7);
-int main() {
- while(1) {
- for (i=1; i<7; i++) {
- red = i & 1;
- blue = i & 2;
- green = i & 4;
- wait(0.2);
- }
+ float meas;
+int read_LCD_buttons(){
+ meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
+ meas = meas * 3300; // Change the value to be in the 0 to 3300 range
+ if (meas > 3300) return btnNONE;
+ if (meas < 50) return btnRIGHT;
+ if ((meas > 900)&&( meas < 1300)) return btnUP;
+ if ((meas > 1800)&&( meas < 2200)) return btnDOWN;
+ if ((meas > 2800)&&( meas < 3200)) return btnLEFT;
+ return btnNONE;
}
+
+int main()
+{
+ int lcd_key;
+ lcd.printf("NUCLEO F103RB");
+ while(1)
+ {
+ wait_ms(200);
+ lcd_key = read_LCD_buttons(); // read the buttons
+ switch (lcd_key){ // depending on which button was pushed, we perform an action
+ case btnRIGHT:{ // push button "RIGHT" and show the word on the screen
+ lcd.locate(4,1);
+ lcd.printf("RIGHT ");
+ break;}
+ case btnLEFT:{
+ lcd.locate(4,1);
+ lcd.printf("LEFT "); // push button "LEFT" and show the word on the screen
+ break;}
+ case btnUP:{
+ lcd.locate(4,1);
+ lcd.printf("UP "); // push button "UP" and show the word on the screen
+ break;}
+ case btnDOWN:{
+ lcd.locate(4,1);
+ lcd.printf("DOWN "); // push button "DOWN" and show the word on the screen
+ break;}
+ case btnSELECT:{
+ lcd.locate(4,1);
+ lcd.printf("SELECT"); // push button "SELECT" and show the word on the screen
+ break;}
+ case btnNONE:{
+ lcd.locate(4,1);
+ lcd.printf("NONE "); // No action will show "None" on the screen
+ break;}
+ }
}
+}
+
+
+
+
\ No newline at end of file