-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pulse_Generator.ino
117 lines (107 loc) · 2.46 KB
/
Pulse_Generator.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
/* Pulse generator without delay
*
*
*/
const String psw = "jesus123";
const int pulseOut = 13;
int pulses=10, pulseTime=10, betweenTime=90;
float freq=10;
long interval = 1000;
char inChar;
String inputString, commandStr, amountStr, checkStr;
boolean stringComplete = false;
boolean accessRefused = true;
boolean error=false;
void setup()
{
Serial.begin(9600);
Serial.println("Successful connection!");
pinMode(pulseOut, OUTPUT);
}
void loop()
{
if (stringComplete)
{
if(inputString=="send")
{
Serial.println("Sending...");
//Serial.println("Sending: "+configString());
for(int i=0;i<pulses;i++)
{
// Pulse ON
digitalWrite(pulseOut, HIGH);
delay(pulseTime);
// Pulse OFF
digitalWrite(pulseOut, LOW);
delay(betweenTime);
}
Serial.println("Done!");
}
else if(inputString=="default")
{
pulses=10, pulseTime=10, betweenTime=90;
freq=1.0/(pulseTime+betweenTime)*1000.0;
//Serial.println("Configuration: "+configString());
}
else if(inputString=="check")
{
checkStr="check,";
checkStr+=pulses;
checkStr+=",";
checkStr+=pulseTime;
checkStr+=",";
checkStr+=betweenTime;
checkStr+=",";
Serial.println(checkStr);
}
else
{
commandStr=inputString.substring(0,2);
amountStr=inputString.substring(2,7);
if(commandStr=="PP")
pulses=amountStr.toInt();
else if(commandStr=="PT")
pulseTime=amountStr.toInt();
else if(commandStr=="BT")
betweenTime=amountStr.toInt();
else
error=true;
if(error)
{
Serial.println("Wrong command!");
error=false;
}
else
{
freq=1.0/(pulseTime+betweenTime)*1000.0;
//Serial.println("Configuration: "+configString());
}
}
stringComplete=false;
inputString="";
}
}
String configString()
{
String configurationStr="";
configurationStr+=pulses;
configurationStr+=" pulses at ";
configurationStr+=freq;
configurationStr+=" Hz\n(pulse time: ";
configurationStr+=pulseTime;
configurationStr+=" ms; time between pulses: ";
configurationStr+=betweenTime;
configurationStr+=" ms)";
return configurationStr;
}
void serialEvent()
{
while (Serial.available())
{
inChar = (char)Serial.read();
if (inChar == '\n')
stringComplete = true;
else
inputString += inChar;
}
}