-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharduino-nano-nhd--boost,rpm.ino
94 lines (81 loc) · 2.47 KB
/
arduino-nano-nhd--boost,rpm.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
84
85
86
87
88
89
90
91
92
93
94
// Arduino nano NHD -- Boost,RPM
#include <Arduino.h>
#include <U8g2lib.h>
// Initialize the display
U8G2_SSD1322_NHD_256X64_2_4W_HW_SPI u8g2(U8G2_R2, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
// Add power saving loop?
void setup() {
u8g2.begin();
u8g2.setFont(u8g2_font_6x10_tr);
}
// Draw a curved bar
void drawCurvedBar(int centerX, int centerY, int startAngle, int endAngle, int radius, int value, int maxValue) {
int barEndAngle = startAngle + (endAngle - startAngle) * value / maxValue;
for (int r = radius; r > radius - 5; r--) { // Bar thickness of 5 pixels
u8g2.drawArc(centerX, centerY, r, startAngle, barEndAngle);
}
}
// needs numbers?
int boost(int boostValue, int maxBoost){
// Bottom hori line
u8g2.drawLine(169, 63, 191, 63);
u8g2.drawLine(169, 62, 191, 62);
// Right line
u8g2.drawLine(255, 30, 255, 51);
u8g2.drawLine(254, 30, 254, 51);
// Top arc line
u8g2.drawLine(255, 30, 215, 30);
u8g2.drawLine(255, 31, 215, 31);
// Top arc
u8g2.drawArc(212, 75, 45, 60, 116);
u8g2.drawArc(214, 77, 46, 60, 116);
// Bottom arc Line
u8g2.drawLine(255, 50, 215, 50);
u8g2.drawLine(255, 51, 215, 51);
// Bottom arc
u8g2.drawArc(212, 75, 25, 60, 116);
u8g2.drawArc(213, 76, 25, 60, 116);
// Text
u8g2.drawStr(205, 62, "Boost");
// Dynamic curved bar
drawCurvedBar(212, 75, 60, 116, 45, boostValue, maxBoost);
}
// needs numbers?
int rpm(int rpmValue, int maxRPM){
// Bottom hori line
u8g2.drawLine(49, 63, 71, 63);
u8g2.drawLine(49, 62, 71, 62);
// Right line
u8g2.drawLine(145, 30, 145, 51);
u8g2.drawLine(144, 30, 144, 51);
// Top arc line
u8g2.drawLine(145, 30, 95, 30);
u8g2.drawLine(145, 31, 95, 31);
// Top arc
u8g2.drawArc(92, 75, 45, 60, 116);
u8g2.drawArc(94, 77, 46, 60, 116);
// Bottom arc Line
u8g2.drawLine(145, 50, 95, 50);
u8g2.drawLine(145, 51, 95, 51);
// Bottom arc
u8g2.drawArc(92, 75, 25, 60, 116);
u8g2.drawArc(93, 76, 25, 60, 116);
// Text
u8g2.setFont(u8g2_font_6x10_tr);
u8g2.drawStr(85, 62, "RPM x1000");
// Dynamic curved bar
drawCurvedBar(92, 75, 60, 116, 45, rpmValue, maxRPM);
}
void loop() {
u8g2.firstPage();
// I'll have to write a function pull data from the raspi
int currentBoost = 15; // Example value for boost
int maxBoost = 30; // Maximum boost value
int currentRPM = 4500; // Example value for RPM
int maxRPM = 8000; // Maximum RPM value
do {
boost();
rpm();
} while (u8g2.nextPage());
delay(500); // Refresh the bar every 500 ms
}