Displays a large title and some small text with a blue rectangle Constantly refreshes 3 variable values on the screen. NO TOUCH SUPPORT AS OF YET
main.cpp@0:38cf064697d7, 2015-12-05 (annotated)
- Committer:
- EmbeddedSam
- Date:
- Sat Dec 05 23:41:01 2015 +0000
- Revision:
- 0:38cf064697d7
First commit, working with displaying messages; no touch support as of yet
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| EmbeddedSam | 0:38cf064697d7 | 1 | /* |
| EmbeddedSam | 0:38cf064697d7 | 2 | Adafruit LCD STM32F401RE Nucleo Example |
| EmbeddedSam | 0:38cf064697d7 | 3 | |
| EmbeddedSam | 0:38cf064697d7 | 4 | This code was adapted from ILI9341 TFT LCD library found on mbed.org |
| EmbeddedSam | 0:38cf064697d7 | 5 | Can't find original code right now but it's on mbed somewhere. |
| EmbeddedSam | 0:38cf064697d7 | 6 | |
| EmbeddedSam | 0:38cf064697d7 | 7 | For use with Adafruit 2.8 inch Capacative ILI9341 LCD |
| EmbeddedSam | 0:38cf064697d7 | 8 | Please note that the touch screen is not used in this example |
| EmbeddedSam | 0:38cf064697d7 | 9 | |
| EmbeddedSam | 0:38cf064697d7 | 10 | Author Samuel.Walsh@Manchester.ac.uk (ported slightly, didn't write) |
| EmbeddedSam | 0:38cf064697d7 | 11 | */ |
| EmbeddedSam | 0:38cf064697d7 | 12 | |
| EmbeddedSam | 0:38cf064697d7 | 13 | |
| EmbeddedSam | 0:38cf064697d7 | 14 | #include "SPI_TFT_ILI9341.h" |
| EmbeddedSam | 0:38cf064697d7 | 15 | #include "Arial12x12.h" |
| EmbeddedSam | 0:38cf064697d7 | 16 | #include "Neu42x35.h" |
| EmbeddedSam | 0:38cf064697d7 | 17 | #include "mbed.h" |
| EmbeddedSam | 0:38cf064697d7 | 18 | |
| EmbeddedSam | 0:38cf064697d7 | 19 | /* Adafruit 2.8" Cap Touch LCD Panel - Arduino Pinout |
| EmbeddedSam | 0:38cf064697d7 | 20 | |
| EmbeddedSam | 0:38cf064697d7 | 21 | FUNCTION MBED NUCLEO (pins) |
| EmbeddedSam | 0:38cf064697d7 | 22 | ===================================== |
| EmbeddedSam | 0:38cf064697d7 | 23 | TFT SCLK = D13 = PA_5 (SPI1 SCLK) |
| EmbeddedSam | 0:38cf064697d7 | 24 | TFT MISO = D12 = PA_6 (SPI1 MISO) |
| EmbeddedSam | 0:38cf064697d7 | 25 | TFT MOSI = D11 = PA_7 (SPI1 MOSI) |
| EmbeddedSam | 0:38cf064697d7 | 26 | TFT CS = D10 = PB_6 |
| EmbeddedSam | 0:38cf064697d7 | 27 | TFT DC = D9 = PC_7 |
| EmbeddedSam | 0:38cf064697d7 | 28 | |
| EmbeddedSam | 0:38cf064697d7 | 29 | CARD CS = D4 = PB_5 |
| EmbeddedSam | 0:38cf064697d7 | 30 | |
| EmbeddedSam | 0:38cf064697d7 | 31 | TOUCH SCL = D15 = PB8 (I2C1_SCL) |
| EmbeddedSam | 0:38cf064697d7 | 32 | TOUCH SDA = D14 = PB_9 (I2C1 SDA) |
| EmbeddedSam | 0:38cf064697d7 | 33 | |
| EmbeddedSam | 0:38cf064697d7 | 34 | //D7 = PA_8 = TPIRQ |
| EmbeddedSam | 0:38cf064697d7 | 35 | */ |
| EmbeddedSam | 0:38cf064697d7 | 36 | |
| EmbeddedSam | 0:38cf064697d7 | 37 | |
| EmbeddedSam | 0:38cf064697d7 | 38 | int main(void) |
| EmbeddedSam | 0:38cf064697d7 | 39 | { |
| EmbeddedSam | 0:38cf064697d7 | 40 | //Setup pins and hardware |
| EmbeddedSam | 0:38cf064697d7 | 41 | //DigitalIn shellSwitch(D6); // PB_0 (normally pulled high) |
| EmbeddedSam | 0:38cf064697d7 | 42 | I2C i2c(I2C_SDA, I2C_SCL); // SDA, SCL |
| EmbeddedSam | 0:38cf064697d7 | 43 | SPI_TFT_ILI9341 TFT(PA_7, PA_6, PA_5, PB_6, PA_8, PC_7,"TFT"); // mosi, miso, sclk, cs, reset, dc |
| EmbeddedSam | 0:38cf064697d7 | 44 | DigitalOut lcdOn(PC_7); //not sure this one is correct PC_7 function is unknown |
| EmbeddedSam | 0:38cf064697d7 | 45 | |
| EmbeddedSam | 0:38cf064697d7 | 46 | //Init display SPI |
| EmbeddedSam | 0:38cf064697d7 | 47 | lcdOn = 1; |
| EmbeddedSam | 0:38cf064697d7 | 48 | |
| EmbeddedSam | 0:38cf064697d7 | 49 | TFT.claim(stdout); |
| EmbeddedSam | 0:38cf064697d7 | 50 | TFT.set_orientation(1); |
| EmbeddedSam | 0:38cf064697d7 | 51 | TFT.background(White); // set background to black |
| EmbeddedSam | 0:38cf064697d7 | 52 | TFT.foreground(Black); // set chars to white |
| EmbeddedSam | 0:38cf064697d7 | 53 | TFT.cls(); // clear the screen |
| EmbeddedSam | 0:38cf064697d7 | 54 | |
| EmbeddedSam | 0:38cf064697d7 | 55 | |
| EmbeddedSam | 0:38cf064697d7 | 56 | TFT.set_font((unsigned char*) Arial12x12); |
| EmbeddedSam | 0:38cf064697d7 | 57 | TFT.locate(0,0); |
| EmbeddedSam | 0:38cf064697d7 | 58 | |
| EmbeddedSam | 0:38cf064697d7 | 59 | double var1 = 123.32; |
| EmbeddedSam | 0:38cf064697d7 | 60 | double var2 = 123.4; |
| EmbeddedSam | 0:38cf064697d7 | 61 | double var3 = 87; //example variables to display |
| EmbeddedSam | 0:38cf064697d7 | 62 | |
| EmbeddedSam | 0:38cf064697d7 | 63 | // Use large fonts to display title |
| EmbeddedSam | 0:38cf064697d7 | 64 | TFT.background(White); |
| EmbeddedSam | 0:38cf064697d7 | 65 | TFT.foreground(Blue); |
| EmbeddedSam | 0:38cf064697d7 | 66 | TFT.locate(60, 50); |
| EmbeddedSam | 0:38cf064697d7 | 67 | TFT.set_font((unsigned char *) Neu42x35); |
| EmbeddedSam | 0:38cf064697d7 | 68 | TFT.printf("Title Here"); |
| EmbeddedSam | 0:38cf064697d7 | 69 | |
| EmbeddedSam | 0:38cf064697d7 | 70 | while(1){ |
| EmbeddedSam | 0:38cf064697d7 | 71 | // Display variable 1 in large and red |
| EmbeddedSam | 0:38cf064697d7 | 72 | TFT.background(White); |
| EmbeddedSam | 0:38cf064697d7 | 73 | TFT.foreground(Red); |
| EmbeddedSam | 0:38cf064697d7 | 74 | TFT.locate(100, 120); |
| EmbeddedSam | 0:38cf064697d7 | 75 | TFT.set_font((unsigned char *) Neu42x35); |
| EmbeddedSam | 0:38cf064697d7 | 76 | TFT.printf("%.02f",var1); |
| EmbeddedSam | 0:38cf064697d7 | 77 | |
| EmbeddedSam | 0:38cf064697d7 | 78 | // Smaller font in blue box for variable 2 |
| EmbeddedSam | 0:38cf064697d7 | 79 | TFT.fillrect(0,185,320,216,Blue); |
| EmbeddedSam | 0:38cf064697d7 | 80 | TFT.background(Blue); |
| EmbeddedSam | 0:38cf064697d7 | 81 | TFT.foreground(White); |
| EmbeddedSam | 0:38cf064697d7 | 82 | TFT.locate(0,187); |
| EmbeddedSam | 0:38cf064697d7 | 83 | TFT.set_font((unsigned char*) Arial12x12); |
| EmbeddedSam | 0:38cf064697d7 | 84 | TFT.printf("Variable 2 = %.02f", var2); |
| EmbeddedSam | 0:38cf064697d7 | 85 | |
| EmbeddedSam | 0:38cf064697d7 | 86 | //Bottom black box for variable 3 |
| EmbeddedSam | 0:38cf064697d7 | 87 | TFT.locate(0, 218); |
| EmbeddedSam | 0:38cf064697d7 | 88 | TFT.background(Black); |
| EmbeddedSam | 0:38cf064697d7 | 89 | TFT.foreground(White); |
| EmbeddedSam | 0:38cf064697d7 | 90 | TFT.set_font((unsigned char*) Arial12x12); |
| EmbeddedSam | 0:38cf064697d7 | 91 | TFT.printf("Variable 3: %0.2f", var3); |
| EmbeddedSam | 0:38cf064697d7 | 92 | |
| EmbeddedSam | 0:38cf064697d7 | 93 | wait(0.5); //Refresh the LCD once every half second |
| EmbeddedSam | 0:38cf064697d7 | 94 | |
| EmbeddedSam | 0:38cf064697d7 | 95 | //Change the variable values on refresh |
| EmbeddedSam | 0:38cf064697d7 | 96 | var1 += 0.01; |
| EmbeddedSam | 0:38cf064697d7 | 97 | var2 += 1; |
| EmbeddedSam | 0:38cf064697d7 | 98 | var3 += 0.5; |
| EmbeddedSam | 0:38cf064697d7 | 99 | } |
| EmbeddedSam | 0:38cf064697d7 | 100 | } |
| EmbeddedSam | 0:38cf064697d7 | 101 | |
| EmbeddedSam | 0:38cf064697d7 | 102 | |
| EmbeddedSam | 0:38cf064697d7 | 103 | |
| EmbeddedSam | 0:38cf064697d7 | 104 |