Please run it on your NUCLEO-L152

Dependencies:   mbed

Committer:
davidprentice
Date:
Wed Sep 18 10:26:00 2019 +0000
Revision:
0:b608c7f02f80
Child:
1:d88d2ad55fac
add L152 to utility/pin_shield_?.h; otherwise MCUFRIEND_kbv from Beta on GitHub

Who changed what in which revision?

UserRevisionLine numberNew contents of line
davidprentice 0:b608c7f02f80 1 #include "Arduino.h"
davidprentice 0:b608c7f02f80 2
davidprentice 0:b608c7f02f80 3 #include <MCUFRIEND_kbv.h>
davidprentice 0:b608c7f02f80 4 MCUFRIEND_kbv tft;
davidprentice 0:b608c7f02f80 5
davidprentice 0:b608c7f02f80 6 // Assign human-readable names to some common 16-bit color values:
davidprentice 0:b608c7f02f80 7 #define BLACK 0x0000
davidprentice 0:b608c7f02f80 8 #define BLUE 0x001F
davidprentice 0:b608c7f02f80 9 #define RED 0xF800
davidprentice 0:b608c7f02f80 10 #define GREEN 0x07E0
davidprentice 0:b608c7f02f80 11 #define CYAN 0x07FF
davidprentice 0:b608c7f02f80 12 #define MAGENTA 0xF81F
davidprentice 0:b608c7f02f80 13 #define YELLOW 0xFFE0
davidprentice 0:b608c7f02f80 14 #define WHITE 0xFFFF
davidprentice 0:b608c7f02f80 15 #define GRAY 0x8410
davidprentice 0:b608c7f02f80 16
davidprentice 0:b608c7f02f80 17 uint16_t version = MCUFRIEND_KBV_H_;
davidprentice 0:b608c7f02f80 18
davidprentice 0:b608c7f02f80 19 void setup()
davidprentice 0:b608c7f02f80 20 {
davidprentice 0:b608c7f02f80 21 uint16_t ID = tft.readID(); //
davidprentice 0:b608c7f02f80 22 tft.begin(ID);
davidprentice 0:b608c7f02f80 23 }
davidprentice 0:b608c7f02f80 24
davidprentice 0:b608c7f02f80 25 void loop()
davidprentice 0:b608c7f02f80 26 {
davidprentice 0:b608c7f02f80 27 static uint8_t aspect = 0;
davidprentice 0:b608c7f02f80 28 const char *aspectname[] = {
davidprentice 0:b608c7f02f80 29 "PORTRAIT", "LANDSCAPE", "PORTRAIT_REV", "LANDSCAPE_REV"
davidprentice 0:b608c7f02f80 30 };
davidprentice 0:b608c7f02f80 31 const char *colorname[] = { "BLUE", "GREEN", "RED", "GRAY" };
davidprentice 0:b608c7f02f80 32 uint16_t colormask[] = { BLUE, GREEN, RED, GRAY };
davidprentice 0:b608c7f02f80 33 uint16_t ID = tft.readID(); //
davidprentice 0:b608c7f02f80 34 tft.setRotation(aspect);
davidprentice 0:b608c7f02f80 35 int width = tft.width();
davidprentice 0:b608c7f02f80 36 int height = tft.height();
davidprentice 0:b608c7f02f80 37 tft.fillScreen(colormask[aspect]);
davidprentice 0:b608c7f02f80 38 tft.drawRect(0, 0, width, height, WHITE);
davidprentice 0:b608c7f02f80 39 tft.drawRect(32, 32, width - 64, height - 64, WHITE);
davidprentice 0:b608c7f02f80 40 tft.setTextSize(2);
davidprentice 0:b608c7f02f80 41 tft.setTextColor(BLACK);
davidprentice 0:b608c7f02f80 42 tft.setCursor(40, 40);
davidprentice 0:b608c7f02f80 43 tft.print("ID=0x");
davidprentice 0:b608c7f02f80 44 tft.println(ID, HEX);
davidprentice 0:b608c7f02f80 45 if (ID == 0xD3D3) tft.print(" w/o");
davidprentice 0:b608c7f02f80 46 tft.setCursor(40, 70);
davidprentice 0:b608c7f02f80 47 tft.print(aspectname[aspect]);
davidprentice 0:b608c7f02f80 48 tft.setCursor(40, 100);
davidprentice 0:b608c7f02f80 49 tft.print(width);
davidprentice 0:b608c7f02f80 50 tft.print(" x ");
davidprentice 0:b608c7f02f80 51 tft.print(height);
davidprentice 0:b608c7f02f80 52 tft.setTextColor(WHITE);
davidprentice 0:b608c7f02f80 53 tft.setCursor(40, 130);
davidprentice 0:b608c7f02f80 54 tft.print(colorname[aspect]);
davidprentice 0:b608c7f02f80 55 tft.setCursor(40, 160);
davidprentice 0:b608c7f02f80 56 tft.setTextSize(1);
davidprentice 0:b608c7f02f80 57 tft.print("MCUFRIEND_KBV_H_ = ");
davidprentice 0:b608c7f02f80 58 tft.print(version);
davidprentice 0:b608c7f02f80 59 if (++aspect > 3) aspect = 0;
davidprentice 0:b608c7f02f80 60 delay(5000);
davidprentice 0:b608c7f02f80 61 }
davidprentice 0:b608c7f02f80 62
davidprentice 0:b608c7f02f80 63 uint32_t millis(void)
davidprentice 0:b608c7f02f80 64 {
davidprentice 0:b608c7f02f80 65 static Timer t;
davidprentice 0:b608c7f02f80 66 static int first = 1;
davidprentice 0:b608c7f02f80 67 if (first) first = 0, t.start();
davidprentice 0:b608c7f02f80 68 return t.read_ms();
davidprentice 0:b608c7f02f80 69 }
davidprentice 0:b608c7f02f80 70
davidprentice 0:b608c7f02f80 71 uint32_t micros(void)
davidprentice 0:b608c7f02f80 72 {
davidprentice 0:b608c7f02f80 73 static Timer t;
davidprentice 0:b608c7f02f80 74 static int first = 1;
davidprentice 0:b608c7f02f80 75 if (first) first = 0, t.start();
davidprentice 0:b608c7f02f80 76 return t.read_us();
davidprentice 0:b608c7f02f80 77 }
davidprentice 0:b608c7f02f80 78
davidprentice 0:b608c7f02f80 79 void main(void)
davidprentice 0:b608c7f02f80 80 {
davidprentice 0:b608c7f02f80 81 setup();
davidprentice 0:b608c7f02f80 82 while (1) {
davidprentice 0:b608c7f02f80 83 loop();
davidprentice 0:b608c7f02f80 84 }
davidprentice 0:b608c7f02f80 85 }