-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_i2c.h
More file actions
97 lines (90 loc) · 3.33 KB
/
init_i2c.h
File metadata and controls
97 lines (90 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef INIT_I2C_H
#define INIT_I2C_H
#include <stdlib.h>
#include "pico/stdlib.h"
#include "hardware/i2c.h"
#include "init_GPIO.h"
#define I2C_PORT i2c1
#define I2C_SDA 14
#define I2C_SCL 15
#define endereco 0x3C
ssd1306_t ssd;
bool cor = true;
void init_i2c()
{
// I2C Initialisation. Using it at 400Khz.
i2c_init(I2C_PORT, 400 * 1000);
gpio_set_function(I2C_SDA, GPIO_FUNC_I2C); // Set the GPIO pin function to I2C
gpio_set_function(I2C_SCL, GPIO_FUNC_I2C); // Set the GPIO pin function to I2C
gpio_pull_up(I2C_SDA); // Pull up the data line
gpio_pull_up(I2C_SCL); // Pull up the clock line
ssd1306_init(&ssd, WIDTH, HEIGHT, false, endereco, I2C_PORT); // Inicializa o display
ssd1306_config(&ssd); // Configura o display
ssd1306_send_data(&ssd); // Envia os dados para o display
// Limpa o display. O display inicia com todos os pixels LIGADOS.
ssd1306_fill(&ssd, true);
ssd1306_send_data(&ssd);
}
void desenha_caractere(char c) // atualiza o display com o caractere inserido pelo usuario
{
ssd1306_fill(&ssd, cor);
ssd1306_rect(&ssd, 3, 3, 122, 58, !cor, cor);
ssd1306_draw_string(&ssd, "CARACTERE", 28, 10);
ssd1306_draw_string(&ssd, &c, 63, 30);
ssd1306_draw_string(&ssd, "PRESSIONADO", 20, 48);
ssd1306_send_data(&ssd);
}
void resposta_btns(bool led, bool verde) //trata o acionamento dos botoes, verificando estado e cor dos leds
{
if (verde)
{
gpio_put(LED_BLUE, false);
gpio_put(LED_GREEN, !gpio_get(LED_GREEN));
if (led)
{
ssd1306_fill(&ssd, cor);
ssd1306_rect(&ssd, 3, 3, 122, 58, !cor, cor);
ssd1306_draw_string(&ssd, "BOTAO A", 35, 10);
ssd1306_draw_string(&ssd, "PRESSIONADO", 20, 30);
ssd1306_draw_string(&ssd, "LED VERDE ON", 16, 48);
ssd1306_send_data(&ssd);
printf("Led VERDE ligado\n");
}
else
{
ssd1306_fill(&ssd, cor);
ssd1306_rect(&ssd, 3, 3, 122, 58, !cor, cor);
ssd1306_draw_string(&ssd, "BOTAO A", 35, 10);
ssd1306_draw_string(&ssd, "PRESSIONADO", 20, 30);
ssd1306_draw_string(&ssd, "LED VERDE OFF", 16, 48);
ssd1306_send_data(&ssd);
printf("Led VERDE desligado\n");
}
}
else
{
gpio_put(LED_GREEN, false);
gpio_put(LED_BLUE, !gpio_get(LED_BLUE));
if (led)
{
ssd1306_fill(&ssd, cor);
ssd1306_rect(&ssd, 3, 3, 122, 58, !cor, cor);
ssd1306_draw_string(&ssd, "BOTAO B", 35, 10);
ssd1306_draw_string(&ssd, "PRESSIONADO", 20, 30);
ssd1306_draw_string(&ssd, "LED AZUL ON", 20, 48);
ssd1306_send_data(&ssd);
printf("Led AZUL ligado\n");
}
else
{
ssd1306_fill(&ssd, cor);
ssd1306_rect(&ssd, 3, 3, 122, 58, !cor, cor);
ssd1306_draw_string(&ssd, "BOTAO B", 35, 10);
ssd1306_draw_string(&ssd, "PRESSIONADO", 20, 30);
ssd1306_draw_string(&ssd, "LED AZUL OFF", 20, 48);
ssd1306_send_data(&ssd);
printf("Led AZUL desligado\n");
}
}
}
#endif