segunda-feira, 10 de novembro de 2014

Making your arduino sketch support multiple languages

So you have an LCD attached to your arduino, and want to support multiple languages?

Let me show you how i solved this problem:

Inside your library folder, create a folder called languages. Inside this folder, save the file below as languages.h

 typedef enum Language  
 {  
    pt_br,  
    en_en  
 };  
 typedef enum Sentences  
 {  
    HELLO,  
    GOODBYE  
 };  

And the following code as languages.c

 char* pt_br[] = {"Olá","Tchau"};  
 char* en_en[] = {"Hello","Goodbye"};  
 char** languages[2] = {pt_br,en_en};  

This code shows you how to use the library


 #include <languages.h>  
 Language current_language;  
 extern char** languages[2];  
 void setup()   
 {  
  Serial.begin(9600);  
  current_language=pt_br; //pt_br, en_en  
 }  
 void loop()   
 {  
  Serial.println(languages[current_language][HELLO]);  
  Serial.println(languages[current_language][GOODBYE]);  
  if (current_language == pt_br)  
  {  
   current_language = en_en;  
  }  
  else  
  {  
   current_language = pt_br;  
  }  
  delay(1000);  
 }  

Let me know if you have suggestions on how to improve this.


Nenhum comentário:

Postar um comentário