![](/media/cache/profiles/ndu.jpg.50x50_q85.jpg)
keyboard input, serial com test
Dependencies: mbed DISCO_L475VG_IOT01A_wifi TextLCD USBHost
Diff: main.cpp
- Revision:
- 4:c2cdba0bae47
- Parent:
- 2:c1f316e932bc
- Child:
- 5:0466445897b8
--- a/main.cpp Fri Jul 26 03:34:02 2019 +0000 +++ b/main.cpp Mon Aug 05 18:26:58 2019 +0000 @@ -1,69 +1,27 @@ #include "mbed.h" -#include "USBHostMouse.h" #include "TextLCD.h" DigitalOut led1(LED1); Serial pc(SERIAL_TX, SERIAL_RX); AnalogIn button(A0); // Init button (SELECT, LEFT, UP, DOWN, RIGHT) -// LCD (RS, E, D4, D5, D6, D7); -TextLCD lcd(D8, D9, D4, D5, D6, D7); +TextLCD lcd(D8, D9, D4, D5, D6, D7); // LCD (RS, E, D4, D5, D6, D7); PwmOut backlight(D10); // Backlight LCD -void onMouseEvent(uint8_t buttons, int8_t x, int8_t y, int8_t z) -{ - static int buttonState = 0; - - if (buttons != buttonState){ - buttonState = buttons; - - lcd.cls(); // Clear LCD - lcd.locate(1,0); // Set locate (1 row, 2 column) - printf("Buttons: %d, x: %d, y: %d, z: %d\r\n", buttons, x, y, z); - lcd.printf("Buttons: %d", buttons); - } -} - -void mouse_task(void const *) -{ - USBHostMouse mouse; - - printf("Mouse started\r\n"); - - while(1) { - - // Try to connect a USB mouse - while(!mouse.connect()) { - Thread::wait(500); - } - - // When connected, attach handler called on mouse event - mouse.attachEvent(onMouseEvent); - - // Wait until the mouse is disconnected - while(mouse.connected()) { - Thread::wait(500); - } - - printf("Mouse disconnected\r\n"); - } -} - int main() -{ +{ // Set backlight period and duty cycle backlight.period(0.002); backlight = 1; - lcd.cls(); // Clear LCD lcd.locate(1,0); // Set locate (1 row, 2 column) lcd.printf("LCD Key Shield"); - wait(1); - - - Thread mouseTask(mouse_task, NULL, osPriorityNormal, 1024* 4); + while(1) { + lcd.cls(); + lcd.locate(1,0); + lcd.printf("%f", button.read()); + wait(1); led1 = !led1; - Thread::wait(100); } }