Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI BSP_DISCO_F429ZI
Revision 2:db40a2b0b177, committed 2020-05-23
- Comitter:
- matis755
- Date:
- Sat May 23 07:11:44 2020 +0000
- Parent:
- 1:36b3fd4a01fd
- Child:
- 3:15deb9bc946b
- Commit message:
- Make class Led to drive each one directly;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Keyboard.cpp Sat May 23 07:11:44 2020 +0000
@@ -0,0 +1,26 @@
+#include "Keyboard.h"
+
+Keyboard::Keyboard(unsigned char ucIdx) {
+ ucColIdx = ucIdx;
+ Init(240,320);
+}
+
+enum KeyboardState Keyboard::eRead(void) {
+ TS_StateTypeDef TS_State;
+ GetState(&TS_State);
+ if ((TS_State.TouchDetected) && (TS_State.Y > 0 ) && (TS_State.Y < 80) && (TS_State.X > (80 * ucColIdx)) && (TS_State.X < (80 * (ucColIdx + 1)))) {
+ return BUTTON_0;
+ }
+ else if ((TS_State.TouchDetected) && (TS_State.Y > 80 ) && (TS_State.Y < 160) && (TS_State.X > (80 * ucColIdx)) && (TS_State.X < (80 * (ucColIdx + 1)))) {
+ return BUTTON_1;
+ }
+ else if ((TS_State.TouchDetected) && (TS_State.Y > 160 ) && (TS_State.Y < 240) && (TS_State.X > (80 * ucColIdx)) && (TS_State.X < (80 * (ucColIdx + 1)))) {
+ return BUTTON_2;
+ }
+ else if ((TS_State.TouchDetected) && (TS_State.Y > 240 ) && (TS_State.Y < 320) && (TS_State.X > (80 * ucColIdx)) && (TS_State.X < (80 * (ucColIdx + 1)))) {
+ return BUTTON_3;
+ }
+ else{
+ return RELASED;
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Keyboard.h Sat May 23 07:11:44 2020 +0000
@@ -0,0 +1,23 @@
+#ifndef KEYBOARD_
+#define KEYBOARD
+
+#include "TS_DISCO_F429ZI.h"
+
+enum KeyboardState{
+ RELASED,
+ BUTTON_0,
+ BUTTON_1,
+ BUTTON_2,
+ BUTTON_3
+};
+
+class Keyboard : private TS_DISCO_F429ZI {
+ private:
+ unsigned char ucColIdx;
+ public:
+ Keyboard(unsigned char);
+ enum KeyboardState eRead(void);
+
+};
+
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/KeyboardLed.cpp Sat May 23 07:11:44 2020 +0000
@@ -0,0 +1,28 @@
+#include "KeyboardLed.h"
+
+KeyboardLed::KeyboardLed(unsigned char _ucColumn) {
+ pKeyboard = new Keyboard(_ucColumn);
+ pLed = new Ledboard(_ucColumn);
+};
+
+enum KeyboardState KeyboardLed::eRead(void) {
+ enum KeyboardState eButton = pKeyboard -> eRead();
+ switch(eButton) {
+ case BUTTON_0:
+ pLed -> On(0);
+ break;
+ case BUTTON_1:
+ pLed -> On(1);
+ break;
+ case BUTTON_2:
+ pLed -> On(2);
+ break;
+ case BUTTON_3:
+ pLed -> On(3);
+ break;
+ default :
+ pLed -> Off();
+ break;
+ }
+ return eButton;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/KeyboardLed.h Sat May 23 07:11:44 2020 +0000
@@ -0,0 +1,16 @@
+#ifndef KEYBOARDLED
+#define KEYBOARDLED
+
+#include "Ledboard.h"
+#include "Keyboard.h"
+
+class KeyboardLed {
+ public:
+ KeyboardLed(unsigned char);
+ enum KeyboardState eRead(void);
+ private:
+ Ledboard *pLed;
+ Keyboard *pKeyboard;
+};
+
+#endif
\ No newline at end of file
--- a/Keyboard_Ts.cpp Sat May 09 08:31:59 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-#include "Keyboard_Ts.h"
-
-KeyboardTs::KeyboardTs(unsigned char ucIdx) {
- ucColIdx = ucIdx;
- Init(240,320);
-}
-
-enum KeyboardState KeyboardTs::eRead(void) {
- TS_StateTypeDef TS_State;
- GetState(&TS_State);
- if ((TS_State.TouchDetected) && (TS_State.Y > 0 ) && (TS_State.Y < 80) && (TS_State.X > (80 * ucColIdx)) && (TS_State.X < (80 * (ucColIdx + 1)))) {
- return BUTTON_0;
- }
- else if ((TS_State.TouchDetected) && (TS_State.Y > 80 ) && (TS_State.Y < 160) && (TS_State.X > (80 * ucColIdx)) && (TS_State.X < (80 * (ucColIdx + 1)))) {
- return BUTTON_1;
- }
- else if ((TS_State.TouchDetected) && (TS_State.Y > 160 ) && (TS_State.Y < 240) && (TS_State.X > (80 * ucColIdx)) && (TS_State.X < (80 * (ucColIdx + 1)))) {
- return BUTTON_2;
- }
- else if ((TS_State.TouchDetected) && (TS_State.Y > 240 ) && (TS_State.Y < 320) && (TS_State.X > (80 * ucColIdx)) && (TS_State.X < (80 * (ucColIdx + 1)))) {
- return BUTTON_3;
- }
- else{
- return RELASED;
- }
-}
\ No newline at end of file
--- a/Keyboard_Ts.h Sat May 09 08:31:59 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-#ifndef KEYBOARD_TS
-#define KEYBOARD_TS
-
-#include "TS_DISCO_F429ZI.h"
-
-enum KeyboardState{
- RELASED,
- BUTTON_0,
- BUTTON_1,
- BUTTON_2,
- BUTTON_3
-};
-
-class KeyboardTs : private TS_DISCO_F429ZI {
- private:
- unsigned char ucColIdx;
- public:
- KeyboardTs(unsigned char);
- enum KeyboardState eRead(void);
-
-};
-
-#endif
\ No newline at end of file
--- a/Keyboard_Ts_Lcd.cpp Sat May 09 08:31:59 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-#include "Keyboard_Ts_Lcd.h"
-
-KeyboardTsLcd::KeyboardTsLcd(unsigned char _ucColumn)
-{
- pKeyboard = new KeyboardTs(_ucColumn);
- pLed = new LedLcd(_ucColumn);
-};
-
-enum KeyboardState KeyboardTsLcd::eRead(void) {
- enum KeyboardState eButton = pKeyboard -> eRead();
- switch(eButton) {
- case BUTTON_0:
- pLed -> On(0);
- break;
- case BUTTON_1:
- pLed -> On(1);
- break;
- case BUTTON_2:
- pLed -> On(2);
- break;
- case BUTTON_3:
- pLed -> On(3);
- break;
- default :
- pLed -> On(4);
- break;
- }
- return eButton;
-}
\ No newline at end of file
--- a/Keyboard_Ts_Lcd.h Sat May 09 08:31:59 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-#ifndef KEYBOARD_TS_LCD
-#define KEYBOARD_TS_LCD
-
-#include "Led_Lcd.h"
-#include "Keyboard_Ts.h"
-
-class KeyboardTsLcd {
- public:
- KeyboardTsLcd(unsigned char);
- enum KeyboardState eRead(void);
- private:
- LedLcd *pLed;
- KeyboardTs *pKeyboard;
-};
-
-#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Led.cpp Sat May 23 07:11:44 2020 +0000
@@ -0,0 +1,26 @@
+#include "Led.h"
+#include "LCD_DISCO_F429ZI.h"
+
+extern LCD_DISCO_F429ZI Lcd;
+
+Led::Led(unsigned char ucColIdx, unsigned char ucRowIdx) {
+ ucColumn = ucColIdx;
+ ucRow = ucRowIdx;
+}
+
+void Led::On(void) {
+ Redraw(LCD_COLOR_YELLOW);
+}
+
+void Led::Off(void) {
+ Redraw(LCD_COLOR_BLUE);
+}
+
+void Led::Redraw(uint32_t Color) {
+ Lcd.SetBackColor(LCD_COLOR_RED);
+ Lcd.SetTextColor(Color);
+ Lcd.FillRect(1+ (ucColumn * 80), (ucRow*80 + 1), 79, 79);
+ Lcd.SetTextColor(LCD_COLOR_WHITE);
+ unsigned char ucAscii[2] = {48 + ucRow, 0};
+ Lcd.DisplayStringAt((ucColumn * 80), (ucRow * 80), (uint8_t *)ucAscii, LEFT_MODE);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Led.h Sat May 23 07:11:44 2020 +0000
@@ -0,0 +1,16 @@
+#ifndef LED
+#define LED
+
+#include "mbed.h"
+
+class Led {
+ public:
+ Led(unsigned char ucColIdx, unsigned char ucRowIdx);
+ void On();
+ void Off();
+ private:
+ unsigned char ucColumn, ucRow;
+ void Redraw(uint32_t Color);
+};
+
+#endif
\ No newline at end of file
--- a/Led_Lcd.cpp Sat May 09 08:31:59 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-#include "Led_Lcd.h"
-
-LedLcd::LedLcd(unsigned char ucIdx) {
- ucColIdx = ucIdx;
- SetFont(&Font24);
- Clear(LCD_COLOR_BLACK);
- SetTextColor(LCD_COLOR_GREEN);
- for(unsigned char I = 0; I < 4; I++) {
- DrawRect(80*ucColIdx, 80*I, 80, 80);
- }
-}
-
-void LedLcd::On(unsigned char ucIdx) {
- SetBackColor(LCD_COLOR_RED);
- for(unsigned char I = 0; I < 4; I++) {
- if(I == ucIdx) {
- SetTextColor(LCD_COLOR_GREEN);
- }
- else {
- SetTextColor(LCD_COLOR_BLUE);
- }
- FillRect(1+ (ucColIdx * 80), (I*80 + 1), 79, 79);
- SetTextColor(LCD_COLOR_WHITE);
- unsigned char ucAscii[2] = {48 + I, 0};
- DisplayStringAt((ucColIdx * 80), (I * 80), (uint8_t *)ucAscii, LEFT_MODE);
- }
-}
\ No newline at end of file
--- a/Led_Lcd.h Sat May 09 08:31:59 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-#ifndef LED_LCD
-#define LED_LCD
-
-#include "LCD_DISCO_F429ZI.h"
-
-class LedLcd : private LCD_DISCO_F429ZI{
- private:
- unsigned char ucColIdx;
- public:
- LedLcd(unsigned char);
- void On(unsigned char);
-};
-
-#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Ledboard.cpp Sat May 23 07:11:44 2020 +0000
@@ -0,0 +1,31 @@
+#include "Ledboard.h"
+#include "LCD_DISCO_F429ZI.h"
+
+extern LCD_DISCO_F429ZI Lcd;
+
+Ledboard::Ledboard(unsigned char ucIdx) {
+ Lcd.SetFont(&Font24);
+ Lcd.Clear(LCD_COLOR_BLACK);
+ Lcd.SetTextColor(LCD_COLOR_GREEN);
+ for(unsigned char I = 0; I < 4; I++) {
+ Lcd.DrawRect(80*ucIdx, 80*I, 80, 80);
+ Leds[I] = new Led(ucIdx, I);
+ }
+}
+
+void Ledboard::On(unsigned char ucIdx) {
+ for(unsigned char I = 0; I < 4; I++) {
+ if(I == ucIdx) {
+ Leds[I] -> On();
+ }
+ else {
+ Leds[I] -> Off();
+ }
+ }
+}
+
+void Ledboard::Off(void) {
+ for(unsigned char I = 0; I < 4; I++) {
+ Leds[I] -> Off();
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Ledboard.h Sat May 23 07:11:44 2020 +0000
@@ -0,0 +1,15 @@
+#ifndef LEDBOARD
+#define LEDBOARD
+
+#include "Led.h"
+
+class Ledboard {
+ public:
+ Ledboard (unsigned char ucColumn);
+ void Off();
+ void On(unsigned char);
+ private:
+ Led *Leds[3];
+};
+
+#endif
\ No newline at end of file
--- a/main.cpp Sat May 09 08:31:59 2020 +0000
+++ b/main.cpp Sat May 23 07:11:44 2020 +0000
@@ -1,8 +1,11 @@
-#include "Keyboard_Ts_Lcd.h"
+#include "KeyboardLed.h"
+#include "LCD_DISCO_F429ZI.h"
+
+LCD_DISCO_F429ZI Lcd;
int main() {
- KeyboardTsLcd Keyboard(0);
- LedLcd Led(2);
+ KeyboardLed Keyboard(0);
+ Ledboard Led(2);
while(1) {
switch(Keyboard.eRead()) {
@@ -19,7 +22,7 @@
Led.On(0);
break;
default :
- Led.On(4);
+ Led.Off();
break;
}
wait(0.1);