Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Bibliotecas: */
- #include <LiquidCrystal.h>
- #include <Keypad.h>
- /* Variaveis: */
- int Tempo = 0; /* Coluna 1 */
- boolean Ligar = false;
- #define buzzer A1
- /* Portas Tela LCD: */
- LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
- /* Setup e Loop: */
- /* Código: */
- const byte qtdLinhas = 4;
- const byte qtdColunas = 4;
- char matriz_teclas[qtdLinhas][qtdColunas] = {
- {'1', '2', '3', 'A'},
- {'4', '5', '6', 'B'},
- {'7', '8', '9', 'C'},
- {'*', '0', '#', 'D'}
- };
- /* Portas Trocadas: 5 = 1 | 4 = 0 | 3 = 13 | 2 = (Não tem) */
- byte PinosqtdLinhas[qtdLinhas] = {9, 8, 7, 6};
- byte PinosqtdColunas[qtdColunas] = {A2, A3, 13, A0};
- Keypad meuteclado = Keypad( makeKeymap(matriz_teclas),
- PinosqtdLinhas, PinosqtdColunas, qtdLinhas, qtdColunas);
- void setup() {
- Serial.begin(9600);
- /* Tela LCD */
- lcd.begin(2, 16);
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Defina o Tempo:");
- lcd.setCursor(0, 1);
- lcd.print(Tempo);
- /* Teclado Matricial de Membrana */
- Serial.println("Aperte uma tecla...");
- Serial.println();
- /* Buzzer */
- pinMode(buzzer, OUTPUT);
- }
- void loop() {
- /* Tela LCD */
- if (Serial.available()) {
- char cr = Serial.read();
- if (cr == '%') {
- lcd.clear();
- }
- else if (cr == '>') {
- lcd.setCursor(0, 1);
- }
- else {
- lcd.write(cr);
- }
- }
- /* Teclado Matricial de Membrana */
- char tecla_pressionada = meuteclado.getKey();
- if (tecla_pressionada) {
- tone(buzzer, 800,100);
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Defina o Tempo:");
- Serial.print("Tecla pressionada : ");
- Serial.println(tecla_pressionada);
- //funções
- if (tecla_pressionada == '#') {
- Ligar = true;
- }
- if (Ligar = true && Tempo > 0){
- Tempo--;
- lcd.setCursor(0, 1);
- lcd.print(Tempo);
- } else {
- Ligar = false;
- }
- if (tecla_pressionada == 'D') {
- Tempo = 0;
- }
- if (Ligar = false){
- lcd.setCursor(0, 1);
- lcd.print(Tempo);
- }
- //numeros
- if (tecla_pressionada == '1') {
- Tempo = 1;
- lcd.setCursor(0, 1);
- lcd.print(Tempo);
- }
- if (tecla_pressionada == '2') {
- Tempo = 2;
- lcd.setCursor(0, 1);
- lcd.print(Tempo);
- }
- if (tecla_pressionada == '3') {
- Tempo = 3;
- lcd.setCursor(0, 1);
- lcd.print(Tempo);
- }
- if (tecla_pressionada == '4') {
- Tempo = 4;
- lcd.setCursor(0, 1);
- lcd.print(Tempo);
- }
- if (tecla_pressionada == '5') {
- Tempo = 5;
- lcd.setCursor(0, 1);
- lcd.print(Tempo);
- }
- if (tecla_pressionada == '6') {
- Tempo = 6;
- lcd.setCursor(0, 1);
- lcd.print(Tempo);
- }
- if (tecla_pressionada == '7') {
- Tempo = 7;
- lcd.setCursor(0, 1);
- lcd.print(Tempo);
- }
- if (tecla_pressionada == '8') {
- Tempo = 8;
- lcd.setCursor(0, 1);
- lcd.print(Tempo);
- }
- if (tecla_pressionada == '9') {
- Tempo = 9;
- lcd.setCursor(0, 1);
- lcd.print(Tempo);
- }
- if (tecla_pressionada == '0') {
- Tempo = 0;
- lcd.setCursor(0, 1);
- lcd.print(Tempo);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement