-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquantum_node_device_sigma.ino
116 lines (96 loc) · 2.01 KB
/
quantum_node_device_sigma.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
/*************************************************************
This is a simple demo of sending and receiving some data.
Be sure to check out other examples!
*************************************************************/
// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#define BLYNK_TEMPLATE_ID "TMPLivAjjUDQ"
#define BLYNK_DEVICE_NAME "Quantum Node Sigma"
#define BLYNK_AUTH_TOKEN "enterauthkeyhere"
#define W5100_CS 10
#define SDCARD_CS 4
char auth[] = BLYNK_AUTH_TOKEN;
int triggerPin = 2;
int hPin = A0;
int vPin = A1;
float H = 0;
float V = 0;
bool xtra = 0;
int x;
int y;
int z;
BlynkTimer timer;
BLYNK_WRITE(V0)
{
x = param.asInt();
}
BLYNK_WRITE(V2)
{
y = param.asInt();
}
BLYNK_WRITE(V4)
{
z = param.asInt();
}
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
pinMode(triggerPin, OUTPUT);
Blynk.begin(auth, "blynk.cloud", 80);
timer.setInterval(0L, quantum);
}
float angle() {
float a = degrees(atan(V / H));
return a;
}
void HGate() {
digitalWrite(triggerPin, HIGH);
digitalWrite(triggerPin, LOW);
H = analogRead(hPin);
V = analogRead(vPin);
}
int Rand() {
HGate();
if (H > V) {
return 0;
} if (H < V) {
return 1;
} else {
Rand();
}
}
void quantum() {
char val = Serial.read();
if (z == 1) {
Serial.print("\nH: ");
Serial.print(H);
Blynk.virtualWrite(V5, H);
Serial.print("\nV: ");
Serial.print(V);
Blynk.virtualWrite(V6, V);
Serial.print('\n');
}
if (x == 1) {
HGate();
Blynk.virtualWrite(V1, angle());
}
if (y == 1) {
Blynk.virtualWrite(V3, Rand());
}
if (val == 't') {
Serial.print("Success!\n");
}
if (val == 'v') {
Serial.print("Version 1.1\n");
}
}
void loop()
{
Blynk.run();
timer.run();
}