Hello
I have Nextion touch screen. In my project, i have 12 button to touch on screen, 10 numbers, one dot(.) and one OK button. Like in the picture:
For every pressing to the buttons, i am getting a char from serial and I change this char to integer value with this code below:
int number = msg5 - '0'; // Change char to int value
For the numbers, i am getting numbers(for 1<<1,2<<2....9<<9,0<<0), for the "dot(.)" i am having 50 and for the "OK" button 51.
I want to make the numbers entered equal the any integer value like example below:
int x = ( Number entered from touch screen). For 1 digit, it is ok but for multi-digit, not. I want to enter 256, 256.7 or 1889 etc... and after pressing "OK" want to this number equal to my integer value in arduino.. Below code, i can store the numbers entered in Array, but the rest is the problem.
/* Adress Information
* Motor1 (0,1) << X (1,1) << X^2 (1,2) << X^3 (1,3) << X^4 (1,4) << X^5 (1,5)
* Motor2 (0,2) << X (2,1) << X^2 (2,2) << X^3 (2,3) << X^4 (2,4) << X^5 (2,5)
* Motor3 (0,3) << X (3,1) << X^2 (3,2) << X^3 (3,3) << X^4 (3,4) << X^5 (3,5)
* Motor4 (0,4) << X (4,1) << X^2 (4,2) << X^3 (4,3) << X^4 (4,4) << X^5 (4,5)
* Motor5 (0,5) << X (5,1) << X^2 (5,2) << X^3 (5,3) << X^4 (5,4) << X^5 (5,5)
*/
#include <SoftwareSerial.h>
#include <Nextion.h>
SoftwareSerial nextion(2, 3); // Nextion Tx to 3, Rx to 2
Nextion myNextion(nextion, 9600); // Create a Nextion object named myNextion using the nextion serial port @ 9600bps
int x = 5; // Number that powered
int stp1,stp2,stp3,stp4,stp5; // Steps Results
int i = 0;
String message; //the last message
char msg3, msg5; //the values parsed from a message
int messages[10];
int buffers[10];
int rnumb;
void setup() {
Serial.begin(9600); // Start serial communication
myNextion.init(); // Initialize nextion
}
void loop() {
setMsgChar(); // Call the Function
}
void setMsgChar()
{
message = myNextion.listen(); // Listen serial communication
if(message !=""){ // If message is received
msg5 = message[5]; // Get only the 5. char
int number = msg5 - '0'; // Change char to int value
messages[i] = number; i++; // Save number into array
if(msg5 == 'a') // For 0 ( Zero )
{
number = 0;
}
Serial.println(number); // Print the number incoming
if(msg5 == 'c') // If OK is pressed. ( Not neccesary to change to Integer value )
{
Serial.println("Number Entered");
}
}
}
Any suggestion, idea or comment ???
Thank you
Best Regards.