forked from monur/ArduCamMonitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPCVideo.ino
75 lines (65 loc) · 1.98 KB
/
PCVideo.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
#define PIN_SCE 7
#define PIN_RESET 6
#define PIN_DC 5
#define PIN_SDIN 4
#define PIN_SCLK 3
#define LCD_C LOW
#define LCD_D HIGH
#define LCD_X 84
#define LCD_Y 6
#define bufferSize 4
byte frameStart[] = {0x80, 0x01, 0x80, 0x01};
byte buffer[bufferSize];
void setup(){
LcdInitialise();
delay(500);
Serial.begin(115200);
}
void loop(){
while(Serial.available() > 0){
byte b = Serial.read();
for(int i = 0; i < bufferSize-1; i++){
buffer[i] = buffer[i+1];
}
buffer[bufferSize-1] = b;
boolean isFrameStart = true;
for(int i = 0; i < bufferSize; i++){
if(buffer[i] != frameStart[i])
isFrameStart = false;
}
if(isFrameStart){
LcdWrite(LCD_C, 0x80 ); //select X Address 0 of the LCD Ram
LcdWrite(LCD_C, 0x40 ); //select Y Address 0 of the LCD Ram - Reset is not working for some reason, so I had to set these addresses
}else{
//for(int i = 0; i < bufferSize; i++){
LcdWrite(LCD_D, b);
//}
}
}
}
void LcdInitialise(void){
pinMode(PIN_SCE, OUTPUT);
pinMode(PIN_RESET, OUTPUT);
pinMode(PIN_DC, OUTPUT);
pinMode(PIN_SDIN, OUTPUT);
pinMode(PIN_SCLK, OUTPUT);
delay(200);
digitalWrite(PIN_RESET, LOW);
delay(500);
digitalWrite(PIN_RESET, HIGH);
LcdWrite(LCD_C, 0x21 ); // LCD Extended Commands.
LcdWrite(LCD_C, 0xB1 ); // Set LCD Vop (Contrast).
LcdWrite(LCD_C, 0x04 ); // Set Temp coefficent. //0x04
LcdWrite(LCD_C, 0x14 ); // LCD bias mode 1:48. //0x13
LcdWrite(LCD_C, 0x0C ); // LCD in normal mode.
LcdWrite(LCD_C, 0x20 );
LcdWrite(LCD_C, 0x80 ); //select X Address 0 of the LCD Ram
LcdWrite(LCD_C, 0x40 ); //select Y Address 0 of the LCD Ram - Reset is not working for some reason, so I had to set these addresses
LcdWrite(LCD_C, 0x0C );
}
void LcdWrite(byte dc, byte data){
digitalWrite(PIN_DC, dc);
digitalWrite(PIN_SCE, LOW);
shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data);
digitalWrite(PIN_SCE, HIGH);
}