-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
65 lines (55 loc) · 1.87 KB
/
main.cpp
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
#include "mbed.h"
#include"beep.h"
int morse[26] = {21,1112,1212,112,1,1211,122,1111,11,2221,
212,1121,22,12,222,1221,2122,121,111,2,
211,2111,221,2112,2212,1122};
DigitalOut buzzer(PTB0);
//DigitalOut myled(LED1);
/*DigitalIn gnd(PTB2);
DigitalOut zero(PTC1);
DigitalOut one(PTC2);*/
Serial pc(USBTX,USBRX);
int main(){
int alpha_input;
int temp,c,t;
pc.printf("Please enter the letter to hear morse \n");
while(1){
if(pc.readable()){
alpha_input = pc.getc();
pc.putc(alpha_input);
pc.printf("\n yo %d : ",(int)alpha_input);
if(alpha_input<123 && alpha_input>96){
alpha_input=alpha_input - 97;
}
else if(alpha_input<91 &&alpha_input>64){
alpha_input=alpha_input-65;
}
else{
pc.printf("Invalid character\n");
}
c=alpha_input;
if(c>=0 && c<26)
{
temp = morse[c];
while(temp!=0){
t=temp%10;
temp=temp/10;
if(t==1){
buzzer=1;
wait(0.1);
buzzer=0;
pc.putc('.');
}
else if(t==2){
buzzer=1;
wait(0.25);
buzzer=0;
pc.putc('-');
}
wait(0.2);
}
}
wait(0.5);
}
}
}