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
main.cpp@0:e579c6f35abf, 2020-11-15 (annotated)
- Committer:
- kkleong
- Date:
- Sun Nov 15 21:53:52 2020 +0000
- Revision:
- 0:e579c6f35abf
- Child:
- 1:9770f292298c
Error with quads
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| kkleong | 0:e579c6f35abf | 1 | #include "mbed.h" |
| kkleong | 0:e579c6f35abf | 2 | #include "TS_DISCO_F429ZI.h" |
| kkleong | 0:e579c6f35abf | 3 | #include "LCD_DISCO_F429ZI.h" |
| kkleong | 0:e579c6f35abf | 4 | |
| kkleong | 0:e579c6f35abf | 5 | extern "C" uint32_t getQuad ( uint16_t x, uint16_t y); |
| kkleong | 0:e579c6f35abf | 6 | extern "C" uint32_t swapRedBlue ( uint32_t color); |
| kkleong | 0:e579c6f35abf | 7 | extern "C" uint32_t toggleAlphaMSB ( uint32_t color); |
| kkleong | 0:e579c6f35abf | 8 | //extern "C" uint32_t rotateRGBBytes ( uint32_t color); |
| kkleong | 0:e579c6f35abf | 9 | //extern "C" uint32_t setRGBBits ( uint32_t color, uint8_t n); |
| kkleong | 0:e579c6f35abf | 10 | |
| kkleong | 0:e579c6f35abf | 11 | LCD_DISCO_F429ZI lcd; |
| kkleong | 0:e579c6f35abf | 12 | TS_DISCO_F429ZI ts; |
| kkleong | 0:e579c6f35abf | 13 | |
| kkleong | 0:e579c6f35abf | 14 | int main() |
| kkleong | 0:e579c6f35abf | 15 | { |
| kkleong | 0:e579c6f35abf | 16 | TS_StateTypeDef TS_State; |
| kkleong | 0:e579c6f35abf | 17 | uint16_t x, y; |
| kkleong | 0:e579c6f35abf | 18 | uint8_t text[30]; |
| kkleong | 0:e579c6f35abf | 19 | //uint8_t status; |
| kkleong | 0:e579c6f35abf | 20 | |
| kkleong | 0:e579c6f35abf | 21 | BSP_LCD_SetFont(&Font20); |
| kkleong | 0:e579c6f35abf | 22 | |
| kkleong | 0:e579c6f35abf | 23 | lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"Project 3!!!", CENTER_MODE); |
| kkleong | 0:e579c6f35abf | 24 | wait(1); |
| kkleong | 0:e579c6f35abf | 25 | |
| kkleong | 0:e579c6f35abf | 26 | int xSize = lcd.GetXSize()/2; |
| kkleong | 0:e579c6f35abf | 27 | int ySize = lcd.GetYSize()/2; |
| kkleong | 0:e579c6f35abf | 28 | |
| kkleong | 0:e579c6f35abf | 29 | uint32_t blue = 0xFF0000FF; |
| kkleong | 0:e579c6f35abf | 30 | uint32_t green = 0xFF00FF00; |
| kkleong | 0:e579c6f35abf | 31 | uint32_t red = 0xFFFF0000; |
| kkleong | 0:e579c6f35abf | 32 | uint32_t yellow = 0xFFFFFF00; |
| kkleong | 0:e579c6f35abf | 33 | |
| kkleong | 0:e579c6f35abf | 34 | lcd.SetTextColor(blue); //blue |
| kkleong | 0:e579c6f35abf | 35 | lcd.FillRect(0, 0, xSize, ySize); |
| kkleong | 0:e579c6f35abf | 36 | lcd.SetTextColor(green); //green |
| kkleong | 0:e579c6f35abf | 37 | lcd.FillRect(0, ySize, xSize, ySize); |
| kkleong | 0:e579c6f35abf | 38 | lcd.SetTextColor(red); //red |
| kkleong | 0:e579c6f35abf | 39 | lcd.FillRect(xSize, 0, xSize, ySize); |
| kkleong | 0:e579c6f35abf | 40 | lcd.SetTextColor(yellow); //yellow |
| kkleong | 0:e579c6f35abf | 41 | lcd.FillRect(xSize, ySize, xSize, ySize); |
| kkleong | 0:e579c6f35abf | 42 | |
| kkleong | 0:e579c6f35abf | 43 | //status = ts.Init(lcd.GetXSize(), lcd.GetYSize()); |
| kkleong | 0:e579c6f35abf | 44 | |
| kkleong | 0:e579c6f35abf | 45 | wait(1); |
| kkleong | 0:e579c6f35abf | 46 | |
| kkleong | 0:e579c6f35abf | 47 | while(1) |
| kkleong | 0:e579c6f35abf | 48 | { |
| kkleong | 0:e579c6f35abf | 49 | ts.GetState(&TS_State); |
| kkleong | 0:e579c6f35abf | 50 | if (TS_State.TouchDetected) |
| kkleong | 0:e579c6f35abf | 51 | { |
| kkleong | 0:e579c6f35abf | 52 | x = TS_State.X; |
| kkleong | 0:e579c6f35abf | 53 | y = TS_State.Y; |
| kkleong | 0:e579c6f35abf | 54 | sprintf((char*)text, "x=%d y=%d ", x, y); |
| kkleong | 0:e579c6f35abf | 55 | lcd.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); |
| kkleong | 0:e579c6f35abf | 56 | |
| kkleong | 0:e579c6f35abf | 57 | int quad = getQuad(x, y); |
| kkleong | 0:e579c6f35abf | 58 | |
| kkleong | 0:e579c6f35abf | 59 | if(quad == 1){ |
| kkleong | 0:e579c6f35abf | 60 | blue = swapRedBlue(blue); |
| kkleong | 0:e579c6f35abf | 61 | lcd.SetTextColor(blue); |
| kkleong | 0:e579c6f35abf | 62 | lcd.FillRect(0, 0, xSize, ySize); |
| kkleong | 0:e579c6f35abf | 63 | } |
| kkleong | 0:e579c6f35abf | 64 | else if(quad == 2){ |
| kkleong | 0:e579c6f35abf | 65 | red = toggleAlphaMSB(red); |
| kkleong | 0:e579c6f35abf | 66 | lcd.SetTextColor(red); |
| kkleong | 0:e579c6f35abf | 67 | lcd.FillRect(xSize, 0, xSize, ySize); |
| kkleong | 0:e579c6f35abf | 68 | } |
| kkleong | 0:e579c6f35abf | 69 | else if(quad == 3){ |
| kkleong | 0:e579c6f35abf | 70 | } |
| kkleong | 0:e579c6f35abf | 71 | else if(quad == 4){ |
| kkleong | 0:e579c6f35abf | 72 | |
| kkleong | 0:e579c6f35abf | 73 | } |
| kkleong | 0:e579c6f35abf | 74 | |
| kkleong | 0:e579c6f35abf | 75 | |
| kkleong | 0:e579c6f35abf | 76 | } |
| kkleong | 0:e579c6f35abf | 77 | } |
| kkleong | 0:e579c6f35abf | 78 | } |