pleasedontcode

# LCD Menu rev_05

Jan 17th, 2026
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 10.00 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: # LCD Menu
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2026-01-17 17:18:41
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* buat progres THC_rotary bisa di kontrol  dan di */
  21.     /* monitor dengan web server real time */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24.  
  25. /* START CODE */
  26.  
  27. #include <LiquidCrystal_I2C.h>
  28. LiquidCrystal_I2C lcd(0x27, 16, 2);
  29.  
  30. //#include <Wire.h>
  31. //#include <LiquidCrystal_AIP31068_I2C.h>
  32. //LiquidCrystal_AIP31068_I2C lcd( 0x27, 16, 2 );
  33.  
  34. //#include <Wire.h>
  35. //#include <hd44780.h>                        // main hd44780 header
  36. //#include <hd44780ioClass/hd44780_I2Cexp.h>  // i2c expander i/o class header
  37. //hd44780_I2Cexp lcd(0x27);
  38.  
  39.  
  40. byte armsUpDn[8] = {
  41.   B00000,
  42.   B00100,
  43.   B01110,
  44.   B00100,
  45.   B00000,
  46.   B01110,
  47.   B00000,
  48.   B00000
  49. };
  50.  
  51. byte customUp[8] = {
  52.   B00100,
  53.   B01110,
  54.   B10101,
  55.   B00100,
  56.   B00100,
  57.   B00100,
  58.   B00100,
  59.   B00000
  60. };
  61. byte customDown[8] = {
  62.   B00100,
  63.   B00100,
  64.   B00100,
  65.   B00100,
  66.   B10101,
  67.   B01110,
  68.   B00100,
  69.   B00000
  70. };
  71.  
  72. // Function prototypes for program management
  73. void doProgramSet(int prg);
  74. void doLCDDefault();
  75. void doLCDMenu();
  76. void doLCDMenuSetup();
  77. void doLCDDelayTime();
  78. void doLCDHysreresis();
  79. void doLCDStartVoltage();
  80. void doLCDLoadDefault();
  81. void doLCDTest();
  82. void doTestUp();
  83. void doTestDown();
  84. void doLCDProgramSellect();
  85.  
  86. void Setup_LCD() {
  87.   // set up the LCD's number of columns and rows:
  88.     lcd.init(); //LiquidCrystal_I2C
  89.     lcd.backlight(); //LiquidCrystal_I2C
  90.  
  91.   //lcd.init(); //LiquidCrystal_AIP31068_I2C
  92.  
  93.   Wire.begin(21, 22); // GPIO 21 (SDA)   //  GPIO 22 (SCL)
  94.   //lcd.begin(16, 2);  //hd44780
  95.  
  96.   // create a new character
  97.   lcd.createChar(0, armsUpDn);
  98.   lcd.createChar(1, customUp);
  99.   lcd.createChar(2, customDown);
  100.  
  101.   lcd.setCursor(1, 0);
  102.   lcd.print("MEHMET IBRAHIM");
  103.   lcd.setCursor(3, 1);
  104.   lcd.print("Plasma THC");
  105.   delay(1500);
  106.   lcd.clear();
  107. }
  108.  
  109. void doLCD() {
  110.   if (show >= 2) {
  111.     show = 0;
  112.     switch (menu) {
  113.       case 0:
  114.         doLCDDefault();
  115.         break;
  116.       case 1:
  117.         doLCDMenu();
  118.         break;
  119.       case 11:
  120.         doLCDMenuSetup();
  121.         break;
  122.       case 111:
  123.         doLCDDelayTime();
  124.         break;
  125.       case 112:
  126.         doLCDHysreresis();
  127.         break;
  128.       case 113:
  129.         doLCDStartVoltage();
  130.         break;
  131.       case 114:
  132.         doLCDLoadDefault();
  133.         break;
  134.       case 12:
  135.         doLCDTest();
  136.         break;
  137.       case 115:
  138.         doTestUp();
  139.         break;
  140.       case 116:
  141.         doTestDown();
  142.         break;
  143.       case 13:
  144.         doLCDProgramSellect();
  145.         break;
  146.       case 121:
  147.         doProgramSet(1);
  148.         break;
  149.       case 122:
  150.         doProgramSet(2);
  151.         break;
  152.       case 123:
  153.         doProgramSet(3);
  154.         break;
  155.  
  156.       default:
  157.         doLCDDefault();
  158.     }
  159.   }
  160. }
  161.  
  162. // Program selection - this function is called from both LCD menu and web server
  163. void doProgramSet(int prg) {
  164.   if (prg == 1) {
  165.     SetVa = 0;
  166.     DTa = 1;
  167.     HySa = 2;
  168.     StVa = 3;
  169.     ReadDataProg_1();
  170.   } else if (prg == 2) {
  171.     SetVa = 4;
  172.     DTa = 5;
  173.     HySa = 6;
  174.     StVa = 7;
  175.     ReadDataProg_2();
  176.   } else {
  177.     SetVa = 8;
  178.     DTa = 9;
  179.     HySa = 10;
  180.     StVa = 11;
  181.     ReadDataProg_3();
  182.   }
  183.  
  184.   SaveData(100, prg);
  185.   program = prg;
  186.  
  187.   SetV = Param[0];
  188.   DT = Param[1];
  189.   HyS = Param[2];
  190.   StV = Param[3];
  191.   //Preset value for encoder;
  192.   encoderVal = SetV;
  193.   menu = 0;
  194. }
  195.  
  196. void doLCDDefault() {
  197.   if (encoderVal < 0) encoderVal = 0;
  198.   else if (encoderVal > 250) encoderVal = 250;
  199.   SetV = encoderVal;
  200.   if (SetV != oldValue) {
  201.     SaveData(SetVa, SetV);
  202.     oldValue = SetV;
  203.   }
  204.   lcd.setCursor(0, 0);
  205.   lcd.print("P ");
  206.  
  207.   if (digitalRead(outputUpPin) == HIGH) {
  208.     lcd.write(1);
  209.   } else {
  210.     lcd.print(" ");
  211.   }
  212.   lcd.print(" ");
  213.   lcd.setCursor(4, 0);
  214.   lcd.print("Set.V: ");
  215.   lcd.print(SetV);
  216.   lcd.print("   ");
  217.   lcd.setCursor(0, 1);
  218.   lcd.print(program);
  219.   lcd.print(" ");
  220.   if (digitalRead(outputDnPin) == HIGH) {
  221.     lcd.write(2);
  222.   } else {
  223.     lcd.print(" ");
  224.   }
  225.   lcd.print(" ");
  226.   lcd.setCursor(4, 1);
  227.   lcd.print("Arc.V: ");
  228.   lcd.print(ArcV / 10);
  229.   lcd.print("   ");
  230. }
  231. //Main menu
  232. void doLCDMenu() {
  233.   if (encoderVal < 0) encoderVal = 3;
  234.   pos = encoderVal % 4;
  235.   switch (pos) {
  236.     case 0:
  237.       lcd.setCursor(0, 0);
  238.       lcd.print("> Exit          ");
  239.       lcd.setCursor(0, 1);
  240.       lcd.print("  Program       ");
  241.       break;
  242.     case 1:
  243.       lcd.setCursor(0, 0);
  244.       lcd.print("> Program       ");
  245.       lcd.setCursor(0, 1);
  246.       lcd.print("  Setup         ");
  247.       break;
  248.     case 2:
  249.       lcd.setCursor(0, 0);
  250.       lcd.print("> Setup         ");
  251.       lcd.setCursor(0, 1);
  252.       lcd.print("  Test          ");
  253.       break;
  254.     case 3:
  255.       lcd.setCursor(0, 0);
  256.       lcd.print("> Test          ");
  257.       lcd.setCursor(0, 1);
  258.       lcd.print("  Exit       ");
  259.       break;
  260.   }
  261. }
  262. //Program
  263. void doLCDProgramSellect() {
  264.   if (encoderVal < 0) encoderVal = 3;
  265.   pos = abs(encoderVal % 4);
  266.   switch (pos) {
  267.     case 0:
  268.       lcd.setCursor(0, 0);
  269.       lcd.print(">> Exit         ");
  270.       lcd.setCursor(0, 1);
  271.       lcd.print("   Load Prog: 1 ");
  272.       break;
  273.     case 1:
  274.       lcd.setCursor(0, 0);
  275.       lcd.print(">> Load Prog: 1 ");
  276.       lcd.setCursor(0, 1);
  277.       lcd.print("   Load Prog: 2 ");
  278.       break;
  279.     case 2:
  280.       lcd.setCursor(0, 0);
  281.       lcd.print(">> Load Prog: 2 ");
  282.       lcd.setCursor(0, 1);
  283.       lcd.print("   Load Prog: 3 ");
  284.       break;
  285.     case 3:
  286.       lcd.setCursor(0, 0);
  287.       lcd.print(">> Load Prog: 3 ");
  288.       lcd.setCursor(0, 1);
  289.       lcd.print("   Exit         ");
  290.       break;
  291.   }
  292. }
  293. // Setup
  294. void doLCDMenuSetup() {
  295.   if (encoderVal < 0) encoderVal = 4;
  296.   pos = abs(encoderVal % 5);
  297.   switch (pos) {
  298.     case 0:
  299.       lcd.setCursor(0, 0);
  300.       lcd.print(">> Exit         ");
  301.       lcd.setCursor(0, 1);
  302.       lcd.print("   Delay Time   ");
  303.       break;
  304.     case 1:
  305.       lcd.setCursor(0, 0);
  306.       lcd.print(">> Delay Time   ");
  307.       lcd.setCursor(0, 1);
  308.       lcd.print("   Hysteresis   ");
  309.       break;
  310.     case 2:
  311.       lcd.setCursor(0, 0);
  312.       lcd.print(">> Hysteresis   ");
  313.       lcd.setCursor(0, 1);
  314.       lcd.print("   Start Voltage");
  315.       break;
  316.     case 3:
  317.       lcd.setCursor(0, 0);
  318.       lcd.print(">> Start Voltage");
  319.       lcd.setCursor(0, 1);
  320.       lcd.print("   Load Default ");
  321.       break;
  322.     case 4:
  323.       lcd.setCursor(0, 0);
  324.       lcd.print(">> Load Default ");
  325.       lcd.setCursor(0, 1);
  326.       lcd.print("   Exit         ");
  327.       break;
  328.   }
  329. }
  330. // Test
  331. void doLCDTest() {
  332.   if (encoderVal < 0) encoderVal = 2;
  333.   pos = abs(encoderVal % 3);
  334.   switch (pos) {
  335.     case 0:
  336.       lcd.setCursor(0, 0);
  337.       lcd.print("Test > Exit     ");
  338.       lcd.setCursor(0, 1);
  339.       lcd.print("       Torch Up ");
  340.       digitalWrite(outputDnPin, LOW);  //PORTD 5
  341.       digitalWrite(outputUpPin, LOW);  //PORTD 6
  342.       digitalWrite(outputOkPin, LOW);  //PORTD 7
  343.       break;
  344.     case 1:
  345.       lcd.setCursor(0, 0);
  346.       lcd.print("Test > Torch Up ");
  347.       lcd.setCursor(0, 1);
  348.       lcd.print("       Torch Dn ");
  349.       if (digitalRead(outputOkPin) == LOW) LCDtime = 0;
  350.       if (LCDtime >= 200) {              // 100 LCDtime = 1s
  351.         digitalWrite(outputDnPin, LOW);  //PORTD 5
  352.         digitalWrite(outputUpPin, LOW);  //PORTD 6
  353.         digitalWrite(outputOkPin, LOW);  //PORTD 7
  354.       }
  355.       break;
  356.     case 2:
  357.       lcd.setCursor(0, 0);
  358.       lcd.print("Test > Torch Dn ");
  359.       lcd.setCursor(0, 1);
  360.       lcd.print("       Exit     ");
  361.       if (digitalRead(outputOkPin) == LOW) LCDtime = 0;
  362.       if (LCDtime >= 200) {
  363.         digitalWrite(outputDnPin, LOW);  //PORTD 5
  364.         digitalWrite(outputUpPin, LOW);  //PORTD 6
  365.         digitalWrite(outputOkPin, LOW);  //PORTD 7
  366.       }
  367.       break;
  368.   }
  369. }
  370. void doTestUp() {
  371.   digitalWrite(outputDnPin, LOW);   //PORTD 5
  372.   digitalWrite(outputUpPin, HIGH);  //PORTD 6
  373.   digitalWrite(outputOkPin, HIGH);  //PORTD 7
  374.   LCDtime = 0;
  375.   menu = 12;
  376.   encoderVal = 1;
  377. }
  378. void doTestDown() {
  379.   digitalWrite(outputDnPin, HIGH);  //PORTD 5
  380.   digitalWrite(outputUpPin, LOW);   //PORTD 6
  381.   digitalWrite(outputOkPin, HIGH);  //PORTD 7
  382.   LCDtime = 0;
  383.   menu = 12;
  384.   encoderVal = 2;
  385. }
  386.  
  387. void doLCDDelayTime() {
  388.   if (encoderVal < 1) encoderVal = 1;
  389.   else if (encoderVal > 200) encoderVal = 200;
  390.  
  391.   DT = encoderVal;
  392.   if (DT != oldValue) {
  393.     SaveData(DTa, DT);
  394.     oldValue = DT;
  395.     LCDtime = 0;
  396.   }
  397.  
  398.   double x = DT / 10.00;
  399.   lcd.setCursor(0, 0);
  400.   lcd.print("Set > Delay Time");
  401.   lcd.setCursor(0, 1);
  402.   lcd.print("     : ");
  403.   lcd.print(x, 1);
  404.   lcd.print(" s       ");
  405. }
  406. void doLCDHysreresis() {
  407.   if (encoderVal < 1) encoderVal = 1;
  408.   else if (encoderVal > 99) encoderVal = 99;
  409.  
  410.   HyS = encoderVal;
  411.   if (HyS != oldValue) {
  412.     SaveData(HySa, HyS);
  413.     oldValue = HyS;
  414.     LCDtime = 0;
  415.   }
  416.  
  417.   double x = HyS / 10.00;
  418.   lcd.setCursor(0, 0);
  419.   lcd.print("Set > Hysteresis");
  420.   lcd.setCursor(0, 1);
  421.   lcd.print("     :");
  422.   lcd.write(0);
  423.   lcd.print(x, 1);
  424.   lcd.print(" V       ");
  425. }
  426. void doLCDStartVoltage() {
  427.   if (encoderVal < 50) encoderVal = 50;
  428.   else if (encoderVal > 250) encoderVal = 250;
  429.  
  430.   StV = encoderVal;
  431.   if (StV != oldValue) {
  432.     SaveData(StVa, StV);
  433.     oldValue = StV;
  434.     LCDtime = 0;
  435.   }
  436.  
  437.   lcd.setCursor(0, 0);
  438.   lcd.print("Set > Start Volt");
  439.   lcd.setCursor(0, 1);
  440.   lcd.print("     : ");
  441.   lcd.print(StV);
  442.   lcd.print(" V       ");
  443. }
  444. void doLCDLoadDefault() {
  445.   Default();
  446.  
  447.   for (byte i = 0; i < 100; i++) {
  448.     lcd.setCursor(0, 0);
  449.     lcd.print("     Default    ");
  450.     lcd.setCursor(0, 1);
  451.     lcd.print("Load   ");
  452.     lcd.print(i);
  453.     lcd.print(" ");
  454.     lcd.print("%");
  455.     lcd.print("        ");
  456.     delay(5);
  457.   }
  458.   lcd.setCursor(0, 0);
  459.   lcd.print("Default:  DONE  ");
  460.   lcd.setCursor(0, 1);
  461.   lcd.print("Please Restart  ");
  462.   exit(0);
  463.   //menu = 11;
  464. }
  465.  
  466. /* END CODE */
  467.  
Advertisement
Add Comment
Please, Sign In to add comment