Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #include <Keypad.h>
- #include <math.h>
- #define menu 12
- const byte qtdLinhas = 4; //QUANTIDADE DE LINHAS DO TECLADO
- const byte qtdColunas = 4; //QUANTIDADE DE COLUNAS DO TECLADO
- int vector[10];
- //CONSTRUÇÃO DA MATRIZ DE CARACTERES
- char matriz_teclas[qtdLinhas][qtdColunas] = {
- {'1', '2', '3', 'A'},
- {'4', '5', '6', 'B'},
- {'7', '8', '9', 'C'},
- {'*', '0', '#', 'D'}
- };
- // Teclado
- byte PinosqtdLinhas[qtdLinhas] = {11, 10, 9, 8}; //PINOS UTILIZADOS PELAS LINHAS
- byte PinosqtdColunas[qtdColunas] = {6, 5, 4, 3}; //PINOS UTILIZADOS PELAS COLUNAS
- // Declaração de objetos
- LiquidCrystal_I2C lcd(0x3f, 20, 4);
- // Variáveis Globais
- Keypad meuteclado = Keypad( makeKeymap(matriz_teclas), PinosqtdLinhas, PinosqtdColunas, qtdLinhas, qtdColunas);
- int line [4] = {0, 1, 2, 3}, line_bk[3], index, menu_number = 1;
- boolean menu_flag = 0,
- enter_flag = 0,
- sub_menu = 0;
- // Variaveis Teclado
- int raio = 0;
- int largura = 1;
- int numero_de_voltas = 2;
- int bitola_fio = 3;
- void setup() {
- Serial.begin(9600);
- // Teclado
- lcd.init();
- //Display LCD
- lcd.begin(20, 4); // 20 Colunas 3 Linhas
- lcd.setBacklight(HIGH);
- lcd.setCursor(0, 0);
- lcd.print(">");
- }
- void loop() {
- if (!sub_menu)
- {
- lcd.clear();
- lcd.setCursor(0, line[0]);
- lcd.print("A) Diametro/Largura");
- lcd.setCursor(0, line[1]);
- lcd.print("B) Bitola do Fio");
- lcd.setCursor(0, line[2]);
- lcd.print("C) Numero Voltas ");
- lcd.setCursor(0, line[3]);
- lcd.print("D) Quant Camadas");
- char entrada = meuteclado.waitForKey();
- switch (entrada) {
- case 'A':
- getvalue();
- break;
- }
- }
- }
- void raio_bobina()
- {
- lcd.setCursor(0, 0);
- lcd.print("RAIO : ");
- // Teclado
- }
- void largura_bobina()
- {
- lcd.setCursor(0, 0);
- lcd.print("LARGURA : ");
- // Teclado
- }
- void voltas_bobina()
- {
- lcd.setCursor(0, 0);
- lcd.print("VOLTAS : ");
- // Teclado
- }
- void bitola_bobina()
- {
- lcd.setCursor(0, 0);
- lcd.print("BITOLA : ");
- // Teclado
- }
- void dispMenu() {
- switch (menu)
- {
- case 0:
- raio_bobina();
- break;
- case 1:
- largura_bobina();
- break;
- case 2:
- voltas_bobina();
- break;
- case 3:
- bitola_bobina();
- break;
- }
- }
- int getvalue() {
- int value = 0;
- long number = 0;
- int i = 0;
- lcd.clear();
- lcd.setCursor(0, line[0]);
- lcd.print("Diametro:");
- lcd.setCursor(17, line[1]);
- lcd.print("mm");
- lcd.setCursor(0, line[2]);
- lcd.print("Largura:");
- lcd.setCursor(17, line[3]);
- lcd.print("mm");
- while (value != -13) {
- value = (meuteclado.waitForKey() - '0');
- if (value == -13)break;
- if (i <= 3) {
- number += value * pow(10, i);
- vector[i] = value;
- Serial.println(vector[i]);
- i++;
- lcd.setCursor(12 + i, line[1]);
- lcd.print(value);
- }
- }
- number = 0;
- for (int j = i - 1; j >= 0 ; j-- ) {
- value = vector[j];
- number += value * pow(10, i - j - 1);
- }
- Serial.println(number);//trocar por return
- }
Add Comment
Please, Sign In to add comment