#include <stdio.h>
#include "pico/stdlib.h"
#include "display_lcd.h"
#include "matematica.h"
/*****************************************************************************/
char smile[8] = {
0b00000000,
0b00001010,
0b00001010,
0b00001010,
0b00000000,
0b00010001,
0b00001110,
0b00000000
};
char sad[8] = {
0b00000000,
0b00001010,
0b00001010,
0b00001010,
0b00000000,
0b00000000,
0b00001110,
0b00010001
};
/*****************************************************************************/
#define LED 28
#define LED_2 27
#define OUT 1
#define IN 0
#define BOTAO_START 15 // B1
#define BOTAO_STOP 14 // B2
/*****************************************************************************/
void system_init(void);
/*****************************************************************************/
int main()
{
stdio_init_all();
sleep_ms(250);
system_init();
unsigned int estado_b1 = 0;
unsigned int estado_b2 = 0;
unsigned char tempo_str[17];
unsigned int contador = 0;
bool rodando = false;
posicao_cursor_lcd(1,1);
escreve_frase_ram_lcd(" CRONOMETRO ");
posicao_cursor_lcd(2,1);
escreve_frase_ram_lcd("Tempo: 0 seg");
cria_caractere_lcd(0, smile);
cria_caractere_lcd(1, sad);
while (true)
{
estado_b1 = gpio_get(BOTAO_START);
estado_b2 = gpio_get(BOTAO_STOP);
// Botão de start pressionado
if (estado_b1 == 0)
{
rodando = true;
}
// Botão de stop pressionado
if (estado_b2 == 0)
{
rodando = false;
}
if (rodando)
{
contador++;
sprintf(tempo_str, "Tempo: %2d seg", contador);
posicao_cursor_lcd(2,1);
escreve_frase_ram_lcd(tempo_str);
gpio_put(LED, 1); // liga LED indicando rodando
}
else
{
gpio_put(LED, 0); // desliga LED indicando parado
}
sleep_ms(1000);
}
return 0;
}
/*****************************************************************************/
void system_init(void)
{
gpio_init(LED);
gpio_set_dir(LED, OUT);
gpio_init(LED_2);
gpio_set_dir(LED_2, OUT);
gpio_init(BOTAO_START);
gpio_set_dir(BOTAO_START, IN);
gpio_pull_up(BOTAO_START);
gpio_init(BOTAO_STOP);
gpio_set_dir(BOTAO_STOP, IN);
gpio_pull_up(BOTAO_STOP);
sleep_ms(250);
init_lcd();
LIMPA_DISPLAY();
DesligaCursor();
}