morse code interpretation

master
Eggert Jung 1 year ago
parent 58fe6ef3b1
commit 3607708f8d

@ -29,7 +29,46 @@
while (((PINA)&0x08)) \ while (((PINA)&0x08)) \
; \ ; \
} }
static const char *alpha[] = {
".-", //A
"-...", //B
"-.-.", //C
"-..", //D
".", //E
"..-.", //F
"--.", //G
"....", //H
"..", //I
".---", //J
"-.-", //K
".-..", //L
"--", //M
"-.", //N
"---", //O
".--.", //P
"--.-", //Q
".-.", //R
"...", //S
"-", //T
"..-", //U
"...-", //V
".--", //W
"-..-", //X
"-.--", //Y
"--..", //Z
};
static const char *num[] = {
"-----", //0
".----", //1
"..---", //2
"...--", //3
"....-", //4
".....", //5
"-....", //6
"--...", //7
"---..", //8
"----.", //9
};//stackoverflow.com
/* clang-format off */ /* clang-format off */
const uint8_t PROGMEM emg_logo[640] = const uint8_t PROGMEM emg_logo[640] =
{ {
@ -138,25 +177,47 @@ int main(void)
uint32_t counter = 0; uint32_t counter = 0;
uint8_t button_state = 1; uint8_t button_state = 1;
uint8_t button_state_old = 1; uint8_t button_state_old = 1;
char inputstring[6];
memset(inputstring, 0, sizeof(inputstring));
while (1){ while (1){
button_state = !(PINA & 0x08); button_state = !(PINA & 0x08);
if( button_state == 1 && button_state_old == 0 ){ if( button_state == 1 && button_state_old == 0 ){
_delay_ms(20); _delay_ms(20);
if( counter>=2000 ){
for( uint8_t i = 0; i <26; i++){
int a = strcmp(alpha[i], inputstring);
if(a == 0){
LCD_PutChar("\t");
LCD_PutChar(65+i);
}
}
//LCD_PutString("\t");
//LCD_PutString(inputstring);
LCD_PutString("\r\n");
//LCD_Clear();
memset(inputstring, 0, sizeof(inputstring));
}
counter = 0; counter = 0;
} }
if( button_state == 0 && button_state_old == 1 ){ if( button_state == 0 && button_state_old == 1 ){
_delay_ms(20); _delay_ms(20);
/* print to LCD */ /* print to LCD */
LCD_Clear(); //LCD_Clear();
LCD_GotoXY(0, 0); //LCD_GotoXY(0, 0);
char msg[20]; //char msg[20];
sprintf(msg, "time: %d", counter); //sprintf(msg, "time: %d", counter);
LCD_PutString(msg); if(counter<500 && counter>=1){
LCD_PutString(".");
strcat(inputstring, ".");
}
else if (counter>=500 && counter<1500){
LCD_PutString("-");
strcat(inputstring, "-");
}
//LCD_PutString(msg);
LCD_Update(); LCD_Update();
/* ------------ */ /* ------------ */
counter = 0; counter = 0;
} }

Loading…
Cancel
Save