Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Pipetagem_automatica
Diff: LCD.h
- Revision:
- 1:3dbb9b66b990
- Child:
- 3:8e4c26964bd1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCD.h Mon Jun 29 13:41:37 2020 +0000 @@ -0,0 +1,344 @@ +#include "mbed.h" +#include "TextLCD.h" + +//Portas da LCD: +TextLCD lcd(D10,D11,D4,D5,D8,D9); + +//Entrada A0 para botões LCD: +AnalogIn Botoes_LCD(A5); +AnalogIn SCL(PC_3); +AnalogIn SDA(PC_2); + +//Definição de variáveis: +int estado2 = 1; +int lcd_key = 0; +float adc_key_in = 0; +int quantidade = 0; + +//Definição Botões LCD: +#define btnDIREITA 0 +#define btnCIMA 1 +#define btnBAIXO 2 +#define btnESQUERDA 3 +#define btnSELECT 4 +#define btnRESET 5 + +//Definição Funções LCD: +void Botao_Emergencia(void); +void apeditarpipetagem(void); +void apiniciarpipetagem(void); +void apinformacoesdoprocesso(void); +void apdesligar(void); +void editarpipetagem(void); +void funcaoquantidade(void); +void funcaoposicao(void); +void iniciarpipetagem(void); +void informacoesdoprocesso(void); +void desligar(void); +void repetir(void); +void movimentacao(void); + + +//Função de leitura LCD: +int read_LCD_buttons(){ + //Recebe leitura e multiplica por 1000: + adc_key_in = Botoes_LCD.read()*1000; + //Enquanto nenhum Botão estiver ativado: + //(Funciona como um loop para garantir que não passe pela função sem que um botão haja sido pressionado) + while (adc_key_in>900){ + adc_key_in = Botoes_LCD.read()*1000; + } + //Condição de retorno para cada botão: + if (adc_key_in < 50) return btnDIREITA; + if (adc_key_in < 150) return btnCIMA; + if (adc_key_in < 300) return btnBAIXO; + if (adc_key_in < 450) return btnESQUERDA; + if (adc_key_in < 800) return btnSELECT; + + + + + } + +//Função de exibição do Menu principal: +void exibirMenu () { + lcd.cls(); + lcd.printf("Selecione a"); + lcd.setAddress(0,1); + lcd.printf("operacao:"); + lcd_key = read_LCD_buttons(); + switch (lcd_key){ + case btnBAIXO: apeditarpipetagem(); break; + default: exibirMenu(); + } + } + +//Função de apresentação da parte "Editar Pipetagem": +void apeditarpipetagem() { + //Limpa a tela + lcd.cls(); + //Inicia das coordenadas 0,0 + lcd.setAddress(0,0); + //Apresenta o texto ao usuário: + lcd.printf("Editar pipetagem"); + wait(0.5); + lcd_key = read_LCD_buttons(); + switch (lcd_key){ + //Caso direita tenha sido pressionada: + case btnDIREITA: + //Limpa tela + lcd.cls(); + //Inicia função "Editar Pipetagem" + editarpipetagem(); break; + //Caso baixo tenha sido pressionada + //Segue para próxima apresentação + case btnBAIXO: apiniciarpipetagem(); break; + //Caso nenhum dos anteriores tenha sido pressionado, reinicia a função, para que não interrompa o programa por erro de aperto de botão. + default: apeditarpipetagem(); + } + } +void editarpipetagem(){ + + lcd.cls(); + lcd.setAddress(0,0); + lcd.printf("Quantidade?"); + wait(0.5); + lcd_key = read_LCD_buttons(); + + switch (lcd_key){ + case btnESQUERDA: apeditarpipetagem(); break; + + case btnDIREITA: + lcd.cls(); + funcaoquantidade(); break; + + case btnBAIXO: + lcd.cls(); + lcd.printf("Posicao?"); + wait(0.5); + lcd_key = read_LCD_buttons(); + switch(lcd_key){ + case btnDIREITA: funcaoposicao(); break; + case btnESQUERDA: apeditarpipetagem(); break; + case btnCIMA: editarpipetagem(); break; + } + break; + } + } + +void funcaoquantidade(){ + wait(0.5); + lcd_key = read_LCD_buttons(); + switch (lcd_key){ + + case btnESQUERDA: apeditarpipetagem(); break; + + case btnBAIXO: + quantidade = quantidade - 1; + lcd.setAddress(0,0); + lcd.printf("Por enquanto:"); + lcd.setAddress(0,1); + lcd.printf("%d",quantidade); + funcaoquantidade(); + break; + case btnDIREITA: + quantidade = quantidade + 10; + lcd.setAddress(0,0); + lcd.printf("Por enquanto:"); + lcd.setAddress(0,1); + lcd.printf("%d",quantidade); + funcaoquantidade(); + break; + case btnCIMA: + quantidade = quantidade + 1; + lcd.setAddress(0,0); + lcd.printf("Por enquanto:"); + lcd.setAddress(0,1); + lcd.printf("%d",quantidade); + funcaoquantidade(); + break; + case btnSELECT: + lcd.cls(); + lcd.setAddress(0,0); + lcd.printf("Quantidade final:"); + lcd.setAddress(0,1); + lcd.printf("%d", quantidade); + wait(0.5); + lcd_key = read_LCD_buttons(); + switch (lcd_key){ + case btnSELECT: + exibirMenu(); + break; + } + break; + } + } + +void funcaoposicao(){ + while(estado2 == 1) { + wait(0.5); + lcd_key = read_LCD_buttons(); + switch (lcd_key){ + case btnSELECT: + estado2 = 0; + break; + } + joystick(); + printf("teste\n\r"); + wait(0.2); + } + exibirMenu(); + } +void apiniciarpipetagem(){ + lcd.cls(); + lcd.setAddress(0,0); + lcd.printf("Iniciar"); + lcd.setAddress(0,1); + lcd.printf("pipetagem"); + wait(0.5); + lcd_key = read_LCD_buttons(); + switch (lcd_key){ + case btnDIREITA: + iniciarpipetagem(); break; + + case btnBAIXO: + apinformacoesdoprocesso(); break; + + case btnCIMA: + apeditarpipetagem(); break; + + default: apiniciarpipetagem(); + + } + } +void iniciarpipetagem(){ + lcd.cls(); + lcd.setAddress(0,0); + lcd.printf("Iniciando"); + lcd.setAddress(0,1); + lcd.printf("Pipetagem..."); + wait(1); + lcd_key = read_LCD_buttons(); + switch (lcd_key){ + case btnESQUERDA: apiniciarpipetagem(); break; + case btnDIREITA: repetir(); break; + } + } +void apinformacoesdoprocesso(){ + lcd.cls(); + lcd.setAddress(0,0); + lcd.printf("Informacoes do"); + lcd.setAddress(0,1); + lcd.printf("processo"); + wait(0.5); + lcd_key = read_LCD_buttons(); + switch (lcd_key){ + case btnDIREITA: + informacoesdoprocesso(); break; + + case btnBAIXO: + apdesligar(); break; + + case btnCIMA: + apiniciarpipetagem(); break; + + default: apinformacoesdoprocesso(); + + } + } +void informacoesdoprocesso(){ + lcd.cls(); + lcd.setAddress(0,0); + lcd.printf("Quantidade?"); + wait(0.5); + lcd_key = read_LCD_buttons(); + switch (lcd_key){ + case btnESQUERDA: apinformacoesdoprocesso(); break; + case btnDIREITA: + lcd.cls(); + lcd.setAddress(0,0); + lcd.printf("Quantidade Final"); + lcd.setAddress(0,1); + lcd.printf("%d",quantidade); + lcd.printf(" ml"); + wait(0.5); + lcd_key = read_LCD_buttons(); + switch (lcd_key){ + case btnESQUERDA: + informacoesdoprocesso(); + break; + } + case btnBAIXO: + lcd.cls(); + lcd.printf("Posicao?"); + wait(0.5); + lcd_key = read_LCD_buttons(); + switch(lcd_key){ + case btnDIREITA: + lcd.cls(); + lcd.printf("x:"); + lcd.printf("%d", PosicaoUsuario[0]); + lcd.printf(", y:"); + lcd.printf("%d", PosicaoUsuario[1]); + lcd.printf(", z:"); + lcd.printf("%d", PosicaoUsuario[2]); + wait(0.5); + lcd_key = read_LCD_buttons(); + switch(lcd_key){ + case btnESQUERDA: + apinformacoesdoprocesso(); + break; + } + break; + case btnESQUERDA: apinformacoesdoprocesso(); break; + case btnCIMA: + informacoesdoprocesso(); + break; + default: informacoesdoprocesso(); + } + } + } +void apdesligar(){ + lcd.cls(); + lcd.setAddress(0,0); + lcd.printf("Desligar"); + wait(0.5); + lcd_key = read_LCD_buttons(); + switch (lcd_key){ + case btnDIREITA: + desligar(); break; + + case btnCIMA: + apinformacoesdoprocesso(); break; + + default: apdesligar(); + + } + } +void desligar(){ + lcd.cls(); + Emergencia = 1; + wait(1); + lcd_key = read_LCD_buttons(); + switch (lcd_key){ + case btnESQUERDA: apdesligar(); break; + } + } +void Inicializacao(){ + + exibirMenu(); + + } + +void repetir(){ //Controla baseado no input do usuário quantas vezes a atividade irá se repetir + int i; + for (i=0 ; i<quantidade ; i++) { + movimentacao(); + printf("Completado\n\r"); + } + } + + + + +