-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquantum_node_email.ino
157 lines (122 loc) · 3.38 KB
/
quantum_node_email.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*************************************************************
This is a prototype of sending a command to receiving some quantum RNG by email.
*************************************************************/
// 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 "authkey"
#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;
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();
}
//send data by email
void emailOnButtonPress()
{
// *** WARNING: You are limited to send ONLY ONE E-MAIL PER 5 SECONDS! ***
// Let's send an e-mail when you press the button
// connected to digital pin 2 on your Arduino
int isButtonPressed = !digitalRead(2); // Invert state, since button is "Active LOW"
if (isButtonPressed) // You can write any condition to trigger e-mail sending
{
Serial.println("Button is pressed."); // This can be seen in the Serial Monitor
H++;
V++;
String body = String("You pushed the button ") + H + V + " H and V Values";
Blynk.email("[email protected]", "Subject: Button Logger", body);
// Or, if you want to use the email specified in the App (like for App Export):
//Blynk.email("Subject: Button Logger", "You just pushed the button...");
}
}
void setup()
{
Serial.begin(9600);
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
pinMode(13, OUTPUT);
pinMode(triggerPin, OUTPUT);
Blynk.begin(auth, "blynk.cloud", 80);
// Send e-mail when your hardware gets connected to Blynk Server
// Just put the recepient's "e-mail address", "Subject" and the "message body"
// e.g. to announce activation of Quantum Nodes Rho and Sigma, Mu and Nu in the network
Blynk.email("[email protected]", "Node Rho", "Quantum Node Rho is online.");
// Setting the button
pinMode(2, INPUT_PULLUP);
// Attach pin 2 interrupt to our handler
attachInterrupt(digitalPinToInterrupt(2), emailOnButtonPress, CHANGE);
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();
}