external nextion display example

This commit is contained in:
Siwat Sirichai 2023-09-30 16:29:16 +07:00
parent 6edef21351
commit 6ccbc32911
6 changed files with 38 additions and 18 deletions

View File

@ -222,8 +222,8 @@ bool nexInit(void)
bool ret1 = false;
bool ret2 = false;
dbSerialBegin(9600);
nexSerial.begin(9600);
//dbSerialBegin(9600);
nexSerial.begin(115200);
sendCommand("");
sendCommand("bkcmd=1");
ret1 = recvRetCommandFinished();

View File

@ -1,5 +1,5 @@
#include <external_lcd.hpp>
#include <espmega_iot_external_lcd.hpp>
void ExternalLCD::callTriggerFunction() {
uint8_t touch_hex = Serial2.read();
external_lcd_callback(touch_hex);
ext_lcd_callback(touch_hex);
}

View File

@ -5,7 +5,11 @@
#ifndef EXTERNAL_LCD_LOADED
#define EXTERNAL_LCD_LOADED
#include "user_code.hpp"
extern void ext_lcd_callback(int id);
class ExternalLCD: public EasyNex {
using EasyNex::EasyNex;
protected:
void callTriggerFunction();
};

View File

@ -1,21 +1,28 @@
#include <user_code.hpp>
void timer1_callback()
{
for (int i = 0; i < 16; i++)
{
pwm_set_state(i, 1);
}
}
ESPMega_Timer timer1(0, 50, timer1_callback, 15001);
//Display Componets
NexDSButton bt0 = NexDSButton(1, 2, "bt0");
NexTouch *nex_listen_list[] =
{
&bt0,
NULL
};
void bt0PopCallback(void *ptr)
{
Serial.println("BTN0!");
}
/*
This Code will run right after ESPMega PRO's
Peripheral Initialization Routine
*/
void user_pre_init()
{
nexInit();
}
/*
@ -28,7 +35,7 @@ void user_init()
ESPMega_EXTLCD.write(0xFF);
ESPMega_EXTLCD.write(0xFF);
ESPMega_EXTLCD.write(0xFF);
bt0.attachPop(bt0PopCallback, &bt0);
}
/*
@ -36,11 +43,10 @@ This code will run once every event loop
*/
void user_loop()
{
if(Serial2.available()) {
Serial.println(Serial2.read());
}
nexLoop(nex_listen_list);
}
/*
This code will run when an input pin changed state
*/
@ -48,8 +54,8 @@ void virtual_interrupt_user_callback(int pin, int state)
{
}
void pwm_changed_user_callback(int pin) {
void pwm_changed_user_callback(int pin)
{
}
/*
@ -62,3 +68,11 @@ void timer_tick_callback()
timer1.loop();
}
}
void timer1_callback()
{
for (int i = 0; i < 16; i++)
{
pwm_set_state(i, 1);
}
}

View File

@ -1,9 +1,10 @@
#pragma once
#include <ESPMegaPRO.h>
#include <EasyNextionLibrary.h>
#include <Nextion.h>
#include <PubSubClient.h>
#include <PubSubClientTools.h>
#include "espmega_iot_timer.hpp"
#include "espmega_iot_external_lcd.hpp"
// External LCD Configuration
#define ENABLE_EXTERNAL_LCD
@ -21,6 +22,7 @@ void user_loop();
void virtual_interrupt_user_callback(int pin, int state);
void pwm_changed_user_callback(int pin);
void timer_tick_callback();
void timer1_callback();
void bt0PopCallback(void *ptr);

Binary file not shown.