Hello,
I am a beginner at Adruino programming with prior knowledge on C procedural programming and I am hoping you could clarify some things for me.
Project:
- Input text;
- Convert into Morse Code;
- Display output by turning an LED on and off for specific time spans;
What I have done so far:
I have learnt how to turn on and off an LED on my Adruino and implemented it successfully using the following code:
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
I have a .c source file for a console application/executable that successfully converts a an input string of a specific format into morse code and displays it:
(Runs successfully on Devc++ IDE and Visual Studio)
#include <stdio.h>
#include <stdlib.h>
char* convertString(char*);
char inputString(FILE fp, size_t size){
//The size is extended by the input with the value of the provisional (using memory re allocation functions)
char *str;
int ch;
size_t len = 0;
str = realloc(NULL, sizeof(char)size);//size is start size
if(!str)return str;
while(EOF!=(ch=fgetc(fp)) && ch != '\n'){
str[len++]=ch;
if(len==size){
str = realloc(str, sizeof(char)(size+=16));
if(!str)return str;
}
}
str[len++]='\0';
return realloc(str, sizeof(char)*len);
}
int main(void){
// Main function to create basic UI display, request input and do function calls
char *m;
printf("###############Morse Code Encryption####################\n\n\n\n");
printf("Input a string (UPPERCASEANDWITHNOSPACING): ");
m = inputString(stdin, 10);
//printf("%s\n", m); // test
convertString(m);
printf("\n\nThank you for using PSprograms inc.\n");
printf("We will bill you the total sum of 667 GBP in the next 3 working days.\n");
printf("Take care!");
free(m); //memory deallocation
getch();
return 0;
}
char* convertString(char *m)
{
const char * arrayalphabet[26] = {"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"};
const char * arraymorse[26] = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
const char * output[900]; //think on size and what happens when SPACE
int i;
int z;
int len = strlen( m );
char *temp;
printf("\nEncrypted results:\n\n");
for (i = 0; i < len; i++)
{
temp = m*;*
- printf("%c = ", temp); // test*
- for (z = 0; z < 26; z++)*
- {*
_ if (temp == *arrayalphabet[z])_ - {*
- printf("%s\n", arraymorse[z]);*
- } *
- } *
- }*
}
My question is then: How do I bridge the gap and interface with the Adruino from my C program.
I do realize i might be looking at this whole thing from a wrong perspective so please do set me on the right track.