-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSH1106_128x64.ino
174 lines (107 loc) · 3.13 KB
/
SH1106_128x64.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
* This is a modified code of the original code whose author is silas parker
*/
#include<U8g2lib.h>
#include<Wire.h>
#define PACKET_SYNC 0xFF
#define PACKET_VER 2
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
// icons for the ui
static const unsigned char left_ind[] U8X8_PROGMEM = {0x08,0x00,0x0c,0x00,0xfe,0x01,0xff,0x01,0xfe,0x01,0x0c,0x00,0x08,0x00};
static const unsigned char right_ind[] U8X8_PROGMEM = {0x20,0x00,0x60,0x00,0xff,0x00,0xff,0x01,0xff,0x00,0x60,0x00,0x20,0x00};
static const unsigned char fuel_warning[] U8X8_PROGMEM = {0x10,0x00,0x38,0x00,0x28,0x00,0x6c,0x00,0x6c,0x00,0xfe,0x00,0xee,0x00,0xff,0x01};
static const unsigned char parking_break_warning[] U8X8_PROGMEM = {0x7c,0x00,0x82,0x00,0x39,0x01,0x7d,0x01,0x7d,0x01,0x7d,0x01,0x39,0x01,0x82,0x00,0x7c,0x00};
int serial_byte;
struct truck_data
{
int speedd,RPM,fuel;
bool left,right,fuel_warn,parkbreak;
};
struct truck_data data;
void setup()
{
Serial.begin(115200);
u8g2.begin();
u8g2.setBitmapMode(1);
u8g2.setFontMode(1);
u8g2.clearBuffer();
u8g2.setBitmapMode(1);
u8g2.setFont(u8g2_font_profont22_tr);
u8g2.setCursor(10, 34);
u8g2.print("Starting");
u8g2.sendBuffer();
delay(1500);
u8g2.clearBuffer();
}
void skip_serial_byte()
{
(void)Serial.read();
}
void loop()
{
if (Serial.available() < 16)
return;
serial_byte = Serial.read();
if (serial_byte != PACKET_SYNC)
return;
serial_byte = Serial.read();
if (serial_byte != PACKET_VER)
{
u8g2.clearBuffer();
u8g2.setFontMode(1);
u8g2.setFont(u8g2_font_profont22_tr);
u8g2.drawStr(0, 36, "ERROR");
u8g2.sendBuffer();
return;
}
/*
* I'm using structure to store this data as we may pass variables to different
* function there by calling by reference which saves space
* bit channel
* 1 speed
* 2 rpm
* 3 break air press
* 4 break temp
* 5 fuel ratio
* 6 oil pressure
* 7 oil temp
* 8 water temp
* 9 battery vol
* 10 left indication
* 11 right indication
* 12 parrking break
* 13 fuel warning
*
*
*/
u8g2.clearBuffer();
//u8g2.drawFrame(1, 1, 126, 62);
data.speedd=Serial.read();
u8g2.setFont(u8g2_font_logisoso62_tn);
u8g2.setCursor(0,64);
u8g2.print(data.speedd);
skip_serial_byte();
skip_serial_byte();
skip_serial_byte();
// fuel ratio code here
//data.fuel=Serial.read();
skip_serial_byte();
skip_serial_byte();
skip_serial_byte();
skip_serial_byte();
// left ind code
//data.left=Serial.read();
//u8g2.setFont(u8g2_font_profont22_tr);
//u8g2.setCursor(4, 59);
// u8g2.print(data.left);
//right idi code
//data.right=Serial.read();
//parking break
//data.parkbreak=Serial.read();
//fuel warning
//data.fuel_warn=Serial.read();
skip_serial_byte();
skip_serial_byte();
skip_serial_byte();
u8g2.sendBuffer();
}