This repository was archived by the owner on Jul 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewArduinoCode.ino
More file actions
97 lines (86 loc) · 2.75 KB
/
NewArduinoCode.ino
File metadata and controls
97 lines (86 loc) · 2.75 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
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
#include <U8g2lib.h>
#include <SPI.h>
#include <MemoryFree.h>
U8G2_SSD1306_128X64_NONAME_F_HW_I2C screenController(U8G2_R0, 8, 13, 11);
String stringBase;
bool bluetoothStart = false;
bool isFirst = true;
void setup() {
Serial.begin(57600);
Serial1.begin(57600);
screenController.begin();
}
void loop() {
if(Serial1.available()){
char caractereSerial;
while (Serial1.available()) {
caractereSerial = Serial1.read();
if(caractereSerial == '\n'){
bluetoothStart = true;
}else{
stringBase.concat(caractereSerial);
}
}
}
if(bluetoothStart){
Serial.println(stringBase);
if(isFirst && !stringBase.equals("#ended")){
screenController.clearBuffer();
isFirst = false;
}
if(stringBase.equals("#ended")){
screenController.sendBuffer();
isFirst = true;
stringBase = "";
bluetoothStart = false;
Serial.println("");
return;
}
if(stringBase.charAt(1) == 'f'){
Serial.println(stringBase.substring(2));
Serial.println(stringBase.substring(2).toInt());
if(stringBase.substring(2) == "Freedom"){
screenController.setFont(u8g2_font_freedoomr10_tu);
}else{
switch(stringBase.substring(2).toInt()){
case 4:
screenController.setFont(u8g2_font_u8glib_4_tf);
break;
case 6:
screenController.setFont(u8g2_font_5x7_tf);
break;
case 8:
screenController.setFont(u8g2_font_6x10_tf);
Serial.println("FONT 8");
break;
case 12:
screenController.setFont(u8g2_font_7x14_tf);
break;
default:
screenController.setFont(u8g2_font_u8glib_4_tf);
}
}
stringBase = "";
bluetoothStart = false;
return;
}
if(stringBase.charAt(0) == '#'){
char stringArray[stringBase.length() - 4];
String text = stringBase.substring(5);
text.toCharArray(stringArray, stringBase.length() - 4);
screenController.drawStr(32 + (stringBase.substring(1, 3)).toInt(), 32 + (stringBase.substring(3, 5)).toInt(), stringArray);
}else{
screenController.drawPixel(32 + (stringBase.substring(0, 2)).toInt(), (stringBase.substring(2, 4)).toInt());
}
stringBase = "";
bluetoothStart = false;
}
if(Serial.available()){
char readA = Serial.read();
if(readA == '0'){ Serial1.println(0); /*Serial.println("Up");*/}
if(readA == '1'){ Serial1.println(1); /*Serial.println("Down"); */}
if(readA == '2'){ Serial1.println(2); /*Serial.println("Left"); */}
if(readA == '3'){ Serial1.println(3); /*Serial.println("Right"); */}
if(readA == '4'){ Serial1.println(4); /*Serial.println("Destroy"); */}
}
}