forked from labos-medialab/brava3.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
brava.c
95 lines (87 loc) · 1.96 KB
/
brava.c
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
#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal.h>
#define SS_PIN 4
#define RST_PIN 2
#define LCD_LIGHT 3
#define LOCK_PIN 13
MFRC522 mfrc522(SS_PIN, RST_PIN);
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
String dataString;
int line;
unsigned int lockTimeout = 60000;
void setup() {
Serial1.begin(250000);
Serial.begin(115200);
String pritnToSerial = "";
while(!pritnToSerial.startsWith("bravaBegin")){
pritnToSerial = Serial1.readStringUntil('\n');
if(pritnToSerial.length() > 2)
Serial.println(pritnToSerial);
}
SPI.begin();
lcd.begin(20, 4);
mfrc522.PCD_Init();
pinMode(LCD_LIGHT, OUTPUT);
pinMode(LOCK_PIN, OUTPUT);
digitalWrite(LCD_LIGHT, HIGH);
lcd.print("hello, world");
}
void loop() {
if(mfrc522.PICC_IsNewCardPresent()){
if(mfrc522.PICC_ReadCardSerial()){
Serial1.print("rfid:");
Serial1.println(mfrc522.PICC_ReturnUidString(&(mfrc522.uid)));
}
}
if(Serial.available()){
delay(5);
Serial1.print("fromSerial:")
Serial1.println(Serial.readStringUntil('\n'));
}
if(Serial1.available()){
delay(5); int a = int(Serial1.read() - '0');
switch(a){
case 0:
digitalWrite(LOCK_PIN, HIGH);
lockTimeout = 0;
break;
case 2:
//lcd stuff
line = char(Serial1.read()) - '0';
dataString = Serial1.readStringUntil('\n');
if(line < 4){
if(dataString.length() == 20){
lcd.setCursor(0,line);
lcd.print(dataString);
}
else{
Serial.println(dataString);
}
}
else{
int val = dataString.toInt();
analogWrite(LCD_LIGHT, val);
}
break;
default:
Serial1.print("wrong case ");
Serial1.println(a);
break;
}
while(Serial1.available()) Serial1.read();
}
if(lockTimeout <= 150){
lockTimeout++;
if(lockTimeout == 150)
digitalWrite(LOCK_PIN, LOW);
}
/* if(Serial.available()){
String data = Serial.readStringUntil('\n');
data = data + "\r\n";
Bluetooth.print(data);
}
while(Bluetooth.available()){
Serial.write(Bluetooth.read());
}/**/
}