Advertisement
pleasedontcode

"Microcontroller Control" rev_01

Sep 26th, 2024
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 19.45 KB | None | 0 0
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Microcontroller Control"
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-09-26 22:59:06
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Enhance the code functionality by integrating */
  21.     /* specific libraries for sensor data processing and */
  22.     /* communication protocols to ensure seamless */
  23.     /* interaction with connected components. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <SoftwareSerial.h>
  28. #include <Adafruit_GFX.h>    // Core graphics library
  29. #include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
  30. #include <EEPROM.h>
  31. #include <WiFi.h>           // Include WiFi library for communication
  32. #include <DHT.h>            // Include DHT sensor library for temperature and humidity
  33. #include <AllThingsTalk_WiFi.h> // Include AllThingsTalk library for enhanced communication
  34.  
  35. /****** FUNCTION PROTOTYPES *****/
  36. void setup(void);
  37. void loop(void);
  38.  
  39. // HC12 connections
  40. #define HC12_TX   16  // --> HC-12 TX Pin (GPIO16)
  41. #define HC12_RX   17  // --> HC-12 RX Pin (GPIO17)
  42. EspSoftwareSerial::UART HC12(HC12_TX, HC12_RX);
  43.  
  44. // ST7789 TFT module connections
  45. #define TFT_DC    21  // TFT DC pin is connected to GPIO21
  46. #define TFT_RST   22  // TFT RST pin is connected to GPIO22
  47. #define TFT_CS    -1  // TFT CS pin is not used
  48.  
  49. // initialize ST7789 TFT library with hardware SPI module
  50. Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
  51.  
  52. // DHT Sensor setup
  53. #define DHTPIN 4          // Pin where the DHT sensor is connected
  54. #define DHTTYPE DHT11     // DHT 11 (change to DHT22 if using that sensor)
  55. DHT dht(DHTPIN, DHTTYPE); // Create an instance of the DHT sensor
  56.  
  57. // AllThingsTalk WiFi credentials
  58. auto wifiCreds   = WifiCredentials("Your-WiFi-SSID", "Your-WiFi-Password"); // Replace with your WiFi credentials
  59. auto deviceCreds = DeviceConfig("Your-Device-ID", "Your-Device-Token");     // Replace with your Device ID and Token
  60. auto device      = Device(wifiCreds, deviceCreds);                           // Create "device" object
  61.  
  62. // KY040 - Set encoder pins as inputs
  63. #define CLK 10 // GPIO10 --> D10
  64. #define DT 34  // GPIO34 (input only)
  65. #define SW 35  // GPIO35 (input only)
  66.  
  67. #define SHORT_PRESS_TIME  50
  68. #define ROTARY_FAST        10 // [ms] rotary speed fast
  69. #define ROTARY_SLOW       200 // [ms] rotary speed slow
  70. #define INCREMENT_SLOW      1
  71. #define INCREMENT_FAST     10
  72.  
  73. int counter = 0;
  74. int currentStateCLK;
  75. int lastStateCLK;
  76. unsigned long lastButtonPress = 0;
  77. unsigned long lastButtonReleased = 0;
  78. unsigned long enc_rotated_time = 0;
  79. bool buttonPressed = false;
  80.  
  81. // Display data for sleep
  82. #define TIME_TO_DISPLAY_OFF 10000 // 10s
  83. bool displayOff = false;
  84. bool requestToTurnOnDisplay = true;
  85. unsigned long lastTimeDisplayOff = millis();
  86.  
  87. // STATE MACHINE
  88.  
  89. // CURRENT_PAGE state
  90. #define LONG_PRESS_TIME 10000 // Long press time in milliseconds
  91. unsigned long lastButtonLongPress = 0;
  92. // WAIT to move to MAIN_PAGE
  93. #define DELAY_TIME 2000
  94. unsigned long waitToMoveMainPageTime = 0;
  95.  
  96. // SETUP_COMPLETE_PAGE state
  97. #define COMPLETE_DISPLAY_TIME 3000 // Time to display setup complete page in milliseconds
  98. unsigned long lastCompleteDisplayTime = 0;
  99.  
  100. // Define states
  101. enum State {
  102.   START_PAGE,
  103.   WAIT_TO_MOVE_MAIN_PAGE,
  104.   MAIN_PAGE,
  105.   DEBOUNCING_SETTING_LOWER_BOUND_PAGE,
  106.   SETTING_LOWER_BOUND_PAGE,
  107.   DEBOUNCING_SETTING_UPPER_BOUND_PAGE,
  108.   SETTING_UPPER_BOUND_PAGE,
  109.   SETUP_COMPLETE_PAGE
  110. };
  111.  
  112. enum MAIN_State {
  113.   HC12READ,
  114.   ENCODER_SW_UPDATE,
  115.   ENCODER_KNOB_UPDATE,
  116.   DISPLAY_UPDATE,
  117.   HC12WRITE,
  118.   EEPROM_WRITE,
  119.   DISPLAY_OFF
  120. };
  121.  
  122. State currentState = START_PAGE;
  123. MAIN_State mainState = HC12READ;
  124.  
  125. #define MIN_CURRENT 0
  126. #define MAX_CURRENT 500
  127.  
  128. int current_setpoint      = MIN_CURRENT;
  129. int min_current_setpoint  = MIN_CURRENT;
  130. int max_current_setpoint  = MAX_CURRENT;
  131.  
  132. #define EEPROM_DATA_UPDATE_TIME 10000
  133.  
  134. typedef struct eeprom_data {
  135.   int current_setpoint;
  136.   int min_current_setpoint;
  137.   int max_current_setpoint;
  138. } EEPROM_DATA;
  139.  
  140. EEPROM_DATA myEEPROMData;
  141.  
  142. int current_feedback      = -1;
  143.  
  144. bool receiverDisconnected = true;
  145. #define RECEIVER_DISCONNECTED_TIME 5000
  146.  
  147. #define HC12_DATA_REPETITION_TIME 1000
  148.  
  149. volatile bool readDataEncoder = false;
  150.  
  151. void IRAM_ATTR rotaryEncoderStatus() {
  152.   readDataEncoder = true;
  153. }
  154.  
  155. void updateRotaryEncoderStatus() {
  156.   if(readDataEncoder == true) {
  157.     // Read the current state of CLK
  158.     currentStateCLK = digitalRead(CLK);
  159.  
  160.     // If last and current state of CLK are different, then pulse occurred
  161.     // React to only 1 state change to avoid double count
  162.     if (currentStateCLK != lastStateCLK  && currentStateCLK == 1) {
  163.       // If the DT state is different than the CLK state then
  164.       // the encoder is rotating CCW so decrement
  165.       int dt = digitalRead(DT); // Changed to digitalRead for compatibility
  166.       if (dt != currentStateCLK) {
  167.         if((millis() - enc_rotated_time) > ROTARY_SLOW) {
  168.           counter = INCREMENT_SLOW;  
  169.         }
  170.         else if((millis() - enc_rotated_time) > ROTARY_FAST) {
  171.           counter = INCREMENT_FAST;  
  172.         }
  173.         enc_rotated_time = millis();
  174.         funcRequestToTurnOnDisplay();
  175.       } else {
  176.         // Encoder is rotating CW so increment
  177.         if((millis() - enc_rotated_time) > ROTARY_SLOW) {
  178.           counter = -INCREMENT_SLOW;  
  179.         }
  180.         else if((millis() - enc_rotated_time) > ROTARY_FAST) {
  181.           counter = -INCREMENT_FAST;  
  182.         }
  183.         enc_rotated_time = millis();
  184.         funcRequestToTurnOnDisplay();
  185.       }
  186.     }
  187.  
  188.     // Remember last CLK state
  189.     lastStateCLK = currentStateCLK;
  190.  
  191.     readDataEncoder = false;  
  192.   }
  193. }
  194.  
  195. void updateSwitchRotaryEncoder() {
  196.   int btnState = digitalRead(SW);
  197.  
  198.   // If we detect LOW signal, button is pressed
  199.   if (buttonPressed == false && btnState == LOW) {
  200.     if (millis() - lastButtonPress > SHORT_PRESS_TIME) {
  201.       Serial.println("Button pressed!");
  202.       buttonPressed = true;
  203.       funcRequestToTurnOnDisplay();
  204.     }
  205.   }
  206.   else if(buttonPressed == true && btnState != LOW) {
  207.     if (millis() - lastButtonReleased > SHORT_PRESS_TIME) {
  208.       Serial.println("Button released!");
  209.       buttonPressed = false;
  210.       funcRequestToTurnOnDisplay();
  211.     }
  212.   }
  213.   else {
  214.     lastButtonPress = millis();
  215.     lastButtonReleased = millis();
  216.   }
  217. }
  218.  
  219. void readEEPROMData() {
  220.   EEPROM.begin(sizeof(myEEPROMData));  // Initialize EEPROM
  221.   EEPROM.get(0x00, myEEPROMData);
  222.   if(myEEPROMData.current_setpoint < MIN_CURRENT || myEEPROMData.current_setpoint > MAX_CURRENT) {
  223.     myEEPROMData.current_setpoint = MIN_CURRENT;
  224.   }
  225.   if(myEEPROMData.min_current_setpoint < MIN_CURRENT || myEEPROMData.min_current_setpoint > MAX_CURRENT || myEEPROMData.min_current_setpoint > myEEPROMData.max_current_setpoint) {
  226.     myEEPROMData.min_current_setpoint = MIN_CURRENT;
  227.   }
  228.   if(myEEPROMData.max_current_setpoint < MIN_CURRENT || myEEPROMData.max_current_setpoint > MAX_CURRENT || myEEPROMData.max_current_setpoint < myEEPROMData.min_current_setpoint) {
  229.     myEEPROMData.max_current_setpoint = MAX_CURRENT;
  230.   }
  231.   current_setpoint      = myEEPROMData.current_setpoint;
  232.   min_current_setpoint  = myEEPROMData.min_current_setpoint;
  233.   max_current_setpoint  = myEEPROMData.max_current_setpoint;
  234. }
  235.  
  236. void setup(void) {
  237.   Serial.begin(115200);
  238.   Serial.println("Hello");
  239.  
  240.   pinMode(CLK, INPUT_PULLUP);
  241.   pinMode(DT, INPUT_PULLUP);
  242.   pinMode(SW, INPUT_PULLUP);
  243.  
  244.   readEEPROMData();
  245.  
  246.   // Initialize ST7789 display 240x240 pixel
  247.   tft.init(240, 240, SPI_MODE3);
  248.   tft.setRotation(2); // if the screen is flipped, remove this command
  249.  
  250.   HC12.begin(9600);
  251.  
  252.   // Initialize DHT sensor
  253.   dht.begin(); // Start the DHT sensor
  254.  
  255.   // Initialize AllThingsTalk
  256.   device.init(); // Initialize AllThingsTalk communication
  257.  
  258.   // Attach interrupts to rotary encoder pins
  259.   attachInterrupt(digitalPinToInterrupt(CLK), rotaryEncoderStatus, CHANGE);
  260. }
  261.  
  262. void loop() {
  263.   updateTaskStateMachine();
  264.   readDHTSensor(); // Read DHT sensor data in the loop
  265.   device.loop(); // Keep AllThingsTalk & WiFi alive
  266. }
  267.  
  268. void readDHTSensor() {
  269.   // Read temperature and humidity
  270.   float h = dht.readHumidity();
  271.   float t = dht.readTemperature(); // Read temperature as Celsius
  272.  
  273.   // Check if any reads failed and exit early (to try again).
  274.   if (isnan(h) || isnan(t)) {
  275.     Serial.println("Failed to read from DHT sensor!");
  276.     return;
  277.   }
  278.  
  279.   // Print the values to Serial Monitor
  280.   Serial.print("Humidity: ");
  281.   Serial.print(h);
  282.   Serial.print(" %\t");
  283.   Serial.print("Temperature: ");
  284.   Serial.print(t);
  285.   Serial.println(" *C");
  286.  
  287.   // Send DHT sensor data to AllThingsTalk
  288.   device.send("dht-humidity", h);
  289.   device.send("dht-temperature", t);
  290. }
  291.  
  292. void updateTaskStateMachine() {
  293.   switch(mainState) {
  294.     case HC12READ:
  295.       receiveDataOverHC12();
  296.       mainState = ENCODER_SW_UPDATE;
  297.       break;
  298.  
  299.     case ENCODER_SW_UPDATE:
  300.       updateSwitchRotaryEncoder();
  301.       mainState = ENCODER_KNOB_UPDATE;
  302.       break;
  303.  
  304.     case ENCODER_KNOB_UPDATE:
  305.       updateRotaryEncoderStatus();
  306.       mainState = DISPLAY_UPDATE;
  307.       break;
  308.  
  309.     case DISPLAY_UPDATE:
  310.       updateDisplayStateMachine();
  311.       mainState = HC12WRITE;
  312.       break;
  313.  
  314.     case HC12WRITE:
  315.       sendDataOverHC12();
  316.       mainState = EEPROM_WRITE;
  317.       break;
  318.    
  319.     case EEPROM_WRITE:
  320.       updateEEPROMData();
  321.       mainState = DISPLAY_OFF;
  322.       break;
  323.    
  324.     case DISPLAY_OFF:
  325.       displaySleep();
  326.       mainState = HC12READ;
  327.       break;
  328.  
  329.     default:
  330.       Serial.println("error mainState");
  331.       break;
  332.   }
  333. }
  334.  
  335. void updateDisplayStateMachine() {
  336.   // Handle state-specific actions
  337.   switch (currentState) {
  338.     case START_PAGE:
  339.       // tft.drawRGBBitmap(0,0, image, 240, 240); // Uncomment if image is defined
  340.       waitToMoveMainPageTime = millis();
  341.       currentState = WAIT_TO_MOVE_MAIN_PAGE;
  342.       break;
  343.  
  344.     case WAIT_TO_MOVE_MAIN_PAGE:
  345.       if(millis() - waitToMoveMainPageTime > DELAY_TIME) {
  346.         currentState = MAIN_PAGE;
  347.         clearScreen();
  348.       }
  349.       break;
  350.  
  351.     case MAIN_PAGE:
  352.       updateSetpoint();
  353.       displayCurrentPage();
  354.       if(buttonPressed == true) {
  355.         if ((millis() - lastButtonLongPress) > LONG_PRESS_TIME) {
  356.           currentState = DEBOUNCING_SETTING_LOWER_BOUND_PAGE;
  357.           clearScreen();
  358.         }
  359.       } else {
  360.         lastButtonLongPress = millis();
  361.       }
  362.       break;
  363.  
  364.     case DEBOUNCING_SETTING_LOWER_BOUND_PAGE:
  365.       updateMinSetpoint();
  366.       displaySettingLowerBoundPage();
  367.       if(buttonPressed == false) {
  368.         currentState = SETTING_LOWER_BOUND_PAGE;
  369.       }
  370.       break;
  371.  
  372.     case SETTING_LOWER_BOUND_PAGE:
  373.       updateMinSetpoint();
  374.       displaySettingLowerBoundPage();
  375.       if(buttonPressed == true) {
  376.         currentState = DEBOUNCING_SETTING_UPPER_BOUND_PAGE;
  377.         clearScreen();
  378.       }
  379.       break;
  380.  
  381.     case DEBOUNCING_SETTING_UPPER_BOUND_PAGE:
  382.       updateMaxSetpoint();
  383.       displaySettingUpperBoundPage();
  384.       if(buttonPressed == false) {
  385.         currentState = SETTING_UPPER_BOUND_PAGE;
  386.       }
  387.       break;
  388.  
  389.     case SETTING_UPPER_BOUND_PAGE:
  390.       updateMaxSetpoint();
  391.       displaySettingUpperBoundPage();
  392.       if(buttonPressed == true) {
  393.         currentState = SETUP_COMPLETE_PAGE;
  394.         lastCompleteDisplayTime = millis();
  395.         clearScreen();
  396.       }
  397.       break;
  398.  
  399.     case SETUP_COMPLETE_PAGE:
  400.       displaySetupCompletePage();
  401.       if(millis() - lastCompleteDisplayTime > COMPLETE_DISPLAY_TIME) {
  402.         currentState = MAIN_PAGE;
  403.         clearScreen();
  404.       }
  405.       break;
  406.  
  407.     default:
  408.       Serial.println("error machine state");
  409.       break;
  410.   }
  411. }
  412.  
  413. void displaySleep() {
  414.   if(requestToTurnOnDisplay == true) {
  415.     lastTimeDisplayOff = millis();
  416.   }
  417.  
  418.   if(millis() - lastTimeDisplayOff > TIME_TO_DISPLAY_OFF && displayOff == false) {
  419.     displayOff = true;
  420.     turnOffDisplay();
  421.     Serial.println("TURN OFF DISPLAY");
  422.   }
  423.   else if (displayOff == true && requestToTurnOnDisplay == true) {
  424.     displayOff = false;
  425.     turnOnDisplay();
  426.     Serial.println("TURN ON DISPLAY");
  427.   }
  428.  
  429.   requestToTurnOnDisplay = false;
  430. }
  431.  
  432. void funcRequestToTurnOnDisplay() {
  433.   requestToTurnOnDisplay = true;
  434. }
  435.  
  436. void turnOffDisplay() {
  437.   tft.writeCommand(ST77XX_DISPOFF);  // Turn off display
  438.   tft.writeCommand(ST77XX_SLPIN);    // Enter sleep mode
  439. }
  440.  
  441. void turnOnDisplay() {
  442.   tft.writeCommand(ST77XX_SLPOUT);   // Exit sleep mode
  443.   tft.writeCommand(ST77XX_DISPON);   // Turn on display
  444. }
  445.  
  446. void updateEEPROMData() {
  447.   static unsigned long lastTimeUpdateData = millis();
  448.   if(millis() - lastTimeUpdateData > EEPROM_DATA_UPDATE_TIME) {
  449.     if( current_setpoint != myEEPROMData.current_setpoint || min_current_setpoint != myEEPROMData.min_current_setpoint || max_current_setpoint != myEEPROMData.max_current_setpoint) {
  450.       myEEPROMData.current_setpoint     = current_setpoint;
  451.       myEEPROMData.min_current_setpoint = min_current_setpoint;
  452.       myEEPROMData.max_current_setpoint = max_current_setpoint;
  453.       EEPROM.put(0x00, myEEPROMData);
  454.       EEPROM.commit();
  455.       Serial.println("EEPROM updated");
  456.       lastTimeUpdateData = millis();
  457.     }
  458.     lastTimeUpdateData = millis();
  459.   }
  460. }
  461.  
  462. void sendDataOverHC12() {
  463.   static unsigned long lastTimeSendData = millis();
  464.  
  465.   if(millis() - lastTimeSendData > HC12_DATA_REPETITION_TIME) {
  466.     // Send the string over HC-12
  467.     HC12.println(String(current_setpoint));
  468.  
  469.     lastTimeSendData = millis();
  470.     Serial.print("TX: ");
  471.     Serial.println(current_setpoint);
  472.   }
  473. }
  474.  
  475. void receiveDataOverHC12() {
  476.   static unsigned long lastReceivedPacketTime = millis();
  477.   if (HC12.available()) {
  478.     // Read until the end of the line (until '\n')
  479.     String receivedData = HC12.readStringUntil('\n');
  480.  
  481.     // Split the received data into separate variables
  482.     current_feedback = receivedData.toInt();
  483.     Serial.print("RX: ");
  484.     Serial.println(current_feedback);
  485.  
  486.     lastReceivedPacketTime = millis();
  487.     receiverDisconnected = false;
  488.   }
  489.  
  490.   if (millis() - lastReceivedPacketTime > RECEIVER_DISCONNECTED_TIME) {
  491.     receiverDisconnected = true;
  492.   }
  493. }
  494.  
  495. void updateSetpoint() {
  496.   if(counter > 0) {
  497.     Serial.print("+");
  498.     Serial.println(counter);
  499.     current_setpoint = min(current_setpoint + counter, max_current_setpoint);
  500.     counter = 0;
  501.   } else if(counter < 0) {
  502.     Serial.println(counter);
  503.     current_setpoint = max(current_setpoint + counter, min_current_setpoint);
  504.     counter = 0;
  505.   }
  506. }
  507.  
  508. void updateMinSetpoint() {
  509.   if(counter > 0) {
  510.     Serial.print("+");
  511.     Serial.println(counter);
  512.     min_current_setpoint = min(min_current_setpoint + counter, max_current_setpoint);
  513.     current_setpoint = max(current_setpoint, min_current_setpoint);
  514.     counter = 0;
  515.   } else if(counter < 0) {
  516.     Serial.println(counter);
  517.     min_current_setpoint = max(min_current_setpoint + counter, MIN_CURRENT);
  518.     current_setpoint = max(current_setpoint, min_current_setpoint);
  519.     counter = 0;
  520.   }
  521. }
  522.  
  523. void updateMaxSetpoint() {
  524.   if(counter > 0) {
  525.     Serial.print("+");
  526.     Serial.println(counter);
  527.     max_current_setpoint = min(max_current_setpoint + counter, MAX_CURRENT);
  528.     current_setpoint = min(current_setpoint, max_current_setpoint);
  529.     counter = 0;
  530.   } else if(counter < 0) {
  531.     Serial.println(counter);
  532.     max_current_setpoint = max(max_current_setpoint + counter, min_current_setpoint);
  533.     current_setpoint = min(current_setpoint, max_current_setpoint);
  534.     counter = 0;
  535.   }
  536. }
  537.  
  538. bool fillOneTime = true;
  539. bool displayReceiverDisconnected = false;
  540.  
  541. void clearScreen() {
  542.   tft.fillScreen(ST77XX_BLACK);
  543.   fillOneTime = true;
  544.   displayReceiverDisconnected = false;
  545. }
  546.  
  547. void displayCurrentPage() {
  548.   static int temp_current_setpoint = -1000;
  549.   static int temp_current_feedback = -1000;
  550.  
  551.   if(current_setpoint != temp_current_setpoint || fillOneTime) {
  552.     tft.fillRect(0, 30, 240, 80, ST77XX_BLACK);  // Clear the top portion of the screen
  553.     tft.setTextColor(ST77XX_BLUE);
  554.     tft.setTextSize(10);
  555.     tft.setCursor(30, 30); // Set cursor to the beginning of the first line
  556.     tft.print((float)current_setpoint, 0);  // Print the current value with 0 decimal places
  557.  
  558.     temp_current_setpoint = current_setpoint;
  559.   }
  560.   if(fillOneTime == true) {
  561.     // Set cursor to the beginning of the second line
  562.     tft.setCursor(0, 120);  // Adjust '30' based on your text size and display dimensions
  563.     tft.setTextSize(10);
  564.     tft.print("AMPS");  // Print "AMPS" on the second line
  565.   }
  566.   if(current_feedback != temp_current_feedback || fillOneTime) {
  567.     tft.fillRect(0, 200, 80, 40, ST77XX_BLACK);  // Clear the portion of the screen
  568.     tft.setTextColor(ST77XX_YELLOW);
  569.     tft.setTextSize(2);
  570.     tft.setCursor(0, 200);
  571.     tft.print((float)current_feedback, 0);  // Print feedback
  572.  
  573.     temp_current_feedback = current_feedback;
  574.   }
  575.  
  576.   if(receiverDisconnected == true && displayReceiverDisconnected == false) {
  577.     tft.fillRect(80, 200, 160, 40, ST77XX_BLACK);  // Clear the portion of the screen
  578.     tft.setTextColor(ST77XX_YELLOW);
  579.     tft.setTextSize(2);
  580.     tft.setCursor(80, 200);
  581.     tft.print(F("DISCONNECTED"));  // Print feedback
  582.     displayReceiverDisconnected = true;
  583.   } else if(receiverDisconnected == false && displayReceiverDisconnected == true) {
  584.     tft.fillRect(80, 200, 160, 40, ST77XX_BLACK);  // Clear the portion of the screen
  585.     displayReceiverDisconnected = false;
  586.   }
  587.  
  588.   fillOneTime = false;
  589. }
  590.  
  591. void displaySettingLowerBoundPage() {
  592.   static int temp_min_current_setpoint = -1000;
  593.  
  594.   if(fillOneTime == true) {
  595.     tft.setTextColor(ST77XX_WHITE);
  596.     tft.setTextSize(2);
  597.     tft.setCursor(10, 10);
  598.     tft.print("SET LOWER BOUND");
  599.   }
  600.  
  601.   if(min_current_setpoint != temp_min_current_setpoint || fillOneTime) {
  602.     tft.fillRect(0, 30, 240, 80, ST77XX_BLACK);  // Clear the top portion of the screen
  603.     tft.setTextColor(ST77XX_BLUE);
  604.     tft.setTextSize(10);
  605.     tft.setCursor(30, 30); // Set cursor to the beginning of the first line
  606.     tft.print((float)min_current_setpoint, 0);  // Print the current value with 0 decimal places
  607.  
  608.     temp_min_current_setpoint = min_current_setpoint;
  609.   }
  610.   if(fillOneTime == true) {
  611.     // Set cursor to the beginning of the second line
  612.     tft.setCursor(0, 120);  // Adjust '30' based on your text size and display dimensions
  613.     tft.setTextSize(10);
  614.     tft.print("AMPS");  // Print "AMPS" on the second line
  615.   }
  616.  
  617.   fillOneTime = false;
  618. }
  619.  
  620. void displaySettingUpperBoundPage() {
  621.   static int temp_max_current_setpoint = -1000;
  622.  
  623.   if(fillOneTime == true) {
  624.     tft.setTextColor(ST77XX_WHITE);
  625.     tft.setTextSize(2);
  626.     tft.setCursor(10, 10);
  627.     tft.print("SET UPPER BOUND");
  628.   }
  629.  
  630.   if(max_current_setpoint != temp_max_current_setpoint || fillOneTime) {
  631.     tft.fillRect(0, 30, 240, 80, ST77XX_BLACK);  // Clear the top portion of the screen
  632.     tft.setTextColor(ST77XX_BLUE);
  633.     tft.setTextSize(10);
  634.     tft.setCursor(30, 30); // Set cursor to the beginning of the first line
  635.     tft.print((float)max_current_setpoint, 0);  // Print the current value with 0 decimal places
  636.  
  637.     temp_max_current_setpoint = max_current_setpoint;
  638.   }
  639.   if(fillOneTime == true) {
  640.     // Set cursor to the beginning of the second line
  641.     tft.setCursor(0, 120);  // Adjust '30' based on your text size and display dimensions
  642.     tft.setTextSize(10);
  643.     tft.print("AMPS");  // Print "AMPS" on the second line
  644.   }
  645.  
  646.   fillOneTime = false;
  647. }
  648.  
  649. void displaySetupCompletePage() {
  650.   if(fillOneTime == true) {
  651.     tft.setTextColor(ST77XX_WHITE);
  652.     tft.setTextSize(4);
  653.     tft.setCursor(10, 10);
  654.     tft.print("SETUP");
  655.     tft.setCursor(10, 80);
  656.     tft.print("COMPLETE");
  657.   }
  658.  
  659.   fillOneTime = false;
  660. }
  661.  
  662. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement