-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
109 lines (81 loc) · 2.36 KB
/
main.cpp
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
98
99
100
101
102
103
104
105
106
107
108
109
// Example fetched from:
// https://github.com/pimoroni/pimoroni-pico/tree/main/examples/badger2040
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <string>
#include "badger2040.hpp"
#include "common/pimoroni_common.hpp"
#include "pico/platform.h"
#include "pico/stdlib.h"
#include "pico/time.h"
using namespace pimoroni;
Badger2040 badger;
uint32_t time() {
absolute_time_t t = get_absolute_time();
return to_ms_since_boot(t);
}
std::array<std::string, 8> font_names = {"sans", "sans_bold", "gothic",
"cursive", "cursive_bold", "serif",
"serif_bold", "serif_italic"};
int8_t selected_font = 0;
void draw() {
badger.pen(15);
badger.clear();
badger.font("sans");
for (int i = 0; i < int(font_names.size()); i++) {
std::string name = font_names[i];
if (selected_font == i) {
badger.pen(0);
badger.rectangle(0, i * 16, 80, 16);
badger.pen(15);
} else {
badger.pen(0);
}
badger.text(name, 2, i * 16 + 7, 0.4f);
}
badger.font(font_names[selected_font]);
badger.thickness(2);
badger.text("The quick", 90, 10, 0.80f);
badger.text("brown fox", 90, 32, 0.80f);
badger.text("jumped over", 90, 54, 0.80f);
badger.text("the lazy dog.", 90, 76, 0.80f);
badger.text("0123456789", 90, 98, 0.80f);
badger.text("!\"£$%^&*()", 90, 120, 0.80f);
badger.thickness(1);
badger.update();
}
int main() {
stdio_init_all();
sleep_ms(500);
printf("\n\n=======\nbadger2040 starting up\n\n");
badger.init();
badger.update_speed(1);
uint32_t i = 0;
while (true) {
printf("> drawing..");
draw();
printf("done!\n");
printf("> waiting for a button press..");
badger.wait_for_press();
printf("done!\n");
if (badger.pressed(badger.DOWN)) {
printf("> down pressed\n");
selected_font++;
}
if (badger.pressed(badger.UP)) {
printf("> up pressed\n");
selected_font--;
}
if (badger.pressed(badger.C)) {
printf("> C pressed\n");
badger.halt();
}
selected_font =
selected_font < 0 ? int(font_names.size()) - 1 : selected_font;
selected_font = selected_font >= int(font_names.size()) ? 0 : selected_font;
printf("> newly selected font is %s (%d)\n",
font_names[selected_font].c_str(), selected_font);
i++;
}
}