There are many examples on MBED for ST7735 controlled LCDs, but they're mostly for the AdaFruit LCD. This is a working example of the library used for the cheap-as-dirt KMR-1.8 SPI 128x160 TFT LCD, on a "Black Pill" STM32F407VE developement board.
Dependencies: 24_TFT_STMNUCLEO mbed
main.cpp@0:368cfb35a89a, 2018-09-28 (annotated)
- Committer:
- katbar
- Date:
- Fri Sep 28 03:37:23 2018 +0000
- Revision:
- 0:368cfb35a89a
Cheap ST7735 TFT LCD (KMR-1.8 SPI) with Todor Todorov's library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
katbar | 0:368cfb35a89a | 1 | // WORKS with KMR-1.8 128x160 TFT LCD |
katbar | 0:368cfb35a89a | 2 | // |
katbar | 0:368cfb35a89a | 3 | // Hookup: |
katbar | 0:368cfb35a89a | 4 | // VCC, LED+ - 3.3V |
katbar | 0:368cfb35a89a | 5 | // CS - PC_4 |
katbar | 0:368cfb35a89a | 6 | // SCLK - PA_5 |
katbar | 0:368cfb35a89a | 7 | // SDA - PA_7 |
katbar | 0:368cfb35a89a | 8 | // A0 - PC_5 |
katbar | 0:368cfb35a89a | 9 | // RESET - PA_4 |
katbar | 0:368cfb35a89a | 10 | |
katbar | 0:368cfb35a89a | 11 | |
katbar | 0:368cfb35a89a | 12 | #include "mbed.h" |
katbar | 0:368cfb35a89a | 13 | #include "st7735.h" |
katbar | 0:368cfb35a89a | 14 | #include "terminus.h" |
katbar | 0:368cfb35a89a | 15 | |
katbar | 0:368cfb35a89a | 16 | // create the lcd instance |
katbar | 0:368cfb35a89a | 17 | // ST7735_LCD( PinName CS, PinName RESET, PinName RS, PinName SCL, PinName SDA, PinName BL = NC, backlight_t blType = Constant, float defaultBackLightLevel = 1.0 ); |
katbar | 0:368cfb35a89a | 18 | ST7735_LCD lcd( PC_4, PA_4, PC_5, PA_5, PA_7 ); // control pins |
katbar | 0:368cfb35a89a | 19 | |
katbar | 0:368cfb35a89a | 20 | int main() |
katbar | 0:368cfb35a89a | 21 | { |
katbar | 0:368cfb35a89a | 22 | // initialize display - place it in standard portrait mode and set background to black and |
katbar | 0:368cfb35a89a | 23 | lcd.Initialize( LANDSCAPE_REV, RGB16 ); |
katbar | 0:368cfb35a89a | 24 | lcd.ClearScreen(); |
katbar | 0:368cfb35a89a | 25 | // various graphics primitives |
katbar | 0:368cfb35a89a | 26 | lcd.DrawPixel(1,1,0xFF9FFF); |
katbar | 0:368cfb35a89a | 27 | lcd.DrawLine(10,10,150,10,0xFF29A9); |
katbar | 0:368cfb35a89a | 28 | lcd.FillCircle(70,60,10,0x00FF00); |
katbar | 0:368cfb35a89a | 29 | lcd.DrawRect(30,80,50,100,0x0000FF); |
katbar | 0:368cfb35a89a | 30 | lcd.DrawRect(60,80,80,100,0xFF00FF); // any RGB mix XX-XX-XX |
katbar | 0:368cfb35a89a | 31 | lcd.DrawRect(90,80,110,100,0x00FFFF); // any RGB mix XX-XX-XX |
katbar | 0:368cfb35a89a | 32 | lcd.DrawRect(120,80,140,100,0xFFFF00); // any RGB mix XX-XX-XX |
katbar | 0:368cfb35a89a | 33 | lcd.SetFont( &TerminusFont ); |
katbar | 0:368cfb35a89a | 34 | // print something on the screen |
katbar | 0:368cfb35a89a | 35 | lcd.Print( "Hello, World!", CENTER, 25 ); // align text to center horizontally and use starndard colors |
katbar | 0:368cfb35a89a | 36 | while ( 1 ) { } |
katbar | 0:368cfb35a89a | 37 | } |