-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeedometer.cpp
More file actions
40 lines (36 loc) · 1.33 KB
/
speedometer.cpp
File metadata and controls
40 lines (36 loc) · 1.33 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
#include "pointer.h"
#include "speedometer.h"
#include <Arduino.h>
#include <math.h>
int lowAngle = MIN_SPEED + 270;
int highAngle = MAX_SPEED - 10;
// Starts up the spedometer arc
void initSpeedometer() {
// Initializes the pointer for the speedometer
//TFT_eSPI tft = TFT_eSPI();
int sar = SPEED_ARC_RADIUS;
int sx = tft.width() / 2;
int sy = tft.height() / 2;
// Serial.printf("sx: %d\n ", sx);
// Serial.printf("sy: %d\n ", sy);
tft.drawSmoothArc(sx, sy, sar, sar, lowAngle, highAngle, SPEED_ARC_COLOR, BG_COLOR, false);
// Adds a tick mark every 20 degrees, 15 pixels long
// Also adds one in between each 20 degree segment, 10 pixels long
for (int i = 0; i <= 180; i += 20) {
float radian = radians(i);
tft.drawLine(sx + sar * cos(radian),
sy + sar * sin(radian),
sx + (sar - 15) * cos(radian),
sy + (sar - 15) * sin(radian),
SPEED_ARC_COLOR);
radian = radians(i + 10);
if (i >= 180){
break;
}
tft.drawLine(sx + sar * cos(radian),
sy + sar * sin(radian),
sx + (sar - 10) * cos(radian),
sy + (sar - 10) * sin(radian),
SPEED_ARC_COLOR);
}
}