Last active
October 3, 2016 08:14
-
-
Save bright-light-in-the-night/2c89089899d487a3644875a30e47fdb9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://ee-programming-notepad.blogspot.com/2016/10/c-array-of-pointers-to-objects.html | |
#include "mbed.h" | |
#include "ILI9340_Driver.h" | |
#define LCD_MOSI D11 | |
#define LCD_MISO D12 | |
#define LCD_SCK D13 | |
#define LCD_DC D7 | |
#define LCD1_RST D3 | |
#define LCD1_CS D5 | |
#define LCD2_RST A1 | |
#define LCD2_CS A0 | |
#define LCD_NO_SCREENS 2 | |
ILI9340_Display * tft_lcds[LCD_NO_SCREENS]; | |
int main() { | |
char i = 0; | |
PinName cs_pin, rst_pin; | |
ILI9340_Display * tft_lcd; // array of pointers to objects | |
while (i < LCD_NO_SCREENS) // iterate the screens | |
{ | |
switch (i) | |
{ | |
case 0: // first screen | |
cs_pin = LCD1_CS; | |
rst_pin = LCD1_RST; | |
break; | |
case 1: // second screen | |
cs_pin = LCD2_CS; | |
rst_pin = LCD2_RST; | |
break; | |
} | |
// instantiate the LCD class | |
tft_lcd = new ILI9340_Display(LCD_MOSI, LCD_MISO, LCD_SCK, cs_pin, rst_pin, LCD_DC); // MOSI, MISO, SCK, CS, RST, D/C | |
tft_lcd->DispInit(); | |
tft_lcd->SetRotation(0); | |
tft_lcd->FillScreen(ILI9340_BLUE); | |
// push the new instance to the array of pointers | |
tft_lcds[i] = tft_lcd; | |
i++; | |
} | |
// ... code ... | |
wait(2); | |
// later on, display some text on LCD | |
i = 0; | |
while (i < LCD_NO_SCREENS) | |
{ | |
tft_lcds[i]->FillScreen(ILI9340_RED); | |
char buff[20]; | |
sprintf(buff, "Loading %d...", i); | |
tft_lcds[i]->DrawString(buff, 0, 0, 2, ILI9340_WHITE); // draw a text with 8px font | |
i++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment