lcd ili9341

This commit is contained in:
2021-08-17 13:19:31 +02:00
parent a217c5cd93
commit babb031649
9 changed files with 186 additions and 32 deletions

View File

@@ -1,11 +1,11 @@
#pragma once
#define LCD_MOSI PA7
#define LCD_SCLK PA5
#define LCD_RES PA12
#define LCD_DC PB1
#define LCD_CS PB0
// #define LCD_MOSI PA7
// #define LCD_SCLK PA5
// #define LCD_RES PA12
// #define LCD_DC PB1
// #define LCD_CS PB0
#define THERM_CS PB4
#define THERM_SO PB5

View File

@@ -1,33 +1,29 @@
#include "lcd.h"
// void initLCD(void)
// {
// }
// void handleLCD(void)
// {
// }
unsigned int rainbow(byte value);
#include <TFT_eSPI.h> // Include the graphics library
TFT_eSPI tft = TFT_eSPI(); // Create object "tft"
TFT_eSprite touch_spr = TFT_eSprite(&tft);
#define WIDTH 240
#define HEIGHT 60
// -------------------------------------------------------------------------
// Setup
// -------------------------------------------------------------------------
void prep_sprite(void)
{
touch_spr.createSprite(WIDTH,HEIGHT);
}
void initLCD(void) {
tft.init();
tft.setRotation(0);
tft.setTextFont(1);
tft.setRotation(2);
tft.setTextFont(2);
tft.fillScreen(TFT_BLACK);
tft.invertDisplay(false);
prep_sprite();
}
// -------------------------------------------------------------------------
@@ -35,7 +31,16 @@ void initLCD(void) {
// -------------------------------------------------------------------------
void handleLCD()
{
//tft.setTextColor(TFT_WHITE);
//tft.setTextPadding(60);
tft.drawString("hello World!", 10, 10);
}
touch_spr.fillSprite(TFT_BLACK);
uint16_t t_x = 0, t_y = 0;
touch_spr.setTextColor(TFT_WHITE);
touch_spr.setTextDatum(MC_DATUM);
bool pressed = tft.getTouch(&t_x, &t_y);
String touchxy = "touch x=";
touchxy += t_x;
touchxy += ",touch y=";
touchxy += t_y;
touch_spr.drawString(touchxy, WIDTH / 2, HEIGHT / 4, 2);
touch_spr.drawNumber(getLooptime(), WIDTH / 2, (HEIGHT / 4)*2, 2);
touch_spr.pushSprite(1,1);
}

View File

@@ -1,6 +1,8 @@
#include "Arduino.h"
#include "board.h"
#include "status.h"
void initLCD(void);

View File

@@ -5,6 +5,7 @@
#include "thermo.h"
#include "button.h"
#include "heater.h"
#include "status.h"
void setup()
{
@@ -13,10 +14,11 @@ void setup()
initThermo();
initButton();
initHeater();
pinMode(LED_BUILTIN, OUTPUT);
initStatus();
}
void loop()
{
// put your main code here, to run repeatedly:
@@ -24,9 +26,5 @@ void loop()
handleThermo();
handleButton();
handleHeater();
digitalWrite(LED_BUILTIN, 1);
delay(500);
digitalWrite(LED_BUILTIN, 0);
delay(500);
handleStatus();
}

View File

@@ -0,0 +1,32 @@
#include "status.h"
uint64_t timelast = 0;
uint64_t blinkrate = 500;
bool ledstate = false;
uint32_t looptime = 0;
uint32_t looptimelast = 0;
void initStatus(void)
{
pinMode(LED_BUILTIN, OUTPUT);
}
void handleStatus(void)
{
uint64_t timenow = millis();
if(timenow - timelast > blinkrate)
{
timelast = timenow;
ledstate = !ledstate;
digitalWrite(LED_BUILTIN, ledstate);
}
looptime = timenow - looptimelast;
looptimelast = timenow;
}
uint32_t getLooptime(void)
{
return looptime;
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include "Arduino.h"
#include "board.h"
void initStatus(void);
void handleStatus(void);
uint32_t getLooptime(void);