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
|
#include "TFT_eSPI.h"
#include "ADXL335.h"
#include "seeed_graphics_define.h"
#include "seeed_graphics_base.h"
#include "seeed_line_chart.h"
TFT_eSPI tft;
ADXL335 axl;
#define max_size 50
int mode = 0;
int next_mode = 0;
doubles accelerator_readings[3];
TFT_eSprite spr = TFT_eSprite(&tft);
void show_splash() {
mode = 0;
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_GREEN);
tft.setTextSize(4);
tft.drawString("Hello world!", 20, 100);
}
void setup() {
tft.begin();
tft.setRotation(3);
show_splash();
spr.createSprite(TFT_HEIGHT, TFT_WIDTH);
pinMode(WIO_KEY_A, INPUT);
pinMode(WIO_KEY_B, INPUT);
pinMode(WIO_KEY_C, INPUT);
axl.begin();
}
void show_accelerometer_readings() {
mode = 1;
spr.fillSprite(TFT_WHITE);
float ax = axl.getAccelerationX();
float ay = axl.getAccelerationY();
float az = axl.getAccelerationZ();
if (accelerator_readings[0].size() == max_size) {
for (uint8_t i = 0; i<3; i++){
accelerator_readings[i].pop();
}
}
accelerator_readings[0].push(ax);
accelerator_readings[1].push(ay);
accelerator_readings[2].push(az);
auto header = text(0, 0);
header.value("Acceleration Readings");
header.align(center);
header.valign(vcenter);
header.width(tft.width());
header.thickness(2);
header.height(header.font_height() * 2);
header.draw();
auto content = line_chart(20, header.height());
content.height(tft.height() - header.height() * 1.5);
content.width(tft.width() - content.x() * 2);
content.based_on(-2.0);
content.show_circle(false);
content.value({accelerator_readings[0],accelerator_readings[1], accelerator_readings[2]});
content.color(TFT_BLUE, TFT_RED, TFT_GREEN);
content.draw();
spr.pushSprite(0, 0);
}
void process_input() {
if (digitalRead(WIO_KEY_C) == LOW) {
next_mode = 0;
}
if (digitalRead(WIO_KEY_B) == LOW) {
next_mode = 1;
}
if (digitalRead(WIO_KEY_A) == LOW) {
next_mode = 1;
}
}
void loop() {
process_input();
if (next_mode == 0 && mode != 0) {
show_splash();
}
if (next_mode == 1) {
show_accelerometer_readings();
}
delay(50);
}
|