I'm using Itead Nextion with Arduino. I added a slider in Nextion display. But I can't get value from the slider and I am getting "recvRetNumber err" this error. How can I solve this? Can you help me? Also I'm using Nextion Stable version (0.7.0).
My codes as follows:
#include <ArduinoJson.h>
#include "Nextion.h"
#include "NexButton.h"
#include "NexText.h"
#include "NexSlider.h"
#include <SoftwareSerial.h>
SoftwareSerial serial(6, 7);
NexButton BtnChangeRotation = NexButton(0, 2, "b0");
NexSlider SldPower = NexSlider(0, 1, "h0");
int drection = 0;
int pwr = 0;
char buffer[200];
DynamicJsonBuffer jsonBuffer(512);
JsonObject& root = jsonBuffer.createObject();
char jsonChar[100];
NexTouch *nex_listen_list[] =
{
&BtnChangeRotation,
&SldPower,
NULL
};
void SldPower_Callback(void *ptr)
{
SldPower.getValue(pwr);
root["direction"] = drection;
root["power"] = pwr;
root.printTo((char*)jsonChar, root.measureLength() + 1);
Serial.println(jsonChar);
serial.write(jsonChar);
}
void setup(void)
{
Serial.begin(9600);
serial.begin(9600);
root["direction"] = 0;
root["power"] = 0;
nexInit();
BtnChangeRotation.attachPop(BtnChangeRotation_Callback, &BtnChangeRotation);
SldPower.attachPop(SldPower_Callback);
}
void loop(void)
{
nexLoop(nex_listen_list);
}
Comments
Post a Comment