Fun LED stuff
Dependencies: LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI BSP_DISCO_F429ZI
main.cpp@4:69f1e5fa2cb6, 2020-11-16 (annotated)
- Committer:
- kkleong
- Date:
- Mon Nov 16 15:02:45 2020 +0000
- Revision:
- 4:69f1e5fa2cb6
- Parent:
- 3:d050fe8ebd78
Newe redBlue
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 | 2:1be4e7457636 | 8 | extern "C" uint32_t rotateRGBBytes ( uint32_t color); |
kkleong | 2:1be4e7457636 | 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 | 2:1be4e7457636 | 14 | uint32_t blue = 0xFF0000FF; |
kkleong | 2:1be4e7457636 | 15 | uint32_t green = 0xFF00FF00; |
kkleong | 2:1be4e7457636 | 16 | uint32_t red = 0xFFFF0000; |
kkleong | 2:1be4e7457636 | 17 | uint32_t yellow = 0xFFFFFF00; |
kkleong | 2:1be4e7457636 | 18 | |
kkleong | 0:e579c6f35abf | 19 | int main() |
kkleong | 0:e579c6f35abf | 20 | { |
kkleong | 0:e579c6f35abf | 21 | TS_StateTypeDef TS_State; |
kkleong | 0:e579c6f35abf | 22 | uint16_t x, y; |
kkleong | 0:e579c6f35abf | 23 | uint8_t text[30]; |
kkleong | 1:9770f292298c | 24 | uint8_t status; |
kkleong | 0:e579c6f35abf | 25 | |
kkleong | 0:e579c6f35abf | 26 | BSP_LCD_SetFont(&Font20); |
kkleong | 1:9770f292298c | 27 | |
kkleong | 1:9770f292298c | 28 | status = ts.Init(lcd.GetXSize(), lcd.GetYSize()); |
kkleong | 0:e579c6f35abf | 29 | |
kkleong | 1:9770f292298c | 30 | if (status != TS_OK) |
kkleong | 1:9770f292298c | 31 | { |
kkleong | 1:9770f292298c | 32 | lcd.Clear(LCD_COLOR_RED); |
kkleong | 1:9770f292298c | 33 | lcd.SetBackColor(LCD_COLOR_RED); |
kkleong | 1:9770f292298c | 34 | lcd.SetTextColor(LCD_COLOR_WHITE); |
kkleong | 1:9770f292298c | 35 | lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE); |
kkleong | 1:9770f292298c | 36 | lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"INIT FAIL", CENTER_MODE); |
kkleong | 1:9770f292298c | 37 | } |
kkleong | 1:9770f292298c | 38 | else |
kkleong | 1:9770f292298c | 39 | { |
kkleong | 1:9770f292298c | 40 | lcd.Clear(LCD_COLOR_GREEN); |
kkleong | 1:9770f292298c | 41 | lcd.SetBackColor(LCD_COLOR_GREEN); |
kkleong | 1:9770f292298c | 42 | lcd.SetTextColor(LCD_COLOR_WHITE); |
kkleong | 1:9770f292298c | 43 | lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE); |
kkleong | 1:9770f292298c | 44 | lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"INIT OK", CENTER_MODE); |
kkleong | 1:9770f292298c | 45 | } |
kkleong | 1:9770f292298c | 46 | |
kkleong | 1:9770f292298c | 47 | wait(1); |
kkleong | 1:9770f292298c | 48 | lcd.Clear(LCD_COLOR_BLUE); |
kkleong | 1:9770f292298c | 49 | lcd.SetBackColor(LCD_COLOR_BLUE); |
kkleong | 1:9770f292298c | 50 | |
kkleong | 1:9770f292298c | 51 | |
kkleong | 0:e579c6f35abf | 52 | lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"Project 3!!!", CENTER_MODE); |
kkleong | 2:1be4e7457636 | 53 | wait(1); |
kkleong | 1:9770f292298c | 54 | |
kkleong | 2:1be4e7457636 | 55 | lcd.Clear(LCD_COLOR_WHITE); |
kkleong | 2:1be4e7457636 | 56 | lcd.SetBackColor(LCD_COLOR_WHITE); |
kkleong | 2:1be4e7457636 | 57 | |
kkleong | 2:1be4e7457636 | 58 | wait(.5); |
kkleong | 1:9770f292298c | 59 | |
kkleong | 0:e579c6f35abf | 60 | int xSize = lcd.GetXSize()/2; |
kkleong | 0:e579c6f35abf | 61 | int ySize = lcd.GetYSize()/2; |
kkleong | 0:e579c6f35abf | 62 | |
kkleong | 2:1be4e7457636 | 63 | int quad = 0; |
kkleong | 0:e579c6f35abf | 64 | |
kkleong | 0:e579c6f35abf | 65 | lcd.SetTextColor(blue); //blue |
kkleong | 2:1be4e7457636 | 66 | lcd.DrawRect(0, 0, xSize, ySize); |
kkleong | 0:e579c6f35abf | 67 | lcd.FillRect(0, 0, xSize, ySize); |
kkleong | 2:1be4e7457636 | 68 | |
kkleong | 0:e579c6f35abf | 69 | lcd.SetTextColor(green); //green |
kkleong | 2:1be4e7457636 | 70 | lcd.DrawRect(0, ySize, xSize, ySize); |
kkleong | 0:e579c6f35abf | 71 | lcd.FillRect(0, ySize, xSize, ySize); |
kkleong | 2:1be4e7457636 | 72 | |
kkleong | 0:e579c6f35abf | 73 | lcd.SetTextColor(red); //red |
kkleong | 2:1be4e7457636 | 74 | lcd.DrawRect(xSize, 0, xSize, ySize); |
kkleong | 0:e579c6f35abf | 75 | lcd.FillRect(xSize, 0, xSize, ySize); |
kkleong | 2:1be4e7457636 | 76 | |
kkleong | 0:e579c6f35abf | 77 | lcd.SetTextColor(yellow); //yellow |
kkleong | 2:1be4e7457636 | 78 | lcd.DrawRect(xSize, ySize, xSize, ySize); |
kkleong | 0:e579c6f35abf | 79 | lcd.FillRect(xSize, ySize, xSize, ySize); |
kkleong | 0:e579c6f35abf | 80 | |
kkleong | 0:e579c6f35abf | 81 | while(1) |
kkleong | 0:e579c6f35abf | 82 | { |
kkleong | 2:1be4e7457636 | 83 | quad = 0; |
kkleong | 0:e579c6f35abf | 84 | ts.GetState(&TS_State); |
kkleong | 0:e579c6f35abf | 85 | if (TS_State.TouchDetected) |
kkleong | 0:e579c6f35abf | 86 | { |
kkleong | 0:e579c6f35abf | 87 | x = TS_State.X; |
kkleong | 0:e579c6f35abf | 88 | y = TS_State.Y; |
kkleong | 0:e579c6f35abf | 89 | sprintf((char*)text, "x=%d y=%d ", x, y); |
kkleong | 1:9770f292298c | 90 | lcd.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); |
kkleong | 3:d050fe8ebd78 | 91 | |
kkleong | 3:d050fe8ebd78 | 92 | quad = getQuad(x, y); |
kkleong | 1:9770f292298c | 93 | } |
kkleong | 1:9770f292298c | 94 | |
kkleong | 0:e579c6f35abf | 95 | |
kkleong | 0:e579c6f35abf | 96 | if(quad == 1){ |
kkleong | 3:d050fe8ebd78 | 97 | sprintf((char*)text, "QUAD: %d", quad); |
kkleong | 3:d050fe8ebd78 | 98 | lcd.DisplayStringAt(8, LINE(5), (uint8_t *)&text, CENTER_MODE); |
kkleong | 3:d050fe8ebd78 | 99 | |
kkleong | 0:e579c6f35abf | 100 | blue = swapRedBlue(blue); |
kkleong | 0:e579c6f35abf | 101 | lcd.SetTextColor(blue); |
kkleong | 2:1be4e7457636 | 102 | lcd.DrawRect(0, 0, xSize, ySize); |
kkleong | 0:e579c6f35abf | 103 | lcd.FillRect(0, 0, xSize, ySize); |
kkleong | 0:e579c6f35abf | 104 | } |
kkleong | 0:e579c6f35abf | 105 | else if(quad == 2){ |
kkleong | 3:d050fe8ebd78 | 106 | sprintf((char*)text, "QUAD: %d", quad); |
kkleong | 3:d050fe8ebd78 | 107 | lcd.DisplayStringAt(8, LINE(5), (uint8_t *)&text, CENTER_MODE); |
kkleong | 3:d050fe8ebd78 | 108 | |
kkleong | 0:e579c6f35abf | 109 | red = toggleAlphaMSB(red); |
kkleong | 0:e579c6f35abf | 110 | lcd.SetTextColor(red); |
kkleong | 2:1be4e7457636 | 111 | lcd.DrawRect(xSize, 0, xSize, ySize); |
kkleong | 0:e579c6f35abf | 112 | lcd.FillRect(xSize, 0, xSize, ySize); |
kkleong | 0:e579c6f35abf | 113 | } |
kkleong | 4:69f1e5fa2cb6 | 114 | else if(quad == 4){ |
kkleong | 3:d050fe8ebd78 | 115 | sprintf((char*)text, "QUAD: %d", quad); |
kkleong | 3:d050fe8ebd78 | 116 | lcd.DisplayStringAt(8, LINE(5), (uint8_t *)&text, CENTER_MODE); |
kkleong | 3:d050fe8ebd78 | 117 | |
kkleong | 2:1be4e7457636 | 118 | yellow = rotateRGBBytes(yellow); |
kkleong | 2:1be4e7457636 | 119 | lcd.SetTextColor(yellow); |
kkleong | 2:1be4e7457636 | 120 | lcd.DrawRect(xSize, ySize, xSize, ySize); |
kkleong | 2:1be4e7457636 | 121 | lcd.FillRect(xSize, ySize, xSize, ySize); |
kkleong | 0:e579c6f35abf | 122 | } |
kkleong | 4:69f1e5fa2cb6 | 123 | else if(quad == 3){ |
kkleong | 3:d050fe8ebd78 | 124 | sprintf((char*)text, "QUAD: %d", quad); |
kkleong | 3:d050fe8ebd78 | 125 | lcd.DisplayStringAt(8, LINE(5), (uint8_t *)&text, CENTER_MODE); |
kkleong | 3:d050fe8ebd78 | 126 | |
kkleong | 2:1be4e7457636 | 127 | green = setRGBBits(green, 2); |
kkleong | 2:1be4e7457636 | 128 | lcd.SetTextColor(green); |
kkleong | 4:69f1e5fa2cb6 | 129 | lcd.DrawRect(0, ySize, xSize, ySize); |
kkleong | 4:69f1e5fa2cb6 | 130 | lcd.FillRect(0, ySize, xSize, ySize); |
kkleong | 0:e579c6f35abf | 131 | } |
kkleong | 1:9770f292298c | 132 | wait(.2); |
kkleong | 0:e579c6f35abf | 133 | } |
kkleong | 0:e579c6f35abf | 134 | } |