-
Notifications
You must be signed in to change notification settings - Fork 0
/
lcd_example.c
88 lines (78 loc) · 2.25 KB
/
lcd_example.c
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
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include "pico/stdlib.h"
#include "hardware/i2c.h"
#include "pico/binary_info.h"
#include "rgb_lcd.h"
struct Displaystate disp;
struct Displaystate *disp_ptr = &disp;
const char initmsg[17] = "Starting demo...";
void setup()
{
// Set up i2c, this needs to happen since the lcd library depends on
// default i2c working
i2c_init(i2c_default, 100 * 1000);
gpio_set_function(PICO_DEFAULT_I2C_SDA_PIN, GPIO_FUNC_I2C);
gpio_set_function(PICO_DEFAULT_I2C_SCL_PIN, GPIO_FUNC_I2C);
gpio_pull_up(PICO_DEFAULT_I2C_SDA_PIN);
gpio_pull_up(PICO_DEFAULT_I2C_SCL_PIN);
// Make the I2C pins available to picotool
bi_decl(bi_2pins_with_func(PICO_DEFAULT_I2C_SDA_PIN, PICO_DEFAULT_I2C_SCL_PIN, GPIO_FUNC_I2C));
// Set up Grove LCD monitor
lcd_init(disp_ptr);
// Use 16 columns, 2 rows
lcd_begin(disp_ptr, 16, 2);
// Initialize cursor to start
lcd_set_cursor(disp_ptr, 0, 0);
}
int main()
{
setup();
for (uint32_t i = 0; i < 16; i++)
{
lcd_write(disp_ptr, initmsg[i]);
sleep_ms(50);
}
sleep_ms(2000);
while (1)
{
for (uint32_t i = 0; i < 16; i++)
{
lcd_set_cursor(disp_ptr, i, 0);
lcd_write(disp_ptr, '*');
sleep_ms(150);
lcd_set_cursor(disp_ptr, i, 1);
lcd_write(disp_ptr, '*');
sleep_ms(150);
}
for (int32_t i = 15; i >= 0; i--)
{
lcd_set_cursor(disp_ptr, i, 1);
lcd_write(disp_ptr, ' ');
sleep_ms(150);
lcd_set_cursor(disp_ptr, i, 0);
lcd_write(disp_ptr, ' ');
sleep_ms(150);
}
for (int32_t i = 15; i >= 0; i--)
{
lcd_set_cursor(disp_ptr, i, 0);
lcd_write(disp_ptr, '*');
sleep_ms(150);
lcd_set_cursor(disp_ptr, i, 1);
lcd_write(disp_ptr, '*');
sleep_ms(150);
}
for (uint32_t i = 0; i < 16; i++)
{
lcd_set_cursor(disp_ptr, i, 1);
lcd_write(disp_ptr, ' ');
sleep_ms(150);
lcd_set_cursor(disp_ptr, i, 0);
lcd_write(disp_ptr, ' ');
sleep_ms(150);
}
}
return 0;
}