-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquantum_node_device_rho.ino
130 lines (108 loc) · 2.45 KB
/
quantum_node_device_rho.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
/*************************************************************
quantum node rho for use with BLYNK IOT Phone App
written by John Campbell
Now with some new lines in the void loop for time complexity measures
which print out in the serial monitor
*************************************************************/
// 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 "TMPLve3FHVE9"
#define BLYNK_DEVICE_NAME "Quantum Node Rho "
#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()
{
//now with time complexity measures
// 1. Store the start time
unsigned long timeBegin = micros();
// 2. Execute main action
Blynk.run();
timer.run();
// 3. Store the end time
unsigned long timeEnd = micros();
// 4. Compute duration
unsigned long duration = timeEnd - timeBegin;
double averageDuration = duration / 1000;
Serial.println(averageDuration);
}