Advertisement
Guest User

Untitled

a guest
Feb 10th, 2025
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | Help | 0 0
  1. #include <Nextion.h>
  2. #include <SoftwareSerial.h>
  3.  
  4. // Define the RX and TX pins for the Nextion display
  5. SoftwareSerial nextionSerial(2, 3); // RX, TX
  6.  
  7. // Define Nextion components on page 1 (SUMMARY)
  8. NexButton StartSesion = NexButton(1, 5, "StartSesion");
  9. NexText HandTX = NexText(1, 9, "HandTX");
  10. NexText MovementsTX = NexText(1, 10, "MovementsTX");
  11. NexText SpeedTX = NexText(1, 11, "SpeedTX");
  12. NexText RepetitionTX = NexText(1, 12, "RepetitionTX");
  13.  
  14. // Array of Nextion components for event listening
  15. NexTouch *nex_listen_list[] = {
  16. &StartSesion,
  17. NULL
  18. };
  19.  
  20. // Default values
  21. String currentHand = "Right";
  22. String currentMovement = "S: 45\u00B0-60\u00B0"; // Unicode for degree symbol
  23. int currentSpeed = 68; // Percentage
  24. int currentRepetition = 20; // Count
  25.  
  26. // Function to handle StartSesion button press
  27. void StartSesionPopCallback(void *ptr) {
  28. Serial.println("Start session button pressed");
  29. // Placeholder for starting servo movement logic
  30. }
  31.  
  32. void setup() {
  33. // Initialize Serial communication for debugging
  34. Serial.begin(9600);
  35.  
  36. // Initialize the Nextion display serial communication (SoftwareSerial)
  37. nextionSerial.begin(9600); // Use the nextionSerial for Nextion communication
  38. nexInit(); // No arguments needed for nexInit()
  39.  
  40. // Attach callbacks
  41. StartSesion.attachPop(StartSesionPopCallback, &StartSesion);
  42.  
  43. // Set default text values on the Nextion display
  44. HandTX.setText(currentHand.c_str());
  45. MovementsTX.setText(currentMovement.c_str());
  46. char speedBuffer[10];
  47. sprintf(speedBuffer, "%d%%", currentSpeed);
  48. SpeedTX.setText(speedBuffer);
  49. char repetitionBuffer[10];
  50. sprintf(repetitionBuffer, "%dx", currentRepetition);
  51. RepetitionTX.setText(repetitionBuffer);
  52. }
  53.  
  54. void loop() {
  55. // Listen for events from the Nextion display
  56. nexLoop(nex_listen_list);
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement