From 3607708f8d389907cbb43924195564d9b4783f7e Mon Sep 17 00:00:00 2001 From: Eggert Jung Date: Tue, 4 Jun 2024 20:53:37 +0200 Subject: [PATCH] morse code interpretation --- Firmware/src/main.c | 85 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 12 deletions(-) diff --git a/Firmware/src/main.c b/Firmware/src/main.c index a5cb933..1b5af50 100644 --- a/Firmware/src/main.c +++ b/Firmware/src/main.c @@ -29,7 +29,46 @@ 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 */ const uint8_t PROGMEM emg_logo[640] = { @@ -135,28 +174,50 @@ int main(void) //LCD_Clear(); // loop forever - uint32_t counter = 0; - uint8_t button_state = 1; - uint8_t button_state_old = 1; + uint32_t counter = 0; + uint8_t button_state = 1; + uint8_t button_state_old = 1; + char inputstring[6]; + memset(inputstring, 0, sizeof(inputstring)); while (1){ button_state = !(PINA & 0x08); if( button_state == 1 && button_state_old == 0 ){ _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; } if( button_state == 0 && button_state_old == 1 ){ _delay_ms(20); - /* print to LCD */ - LCD_Clear(); - LCD_GotoXY(0, 0); - char msg[20]; - sprintf(msg, "time: %d", counter); - LCD_PutString(msg); + //LCD_Clear(); + //LCD_GotoXY(0, 0); + //char msg[20]; + //sprintf(msg, "time: %d", counter); + if(counter<500 && counter>=1){ + LCD_PutString("."); + strcat(inputstring, "."); + } + else if (counter>=500 && counter<1500){ + LCD_PutString("-"); + strcat(inputstring, "-"); + } + //LCD_PutString(msg); LCD_Update(); - /* ------------ */ - + /* ------------ */ counter = 0; }