Thank you for your answers
Sorry i dont get it. I have on my page0 my button initVal. There in the preinitialize event of the page0 i put the commands click initVal,1 click initVal,0.
So from my thoughts now, when i unplug/replug my nextion, uplouad my scetch oder visit page0 the button initVal should get triggered.
#include <Arduino.h>
#include <Nextion.h>
//SD-card
#include "FS.h"
#include "SD.h"
#include "SPI.h"
//RTC-clock
#include <Wire.h>
#include "RTClib.h"
//ESP32-Eprom
#include "EEPROM.h"
//Classes
#include <Classes.h>
//Clock
unsigned long Clocktimer = 1000; // Gibt an wie oft die Uhr ins Display geschrieben wird
unsigned long startChrono_clock;
char tempString[100];
/********Objecte*********/
RTC_DS3231 rtc;
/****** Definition of NEXTION-objects*******/
//Other Objects
NexButton initValStart = NexButton(0, 2, "initVal"); //page initialization
NexPage displayInit = NexPage(11, 0, "Display");
NexPage displayInitdd = NexPage(6, 0, "Messintervall");
// Zeit
NexText Zeit = NexText(2, 5, "Zeit");
//page Display
NexNumber brigtNs = NexNumber(11, 7, "n0");
//page Time
NexButton speichernTime = NexButton(9, 3, "b1");
NexNumber tag = NexNumber(9,5,"n0");
NexNumber monat = NexNumber(9,7,"n1");
NexNumber jahr = NexNumber(9,8,"n2");
NexNumber stunden = NexNumber(9,9,"n3");
NexNumber minuten = NexNumber(9,10,"n4");
NexNumber sekunden = NexNumber(9,11,"n5");
//page Intervall
NexNumber Zeitintervall_sek = NexNumber(6, 7, "n0"); //sekunden
NexNumber Zeitintervall_min = NexNumber(6, 8, "n1"); //minuten
NexNumber Zeitintervall_full = NexNumber(5, 9, "n2"); //Zeitintervall
/******Declaration of Nextion-Callbacks********/
void initValStartPopCallback(void *ptr);
void displayInitPopCallback(void *ptr);
void speichernTimePopCallback(void *ptr);
/**** all Nextion objects that need to be listened */
NexTouch *nex_listen_list[] =
{
//buttons
&initValStart,
//pages
&displayInit,
&speichernTime,
NULL
};
void SaveSettings()
{
//Display
uint32_t tbrightness;
brigtNs.getValueGlobal("Display",&tbrightness);
currentSettings.brigtness = tbrightness;
Serial.println(currentSettings.brigtness);
//Messintervall
uint32_t tsecondMi;
Zeitintervall_sek.getValueGlobal("Messintervall",&tsecondMi);
currentSettings.secondMi = tsecondMi;
uint32_t tminuteMi;
Zeitintervall_min.getValueGlobal("Messintervall",&tminuteMi);
currentSettings.minuteMi = tminuteMi;
uint32_t tfullMi;
Zeitintervall_full.getValueGlobal("Messintervall",&tfullMi);
currentSettings.fullMi = tfullMi;
}
/******Definition of Nextion-Callbacks*****/
//Init-button. Will be clicked automaticly to initialize saved values from ESP32 EPROM
void initValStartPopCallback(void *ptr)
{
uint32_t f;
brigtNs.getValueGlobal("Display",&f);
currentSettings.brigtness = f;
Serial.println("lllll");
}
void displayInitPopCallback(void *ptr)
{
uint32_t tbrightness;
brigtNs.getValueGlobal("Display",&tbrightness);
currentSettings.brigtness = tbrightness;
Serial.println("HHHHH");
}
void speichernTimePopCallback(void *ptr)
{
uint32_t stag;
uint32_t smonat;
uint32_t sjahr;
uint32_t sstunden;
uint32_t sminuten;
uint32_t ssekunden;
tag.getValue(&stag);
monat.getValue(&smonat);
jahr.getValue(&sjahr);
stunden.getValue(&sstunden);
minuten.getValue(&sminuten);
sekunden.getValue(&ssekunden);
rtc.adjust(DateTime(sjahr, smonat, stag, sstunden, sminuten, ssekunden));
Serial2.print("vis t2,1");
Serial2.write(0xff);
Serial2.write(0xff);
Serial2.write(0xff);
}
void setup() {
nexInit();
//Serial COM
Serial.begin(9600);
// while the serial stream is not open, do nothing:
while (!Serial) ;
Serial2.begin(9600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, lets set the time!");
// following line sets the RTC to the date & time this sketch was compiled
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
//rtc.adjust(DateTime(2019, 6, 13, 13, 33, 0));
}
//SaveSettings();
startChrono_clock = millis();
// put your setup code here, to run once:
initValStart.attachPop(initValStartPopCallback);
displayInit.attachPop(displayInitPopCallback);
speichernTime.attachPop(speichernTimePopCallback);
}
void loop() {
// put your main code here, to run repeatedly:
DateTime now = rtc.now();
if (millis() - startChrono_clock >= Clocktimer)
{
sprintf(tempString, "%02d.%02d.%02d/%02d:%02d:%02d",now.day(),now.month(),now.year(),now.hour(), now.minute(),now.second());
Zeit.setText(tempString);
startChrono_clock=millis();
}
/*
daysPast = now.unixtime()/86400UL;
if(serviceintervall > daysPast)
{
serviceInt.setValue((serviceintervall-daysPast));
}
else
{
alarm1.setPic(5);
serviceInt.setValue(0);
}
startChrono_clock=millis();
}*/
Serial.println(currentSettings.brigtness);
//Serial.println(currentSettings.secondMi);
//Serial.println(currentSettings.minuteMi);
//Serial.println(currentSettings.fullMi);
nexLoop(nex_listen_list);
delay(1000);
}
but
void initValStartPopCallback(void *ptr)
{
uint32_t f;
brigtNs.getValueGlobal("Display",&f);
currentSettings.brigtness = f;
Serial.println("lllll");
}
the buttons just does that what i am expecting when i touch it on my display. But isnt doing anything when i visit page0.
What do i miss?
PerryBebbington:
Not quite, you need to use:
You can't use 'half' a click, a complete click is click (1) followed buy 'unclick' (0), otherwise the Nextion doesn't respond as you'd expect.
No sir, it isnt about that. the delay is realy just here because this scetch is just for learning purpose, and i dont see why the delay should cause my problems. Shouldnt be disrespectfull or anything.