/
main.ino
143 lines (122 loc) · 2.63 KB
/
main.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
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <RCSwitch.h>
#include <stdint.h>
#include <IRremote.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PN532.h>
#include <string.h>
#include "Keyboard.h"
//pin rfid
#define IRQ 1
#define RESET 0
//ir receiver
#define IR_RECEIVE_PIN 6
#define IR_SEND_PIN 9
int freq_ir = 38;
String irproducer = "";
uint16_t rawData[67];
String data = "";
int scanning = 1;
//pin sd
#define SD_PIN A5
bool sdbegin=false;
File file;
//pin button
#define buttonUp (A4)
#define buttonDown (A0)
#define buttonLeft (A3)
#define buttonSelect (A2)
#define buttonRight (A1)
//menu iniziale
int currentPage = 0;
int scelta = 0;
const int numPages = 5;
//sub menu
int currentPageSubMenu = 0;
int sceltaSubMenu = 0;
int numPagesSubMenu = 3;
//tamaguino
const int sound = 0;
#define button1Pin (A3)
#define button2Pin (A0)
#define button3Pin (A2)
int button1State = 0;
int button2State = 0;
int button3State = 0;
#define ACTIVATED LOW
//battery
#define analogInPin A4 // Analog input pin
int sensorValue; // Analog Output of Sensor
float calibration = 2.33;
int bat_percentage;
//carta per sbloccare
int buf[] = {115, 232, 15, 186};
bool tag = false;
//Rf definition
#define rfreceive 3
#define rftransmit A6
RCSwitch mySwitch = RCSwitch();
//rfid display
Adafruit_PN532 nfc(1, 0);
Adafruit_SSD1306 display(128, 64);
void setup() {
Serial.begin(9600);
Wire.begin();
//setup button
pinMode(buttonUp, INPUT_PULLUP);
pinMode(buttonDown, INPUT_PULLUP);
pinMode(buttonLeft, INPUT_PULLUP);
pinMode(buttonSelect, INPUT_PULLUP);
pinMode(buttonRight, INPUT_PULLUP);
//setup tamaguino
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
pinMode(button3Pin, INPUT_PULLUP);
pinMode(sound, OUTPUT);
//setup display
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.setTextColor(WHITE);
flopperblockedimage();
//setup rf
mySwitch.enableReceive(rfreceive);
mySwitch.enableTransmit(rftransmit);
//ir receiver sender
IrReceiver.begin(IR_RECEIVE_PIN);
IrSender.begin(IR_SEND_PIN);
//Setup rfid/nfc
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1);
}
nfc.SAMConfig();
if (SD.begin(SD_PIN)) {
sdbegin=true;
} else {
sdbegin=false;
}
}
void loop() {
switch (scelta) {
case 0:
displayMenu(); //Mostra il menu
break;
case 1:
badusb();
break;
case 2:
rfid();
break;
case 3:
ir();
break;
default:
currentPage = 0;
scelta = 0;
break;
}
}