-
Notifications
You must be signed in to change notification settings - Fork 7
/
new_and_modified_hacknite_model_with_buzzer1.ino
183 lines (169 loc) · 3.26 KB
/
new_and_modified_hacknite_model_with_buzzer1.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
int ledPin = 9;
int led = ledPin;
// Start the Serial Monitor
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void space() {
delay(1200);
}
void dot() {
digitalWrite(led, HIGH);
delay(300);
digitalWrite(led, LOW);
delay(300);
}
void dash() {
digitalWrite(led, HIGH);
delay(900);
digitalWrite(led, LOW);
delay(300);
}
void gap() {
delay(600);
}
// It takes each character and map it to the morse code output
void morse(char input) {
Serial.println(input);
if (input == 'a' || input == 'A') {
dot();
dash();
} else if (input == 'b' || input == 'B') {
dash();
dot();
dot();
dot();
} else if (input == 'c' || input == 'C') {
dash();
dot();
dash();
dot();
} else if (input == 'd' || input == 'D') {
dash();
dot();
dot();
} else if (input == 'e' || input == 'E') {
dot();
} else if (input == 'f' || input == 'F') {
dot();
dot();
dash();
dot();
} else if (input == 'g' || input == 'G') {
dash();
dash();
dot();
} else if (input == 'h' || input == 'H') {
dot();
dot();
dot();
dot();
} else if (input == 'i' || input == 'I') {
dot();
dot();
} else if (input == 'j' || input == 'J') {
dot();
dash();
dash();
dash();
} else if (input == 'k' || input == 'K') {
dash();
dot();
dash();
} else if (input == 'l' || input == 'L') {
dot();
dash();
dot();
dot();
} else if (input == 'm' || input == 'M') {
dash();
dash();
} else if (input == 'n' || input == 'N') {
dash();
dot();
} else if (input == 'o' || input == 'O') {
dash();
dash();
dash();
} else if (input == 'p' || input == 'P') {
dot();
dash();
dash();
dot();
} else if (input == 'q' || input == 'Q') {
dash();
dash();
dot();
dash();
} else if (input == 'r' || input == 'R') {
dot();
dash();
dot();
} else if (input == 's' || input == 'S') {
dot();
dot();
dot();
} else if (input == 't' || input == 'T') {
dash();
} else if (input == 'u' || input == 'U') {
dot();
dot();
dash();
} else if (input == 'v' || input == 'V') {
dot();
dot();
dot();
dash();
} else if (input == 'w' || input == 'W') {
dot();
dash();
dash();
} else if (input == 'x' || input == 'X') {
dash();
dot();
dot();
dash();
} else if (input == 'y' || input == 'Y') {
dash();
dot();
dash();
dash();
} else if (input == 'z' || input == 'Z') {
dash();
dash();
dot();
dot();
} else if (input == ' ') {
space();
}
gap();
}
void loop() {
char n;
int len = 0;
int len1 = 0;
char c;
int choice = 0;
String binval;
Serial.println("Please enter 0 for buzzer as output and 1 for led as output");
while (Serial.available() == 0) {
}
c=Serial.read();
Serial.println("Please enter your string: ");
// Loop which waits for user to enter string in Serial Monitor
while (Serial.available() == 0) {
}
String input = Serial.readString();
input.trim();
Serial.read();
choice=c-'0';
ledPin=ledPin+choice;
led=led+choice;
len = input.length();
Serial.println(input);
for (int i = 0; i < len; i++) {
n = input.charAt(i);
morse(n);
}
}