Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Nextion.h>
- #include <SoftwareSerial.h>
- // Define the RX and TX pins for the Nextion display
- SoftwareSerial nextionSerial(2, 3); // RX, TX
- // Define Nextion components on page 1 (SUMMARY)
- NexButton StartSesion = NexButton(1, 5, "StartSesion");
- NexText HandTX = NexText(1, 9, "HandTX");
- NexText MovementsTX = NexText(1, 10, "MovementsTX");
- NexText SpeedTX = NexText(1, 11, "SpeedTX");
- NexText RepetitionTX = NexText(1, 12, "RepetitionTX");
- // Array of Nextion components for event listening
- NexTouch *nex_listen_list[] = {
- &StartSesion,
- NULL
- };
- // Default values
- String currentHand = "Right";
- String currentMovement = "S: 45\u00B0-60\u00B0"; // Unicode for degree symbol
- int currentSpeed = 68; // Percentage
- int currentRepetition = 20; // Count
- // Function to handle StartSesion button press
- void StartSesionPopCallback(void *ptr) {
- Serial.println("Start session button pressed");
- // Placeholder for starting servo movement logic
- }
- void setup() {
- // Initialize Serial communication for debugging
- Serial.begin(9600);
- // Initialize the Nextion display serial communication (SoftwareSerial)
- nextionSerial.begin(9600); // Use the nextionSerial for Nextion communication
- nexInit(); // No arguments needed for nexInit()
- // Attach callbacks
- StartSesion.attachPop(StartSesionPopCallback, &StartSesion);
- // Set default text values on the Nextion display
- HandTX.setText(currentHand.c_str());
- MovementsTX.setText(currentMovement.c_str());
- char speedBuffer[10];
- sprintf(speedBuffer, "%d%%", currentSpeed);
- SpeedTX.setText(speedBuffer);
- char repetitionBuffer[10];
- sprintf(repetitionBuffer, "%dx", currentRepetition);
- RepetitionTX.setText(repetitionBuffer);
- }
- void loop() {
- // Listen for events from the Nextion display
- nexLoop(nex_listen_list);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement