-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy path7_segment.c
More file actions
49 lines (40 loc) · 1.23 KB
/
7_segment.c
File metadata and controls
49 lines (40 loc) · 1.23 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
#include <stdio.h>
#include "pico/stdlib.h"
#include "7_segment_lib.h"
const PIO pio = pio0;
const uint first_segment_pin = 8; // gpio 15-8 = segments E,D,B,G,A,C,F,dp
const uint first_digit_pin = 16; // gpio 19-16 = common anodes 4,3,2,1
// By convention the segments are labelled as follows:
//
// AAAA
// F B
// F B
// GGGG
// E C
// E C
// DDDD .
// You can define a custom bit pattern like this:
// the order here is EDBGACF. but should match the way you wire up the GPIOs
const uint32_t Pico = 0b10111010 << 24 | // 'P'
0b10000000 << 16 | // 'i'
0b11010000 << 8 | // 'c'
0b11010100; // 'o'
int main() {
uint sm;
stdio_init_all();
if (seven_segment_init (pio, &sm, first_segment_pin, first_digit_pin)) {
puts ("running");
// display scrolling 'Pico'
for (int shift = 24; shift >= 0; shift -= 8) {
pio_sm_put (pio, sm, Pico >> shift);
sleep_ms (1000);
}
// count to 9999
for (int i = 0; i < 10000; i += 1) {
sleep_ms (100);
pio_sm_put (pio, sm, int_to_seven_segment (i));
}
}
puts ("done");
while (true);
}