Welcome Guest! To enable all features please Login or Register.
Options
Go to last post Go to first unread
trom24  
#1 Posted : Thursday, June 15, 2017 1:08:42 PM(UTC)
trom24

Rank: Member

Groups: Registered
Joined: 6/8/2016(UTC)
Posts: 11

Thanks: 1 times
Was thanked: 7 time(s) in 7 post(s)
Hello again,

Still a newbee! I'm using v2.0.8.0

I have a code that needs a #define statement in declaration for custom node.
I get the error : Cannot use #define statements, use regular variable instead.

The thing is I dont know how to convert the #define statement to regular variable for this custom node to work!

Here is the native code in IDE that works:

#include <Nextion.h>

#define nextion Serial2

Nextion myNextion(nextion, 9600)

void setup() {
Serial.begin(9600);
myNextion.init();

}

void loop() {
String message = myNextion.listen();
if(message != ""){
Serial.println(message);
}

}

Here is the custom node HTML code :

Déclarations :
#include <Nextion.h>
#define nextion Serial2 // line that gives an error!

Startup :
myNextion.init();

Every Update :
String message = myNextion.listen();

if(message != "")
{
Output_MsgOut = message;
}

Thank you in advance!

EmbrioAdmin  
#2 Posted : Thursday, June 15, 2017 1:20:25 PM(UTC)
EmbrioAdmin

Rank: Administration

Groups: Administrators
Joined: 12/11/2014(UTC)
Posts: 661

Thanks: 1 times
Was thanked: 109 time(s) in 104 post(s)
I don't have the nextion.h files so I didn't try compiling it, but does this work? Copy and paste the text in the spoiler tag below into a node editor (this is an easier way to share Embrio nodes than writing out the text like you did).

I don't remember why you can't use a #define statement, I think it messed up the parsing that Embrio does when compiling. I'm not sure if there are cases where you have to use #define instead of a variable. Anyway I will add to my notes to relook at this to see if I can get #defines working.

If this doesn't work, could you paste back the node, but with the nextion references? Assuming you have added the .h and .cpp files to your controller (as seen on the bottom of this page), you can include the references in the copied XML by right clicking on the node and selecting "copy with references", then checking the references to include in the form that pops up.

thanks 1 user thanked EmbrioAdmin for this useful post.
sample@email.tst on 4/7/2024(UTC)
trom24  
#3 Posted : Friday, June 16, 2017 2:37:54 AM(UTC)
trom24

Rank: Member

Groups: Registered
Joined: 6/8/2016(UTC)
Posts: 11

Thanks: 1 times
Was thanked: 7 time(s) in 7 post(s)
Thanks for the quick response! I really appreciate it.

Your HTML code for custom node work fine! ;)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Notification

Icon
Error