RuiViana

funcao13_5.ino

May 5th, 2020
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 31.18 KB | None | 0 0
  1. //---------------------------- IMH -------------------------
  2. void selecao()                                          // Seleciona parametros e menus
  3. {
  4.   if (menu == 0)                                        // Menu 0 - ajuste da guia
  5.   { //                                                  // BT1 menu 1; BT2  5 steps; BT3 50 steps;  BT4 -5 steps;  BT5 -50 steps
  6.     lcd.clear();                                        // LCD clear
  7.     lcd.setCursor(2, 0);                                // Cursor LCD em 0,0
  8.     lcd.print("PRESSOR GNV");                           // Print
  9.     delay(1000);
  10.     lcd.setCursor(2, 1);                                // Cursor LCD em 0,0
  11.     lcd.print("by Jesterson");
  12.     delay(500);
  13.     lcd.clear();
  14.     lcd.setCursor(0, 0);                                // Cursor LCD em 0,0
  15.     lcd.print("Ajuste a guia do");                         // Print
  16.     lcd.setCursor(0, 1);
  17.     lcd.print("fio e pres Enter");
  18.  
  19.     while (menu == 0)
  20.       // Enquanto for menu 0
  21.     {
  22.       if (digitalRead(BT1) == LOW)                      // Se muda de menu
  23.       {
  24.         menu = 1;                                       // Muda para o menu 1  seleciona funcao
  25.         delay(600);                                     // Delay
  26.       }
  27.       else if (digitalRead(BT2) == LOW)                 // Se avança step em 5 steps
  28.       {
  29.         stepper.step(2);                                // 5 steps
  30.         delay(5);                                       // Delay
  31.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  32.       }
  33.       else if (digitalRead(BT3) == LOW)                 // Se avança step em 50 steps
  34.       {
  35.         stepper.step(-40);                               // 50 steps
  36.         delay(1);                                       // Delay
  37.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  38.       }
  39.       else if (digitalRead(BT4) == LOW)                 // Se avança step em -5 steps
  40.       {
  41.         stepper.step(-2);                               // -5 steps
  42.         delay(5);                                       // Delay
  43.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  44.       }
  45.       else if (digitalRead(BT5) == LOW)                 // Se avança step em -50 steps
  46.       {
  47.         stepper.step(40);                              // -50 steps
  48.         delay(1);                                       // Delay
  49.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  50.       }
  51.     }
  52.   }
  53.  
  54.   if (menu == 1)                                        // Menu 1 - seleciona funcao
  55.   { //                                                  // BT1; BT2 menu 8; BT3;  BT4 Configurar menu 2 ; BT5
  56.     lcd.clear();                                        // LCD clear
  57.     lcd.setCursor(0, 0);                                // Cursor LCD em 0,0
  58.     lcd.print("ESCOLHA A OPCAO");                     // Print
  59.     lcd.setCursor(0, 1);                                // Cursor LCD em 0,1
  60.     lcd.print("Config<- ->Inici");                     // Print
  61.     while (menu == 1)                                   // Enquanto menu = 1
  62.     {
  63.       if (digitalRead(BT2) == LOW)                      // Se Inicia processo
  64.       {
  65.         lcd.clear();                                    // LCD clear
  66.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  67.         lcd.print("****************************");      // Print
  68.         lcd.clear();                                    // LCD clear
  69.         lcd.setCursor(0, 1);                            // Cursor LCD em 3,1
  70.         lcd.print("INICIO PROCESSO");                  // Print
  71.         delay(500);                                     // Delay
  72.         menu = 8;                                       // Muda para o menu 8 Inicia processo / calculos
  73.       }
  74.       else if (digitalRead(BT4) == LOW)                 // Se selecionou configuracoes
  75.       {
  76.         lcd.clear();                                    // LCD clear
  77.         lcd.setCursor(1, 0);                            // Cursor LCD em 4,0
  78.         lcd.print("CONFIGURACOES");                     // Print
  79.         delay(1500);                                    // Delay
  80.         lcd.clear();                                    // LCD clear
  81.         menu = 2;                                       // Muda para o menu 2 Numero de espiras
  82.       }
  83.     }
  84.   }
  85.   if (menu == 2)                                        // Menu 2 - Numero de espiras
  86.   { //                                                  // BT1 menu 3; BT2 Incrementa * 10; BT3 Decrementa;  BT4 Incrementa / 10 ;  BT5 Incrementa
  87.     incrementa = 1;                                     // Define incremento inicial
  88.     lcd.setCursor(0, 0);                                // Cursor LCD em 0,0
  89.     lcd.print("Num. de espiras:");                      // Numero de espiras
  90.     lcd.setCursor(0, 1);                                // Cursor LCD em 0,1
  91.     lcd.print("      ");                               // Print
  92.     lcd.setCursor(0, 1);                                // Cursor LCD em 0,1
  93.     lcd.print(numEsp);
  94.     lcd.setCursor(8, 1);                                // Cursor LCD em 0,1
  95.     lcd.print("        ");                                     // Print// Print
  96.     lcd.setCursor(8, 1);                                // Cursor LCD em 8,1
  97.     lcd.print(incrementa);                              // Print
  98.     while (menu == 2)                                   // Enquanto menu  2
  99.     { //                                                // Num. de espiras
  100.       if (digitalRead(BT1) == LOW)
  101.       {
  102.         menu = 3;                                       // Muda para o menu 3 Bitola do fio
  103.         delay(600);                                     // Delay
  104.       }
  105.       else if (digitalRead(BT2) == LOW)                 // Aumenta fator do incremento
  106.       {
  107.         incrementa = incrementa * 10;                   // Aumenta fator do incremento
  108.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  109.         lcd.print("      ");                            // Print
  110.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  111.         lcd.print(numEsp);                              // Print
  112.         lcd.setCursor(8, 1);                                // Cursor LCD em 0,1
  113.         lcd.print("        ");                                     // Print
  114.         lcd.setCursor(8, 1);                            // Cursor LCD em 8,1
  115.         lcd.print(incrementa);                          // Print
  116.         delay(500);                                     // Delay
  117.       }
  118.       else if (digitalRead(BT4) == LOW)                 // Diminui fator do incremento
  119.       {
  120.         incrementa = incrementa / 10;                   // Diminui fator do incremento
  121.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  122.         lcd.print("      ");                            // Print
  123.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  124.         lcd.print(numEsp);                              // Print
  125.         lcd.setCursor(8, 1);                                // Cursor LCD em 0,1
  126.         lcd.print("        ");                                     // Print
  127.         lcd.setCursor(8, 1);                            // Cursor LCD em 8,1
  128.         lcd.print(incrementa);                          // Print
  129.         delay(500);                                     // Delay
  130.       }
  131.       else if (digitalRead(BT3) == LOW)                 // Atualiza decremento
  132.       {
  133.         numEsp = numEsp - incrementa;                   // Atualiza decremento numero de espiras
  134.         if (numEsp < 0)                                 // Se numero de espiras negativo
  135.           numEsp = 0;                                   // Numero de espiras igual a zero
  136.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  137.         lcd.print("      ");                            // Print
  138.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  139.         lcd.print(numEsp);                              // Print
  140.         lcd.setCursor(8, 1);                                // Cursor LCD em 0,1
  141.         lcd.print("        ");                                     // Print
  142.         lcd.setCursor(8, 1);                            // Cursor LCD em 8,1
  143.         lcd.print(incrementa);                          // Print
  144.         delay(500);                                     // Delay
  145.       }
  146.       else if (digitalRead(BT5) == LOW)                 // Atualiza incremento
  147.       {
  148.         numEsp = numEsp + incrementa;
  149.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  150.         lcd.print("      ");                            // Print
  151.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  152.         lcd.print(numEsp);                              // Print
  153.         lcd.setCursor(8, 1);                                // Cursor LCD em 0,1
  154.         lcd.print("        ");                                     // Print
  155.         lcd.setCursor(8, 1);                            // Cursor LCD em 8,1
  156.         lcd.print(incrementa);                          // Print
  157.         delay(500);                                     // Delay
  158.       }
  159.     }
  160.   }
  161.   if (menu == 3)                                        // Menu 3 - Bitola do fio
  162.   { //                                                  // BT1 menu 4; BT2 Incrementa * 10; BT3 Decrementa;  BT4 Incrementa / 10 ;  BT5 Incrementa
  163.     incrementa = 1;                                     // Fator incrementa = 1
  164.     lcd.clear();                                        // LCD clear
  165.     lcd.setCursor(0, 0);                                // Cursor LCD em 0,0
  166.     lcd.print("Bitola fio (mm):");                   // Print
  167.     lcd.setCursor(0, 1);                                // Cursor LCD em 0,1
  168.     lcd.print("        ");                                     // Print
  169.     lcd.setCursor(0, 1);                                // Cursor LCD em 0,1
  170.     lcd.print(bitFio);                                  // Print
  171.     lcd.setCursor(8, 1);                                // Cursor LCD em 0,1
  172.     lcd.print("        ");                                     // Print
  173.     lcd.setCursor(8, 1);                                // Cursor LCD em 8,1
  174.     lcd.print(incrementa);                              // Print
  175.     while (menu == 3)                                   // Enquanto menu 3
  176.     { //                                                // Bitola do fio
  177.       if (digitalRead(BT1) == LOW)                      // Muda para menu 4 Comprimento do carretel
  178.       {
  179.         menu = 4;                                       // Muda para menu 4 Comprimento do carretel
  180.         delay(600);                                     // Delay
  181.       }
  182.       else if (digitalRead(BT2) == LOW)                 // Aumenta fator do incremento
  183.       {
  184.         incrementa = incrementa * 10;                   // Aumenta fator do incremento
  185.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  186.         lcd.print("        ");                                 // Print
  187.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  188.         lcd.print(bitFio);                              // Print
  189.         lcd.setCursor(8, 1);                                // Cursor LCD em 0,1
  190.         lcd.print("        ");                                     // Print
  191.         lcd.setCursor(8, 1);                            // Cursor LCD em 8,1
  192.         lcd.print(incrementa);                          // Print
  193.         delay(500);                                     // Delay
  194.       }
  195.       else if (digitalRead(BT4) == LOW)                 // Diminui fator do incremento
  196.       {
  197.         incrementa = incrementa / 10;                   // Diminui fator do incremento
  198.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  199.         lcd.print("        ");                                 // Print
  200.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  201.         lcd.print(bitFio);                              // Print
  202.         lcd.setCursor(8, 1);                                // Cursor LCD em 0,1
  203.         lcd.print("        ");                                     // Print
  204.         lcd.setCursor(8, 1);                            // Cursor LCD em 8,1
  205.         lcd.print(incrementa);                          // Print
  206.         delay(500);                                     // Delay
  207.       }
  208.       else if (digitalRead(BT3) == LOW)                 // Atualiza decremento
  209.       {
  210.         bitFio = bitFio - incrementa;                   // Atualiza decremento bitola do fio
  211.         if (bitFio < 0)                                 // Se bitola do fio negativa
  212.           bitFio = 0;                                   // Bitola do fio igual a 0
  213.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  214.         lcd.print("        ");                                 // Print
  215.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  216.         lcd.print(bitFio);                              // Print
  217.         lcd.setCursor(8, 1);                                // Cursor LCD em 0,1
  218.         lcd.print("        ");                                     // Print
  219.         lcd.setCursor(8, 1);                            // Cursor LCD em 8,1
  220.         lcd.print(incrementa);                          // Print
  221.         delay(500);                                     // Delay
  222.       }
  223.       else if (digitalRead(BT5) == LOW)                 // Atualiza inecremento bitola do fio
  224.       {
  225.         bitFio = bitFio + incrementa;                   // Atualiza incremento
  226.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  227.         lcd.print("        ");                                 // Print
  228.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  229.         lcd.print(bitFio);
  230.         lcd.setCursor(8, 1);                                // Cursor LCD em 0,1
  231.         lcd.print("        ");                                     // Print// Print
  232.         lcd.setCursor(8, 1);                            // Cursor LCD em 8,1
  233.         lcd.print(incrementa);                          // Print
  234.         delay(500);                                     // Delay
  235.       }
  236.     }
  237.   }
  238.   if (menu == 4)                                        // Menu 4 - Comprimento do carretel
  239.   { //                                                  // BT1 menu 5; BT2 Incrementa * 10; BT3 Incrementa;  BT4 Incrementa / 10 ;  BT5 Decrementa
  240.     incrementa = 1;                                     // Fator incrementa = 1
  241.     lcd.clear();                                        // LCD clear
  242.     lcd.setCursor(0, 0);                                // Cursor LCD em 0,0
  243.     lcd.print("Larg carretel mm");                      // Print
  244.     lcd.setCursor(0, 1);                                // Cursor LCD em 0,2
  245.     lcd.print("        ");                                     // Print
  246.     lcd.setCursor(0, 1);                                // Cursor LCD em 0,2
  247.     lcd.print(carrLeng);                                // Prin
  248.     lcd.setCursor(8, 1);                                // Cursor LCD em 0,1
  249.     lcd.print("        ");                                     // Print
  250.     lcd.setCursor(8, 1);                                // Cursor LCD em 8,2
  251.     lcd.print(incrementa);                              // Print
  252.     while (menu == 4)                                   // Enquanto menu 4
  253.     { //                                                // Largura do carretel
  254.       if (digitalRead(BT1) == LOW)                      // Mudar para menu 5 Seleciona funcao
  255.       {
  256.         menu = 5;                                       // Muda para o menu 5 Seleciona funcao
  257.         delay(500);                                     // Delay
  258.       }
  259.       else if (digitalRead(BT2) == LOW)                 // Aumenta fator do incremento
  260.       {
  261.         incrementa = incrementa * 10;                   // Aumenta fator do incremento
  262.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,2
  263.         lcd.print("       ");                                 // Print
  264.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,2
  265.         lcd.print(carrLeng);                            // Print
  266.         lcd.setCursor(8, 1);                                // Cursor LCD em 0,1
  267.         lcd.print("        ");                                     // Print
  268.         lcd.setCursor(8, 1);                            // Cursor LCD em 8,2
  269.         lcd.print(incrementa);                          // Print
  270.         delay(500);                                     // Delay
  271.       }
  272.       else if (digitalRead(BT4) == LOW)                 // Diminui fator do incremento
  273.       {
  274.         incrementa = incrementa / 10;                   // Diminui fator do incremento
  275.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,2
  276.         lcd.print("       ");                                 // Print
  277.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,2
  278.         lcd.print(carrLeng);                            // Print
  279.         lcd.setCursor(8, 1);                                // Cursor LCD em 0,1
  280.         lcd.print("        ");                                     // Print
  281.         lcd.setCursor(8, 1);                            // Cursor LCD em 8,2
  282.         lcd.print(incrementa);                          // Print
  283.         delay(500);                                     // Delay
  284.       }
  285.       else if (digitalRead(BT3) == LOW)                 // Atualiza decremento
  286.       {
  287.         carrLeng = carrLeng - incrementa;               // Atualiza decremento largura carretel
  288.         if (carrLeng < 0)                               // Se largura negativa
  289.           carrLeng = 0;                                 // Largura igual a 0
  290.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,2
  291.         lcd.print("       ");                                 // Print
  292.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,2
  293.         lcd.print(carrLeng);                            // Print
  294.         lcd.setCursor(8, 1);                                // Cursor LCD em 0,1
  295.         lcd.print("        ");                                     // Print
  296.         lcd.setCursor(8, 1);                            // Cursor LCD em 8,2
  297.         lcd.print(incrementa);                          // Print
  298.         delay(500);                                     // Delay
  299.       }
  300.       else if ( digitalRead(BT5) == LOW)                // Atualiza incremento
  301.       {
  302.         carrLeng = carrLeng + incrementa;               // Atualiza incremento
  303.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,2
  304.         lcd.print("       ");                                 // Print
  305.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,2
  306.         lcd.print(carrLeng);                            // Print
  307.         lcd.setCursor(8, 1);                                // Cursor LCD em 0,1
  308.         lcd.print("        ");                                     // Print
  309.         lcd.setCursor(8, 1);                            // Cursor LCD em 8,2
  310.         lcd.print(incrementa);                          // Print
  311.         delay(500);                                     // Delay
  312.       }
  313.     }
  314.   }
  315.   if (menu == 5)                                        // Janela 5 - Seleciona funcao
  316.   { //                                                  // BT1; BT2 menu 8; BT3;  BT4 inicio = 6;  BT5
  317.     lcd.clear();                                        // LCD clear
  318.     lcd.setCursor(0, 0);                                // Cursor LCD em 0,0
  319.     lcd.print("ESCOLHA A OPCAO");                     // Print
  320.     lcd.setCursor(0, 1);                                // Cursor LCD em 0,1
  321.     lcd.print("Conf <- -> Inic");                  // Print
  322.     while (menu == 5)                                   // Enquanto menu = 5
  323.     {
  324.       if (digitalRead(BT2) == LOW)                      // Mudar para menu 9 Inicia processo
  325.       {
  326.         lcd.clear();                                    // LCD clear
  327.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  328.         lcd.print("************");      // Print
  329.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  330.         lcd.print("INICIO PROCESSO");                  // Print
  331.         delay(500);                                     // Delay
  332.         menu = 8;                                       // Muda para o menu 8
  333.       }
  334.       else if (digitalRead(BT4) == LOW)                 // Mudar para menu 6 define se tem isolação entre camadas
  335.       {
  336.         lcd.setCursor(0, 0);                            // Cursor LCD em 0,0
  337.         delay(500);                                     // Delay
  338.         lcd.clear();                                    // LCD clear
  339.         menu = 6;                                       // Muda para o menu 6 define se tem isolação entre camadas
  340.       }
  341.     }
  342.   }
  343.   if (menu == 6)                                        // Menu 6 - define se tem isolação entre camadas
  344.   { //                                                  // BT1 menu 7; BT2; BT3 NAO;  BT4;  BT5 SIM
  345.     lcd.setCursor(0, 0);                                // Cursor LCD em 0,0
  346.     lcd.print("ISOLACAO? +   -");                       // Print
  347.     lcd.setCursor(0, 1);                                // Cursor LCD em 0,1
  348.     lcd.setCursor(5, 1);                                // Cursor LCD em 5,1
  349.     lcd.print("    Sim Nao");                           // Print
  350.     lcd.print(" ");                                     // Print
  351.     lcd.setCursor(0, 1);                                // Cursor LCD em 0,1
  352.     while (menu == 6)                                   // Enquanto menu 6
  353.     {
  354.       if (digitalRead(BT1) == LOW)                      // Muda de menu
  355.       {
  356.         menu = 7;                                       // Muda para o menu 7 Fator de correcao de passo
  357.         delay(500);                                     // Delay
  358.       }
  359.       else if (digitalRead(BT3) == LOW)                 // Definir isolacao NAO
  360.       { isolador = false;
  361.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  362.         lcd.print(" ");                                 // Print
  363.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  364.         lcd.print("NAO  ==");                           // Print
  365.         delay(500);                                     // Delay
  366.       }
  367.       else if (digitalRead(BT5) == LOW)                 // Definir isolacao SIM
  368.       {
  369.         isolador = true;                                // Define audio ligado
  370.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  371.         lcd.print(" ");                                 // Print
  372.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  373.         lcd.print("SIM  ==");                           // Print
  374.         delay(500);                                     // Delay
  375.       }
  376.     }
  377.   }
  378.   if (menu == 7)                                        // Menu 7 - Fator de correcao de passo
  379.   { //                                                  // BT1 menu 8; BT2; BT3 decrementa dciclos;  BT4;  BT5 Incrementa dciclos
  380.     lcd.clear();                                        // LCD clear
  381.     lcd.setCursor(0, 0);                                // Cursor LCD em 0,0
  382.     lcd.print("Fcorrecao Avan % ");                     // Print
  383.     lcd.setCursor(0, 1);                                // Cursor LCD em 0,1
  384.     lcd.print(" ");                                     // Print
  385.     lcd.setCursor(0, 1);                                // Cursor LCD em 0,1
  386.     lcd.print(dciclos);                                 // Print
  387.     while (menu == 7)                                   // Enquanto menu = 7
  388.     { //                                                // Fcorrecao Avan %
  389.       if (digitalRead(BT1) == LOW)                      // Muda de menu
  390.       {
  391.         menu = 8;                                       // Muda para o menu 8 Inicia processo / calculos
  392.         delay(500);                                     // Delay
  393.       }
  394.       else if (digitalRead(BT3) == LOW)                 // Decrementa fator de passo
  395.       {
  396.         dciclos = dciclos - 1;                          // Decrementa fator de passo
  397.         if (dciclos < 0)                                // Se fator de passo negativo
  398.           dciclos = 0;                                  // fator de passo igual a 0
  399.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  400.         lcd.print(" ");                                 // Print
  401.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  402.         lcd.print(dciclos);                             // Print
  403.         delay(500);                                     // Delay
  404.       }
  405.       else if (digitalRead(BT5) == LOW )                // Incrementa fator de passo
  406.       {
  407.         dciclos = dciclos + 1;                          // Incrementa fator de passo
  408.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  409.         lcd.print(" ");                                 // Print
  410.         lcd.setCursor(0, 1);                            // Cursor LCD em 0,1
  411.         lcd.print(dciclos);                             // Print
  412.         delay(500);                                     // Delay
  413.       }
  414.     }
  415.   }
  416.   if (menu == 8)                                        // Menu 8 - Inicia processo / calculos
  417.   { //                                                  // BT1; BT2 direto = 0, menu 9; BT3;  BT4  direto = 1, menu 9;  BT5
  418.     espCam = (carrLeng * 1 / bitFio) / (1 + dln / 100); // numero de espiras por camada
  419.     lcd.clear();                                        // LCD clear
  420.     lcd.setCursor(0, 0);                                // Cursor LCD em 0,0
  421.     lcd.print("SENT ENROLAMENTO");
  422.     lcd.setCursor(1, 1);                                // Cursor LCD em 0,2
  423.     lcd.print("Esq <- -> Dir");                         // Print
  424.     while (menu == 8)                                   // Enquanto menu 8
  425.     { //                                                // SENTIDO
  426.       if (digitalRead(BT2) == LOW)                      // Define sentido CW
  427.       {
  428.         direct = 0;                                     // Sentido CW
  429.         menu = 9;                                       // Inicia processo
  430.       }
  431.       else if (digitalRead(BT4) == LOW)                 // Define sentido CCW
  432.       {
  433.         direct = 1;                                     // Sentido CCW
  434.         menu = 9;                                       // Inicia processo
  435.       }
  436.     }
  437.     lcd.clear();                                        // LCD clear
  438.     lcd.setCursor(0, 0);                                // Cursor LCD em 0,0
  439.     lcd.print("INICIANDO PROCESSO");                    // Print
  440.     lcd.setCursor(3, 1);                                // Cursor LCD em 3,1
  441.     lcd.print(" ");                                     // Print
  442.     lcd.setCursor(2, 1);                                // Cursor LCD em 2,1
  443.     lcd.setCursor(8, 1);                                // Cursor LCD em 08,1
  444.     delay(1500);                                        // Delay
  445.     lcd.clear();                                        // LCD clear
  446.     lcd.setCursor(3, 1);                                // Cursor LCD em 3,1
  447.     lcd.print(" ");                                     // Print
  448.     lcd.setCursor(0, 0);                                // Cursor LCD em 2,0
  449.     lcd.print("T=");
  450.     lcd.setCursor(2, 0);
  451.     lcd.print(numEsp);
  452.     lcd.setCursor(7, 0);
  453.     lcd.print("Conc=    ");
  454.     // lcd.setCursor(8, 1);
  455.     //lcd.print("Esp=");
  456.     lcd.setCursor(0, 1);
  457.     lcd.print("Camadas=");
  458.     delay(500);// Print
  459.     //                                                  // Calcula ciclos do step por espira
  460.  
  461.     ciclos = espFase * bitFio * 360 / (1 * 0.703125 * 1 * 3.14159 * 5) * 1.8 * (1 + dciclos / 100) / 0.615;       // 0.585; altere esses valores para um ajuste fino do da guia do fio
  462.     //ciclos = espFase * bitFio * 360 / (1 * 0.703125 * 1 * 3.14159 * 5) * 1.8 * (1 + dciclos / 100) / 0.525;       // 0.585; altere esses valores para um ajuste fino do da guia do fio
  463.     // ciclos = espFase * bitFio * 360 / (1 * 0.703125 * 1 * 3.14159 * 5) * 1.8 * (1 + dciclos / 100) / 0.055;
  464.  
  465.     numEspAtual = 0;                                    // Zera contador de espiras feitas
  466.     camf = 0;                                           // Zera contador de camadas feitas
  467.     LCDContagem();                                      // Mostra contagem de espiras e camadas
  468.     contaStep = 0;
  469.   }
  470. }
  471. //--------------------------------------------------
  472. void LCDContagem()                                      // Print contagem de espiras e camadas
  473. {
  474.   lcd.setCursor(12, 0);                                 // Cursor LCD em 3,1
  475.   lcd.print(numEspAtual);                               // Print
  476.   lcd.setCursor(8, 1);                                 // Cursor LCD em 12,1
  477.   lcd.print(camf);                                      // Print
  478.   lcd.setCursor(10, 1);                                 // Cursor LCD em 14,1
  479. }
  480. //---------------------------- FIM DE PROCESSO  --------------------------------
  481. void endProcess()
  482. {
  483.   desligaMotor();
  484.   //  digitalWrite(motor_carretel, LOW );                     // Desliga motor do crretel
  485.   lcd.clear();                                            // LCD clear
  486.   lcd.setCursor(0, 0);                                    // Cursor LCD em 0,1
  487.   lcd.print("Processo concluido");                        // Print
  488.   lcd.setCursor(0, 1);                                    // Cursor LCD em 0,1
  489.   lcd.print("Com:            ");                                      // Print
  490.   lcd.setCursor(4, 1);                                    // Cursor LCD em 0,3
  491.   lcd.print(numEsp);                                      // Print
  492.   lcd.setCursor(9, 1);                                    // Cursor LCD em 8,3
  493.   lcd.print("Espiras:");                                // Print
  494.   returnHome();
  495.   delay(2000);                                             // Delay
  496.   lcd.setCursor(0, 0);                                    // Cursor LCD em 8,3
  497.   lcd.print("Enter= Nova bobin ");                                   // Print
  498.   lcd.setCursor(0, 1);                                    // Cursor LCD em 8,3
  499.   lcd.print("Reset= Seta config");                                   // Print
  500.   delay(300);                                             // Delay
  501.   while (menu == 9)                                       // Enquanto menu 9
  502.   {
  503.     if (digitalRead(BT1) == LOW)                          // BT1;  BT2;  BT3 menu 0;  BT4;  BT5
  504.  
  505.     {
  506.       menu = 0;                                           // menu inicial
  507.       delay(1000);
  508.     }
  509.   }
  510. }
  511. //------------------------------- CCW --------------------------- // funcoes de acionamento do motor de passo
  512. void counterclockwise ()                                    // Avanca step CCW
  513. {
  514.   stepper.step(1);                                          // Avanca um step CCW
  515.   contaStep = contaStep + 1;
  516. }
  517. //-------------------------------- CW ------------------------------
  518. void clockwise()                                            // Avanca step CW
  519. {
  520.   stepper.step(-1);                                         // Avanca um step CW
  521.   contaStep = contaStep - 1;
  522. }
Add Comment
Please, Sign In to add comment