-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathM5Nameplate.ino
83 lines (66 loc) · 1.53 KB
/
M5Nameplate.ino
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
#include <M5Stack.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
uint8_t boxMargin = 10;
uint16_t bgColor = BLACK;
uint16_t textColor = WHITE;
uint16_t isChanged = true;
void setup() {
M5.begin();
initScreen();
}
void loop() {
M5.update();
if (M5.BtnA.wasReleased()) {
isChanged = true;
M5.Lcd.print('A');
switchColor();
}
if (!isChanged) {
return;
}
initScreen();
drawQr();
drawName();
drawAbstract();
isChanged = false;
}
void switchColor() {
if (bgColor == WHITE) {
bgColor = BLACK;
textColor = WHITE;
} else {
bgColor = WHITE;
textColor = BLACK;
}
}
void initScreen() {
M5.Lcd.fillScreen(bgColor);
M5.Lcd.setTextColor(textColor);
}
void drawQr() {
uint8_t qrWidth = (240 / 2) - (boxMargin * 2);
uint16_t qrPosX = (320 - qrWidth - boxMargin);
uint16_t qrPosY = boxMargin;
const char* msg = "https://twitter.com/@kappaseijin";
M5.Lcd.qrcode(msg, qrPosX, qrPosY, qrWidth);
}
void drawName() {
uint8_t fontSize = 2;
const char* msg = "@kappaseijin";
uint16_t posX = boxMargin + (8 * fontSize * strlen(msg) / 2);
uint16_t posY = boxMargin + (8 * fontSize * 1 / 2);
M5.Lcd.setTextSize(2);
M5.Lcd.setCursor(0, 0);
M5.Lcd.drawCentreString(msg, posX, posY, fontSize);
}
void drawAbstract() {
uint8_t fontSize = 2;
const char* msg = "I'm Engineer of Server Side, Embedded and VR.";
uint16_t posX = boxMargin;
uint16_t posY = boxMargin + (240 * 4 / 6);
M5.Lcd.setTextSize(fontSize);
M5.Lcd.setCursor(posX, posY);
M5.Lcd.println(msg);
}