Non ASCII letter

Hi

I have problems with reading and evalueting non ASCII letters.

I am makeing a morse code generator and my code goes like this:

char text[] = "morse text";

int ledPin = 13;
int tempo = 1000;    // timing of one dot

void setup () {
   Serial.begin(9600);    //debugging
   pinMode(ledPin, OUTPUT);
}

void dot() {                        // we need more dots
   digitalWrite(ledPin, HIGH);
   delay(1 * tempo);
   digitalWrite(ledPin, LOW);
   delay(1 * tempo);
}

void dash() {                    // a dash and a splash
   digitalWrite(ledPin, HIGH);
   delay(3 * tempo);
   digitalWrite(ledPin, LOW);
   delay(1 * tempo);
}


void morse(char letter) {                    // time to transmit
   if (letter == 'a' or letter == 'A') {dot(); dash();}
   ...                                                  // code left out
   ...                                                  // code left out

   delay(2 * tempo);      // this makes 3 * tempo for letter end
}

void loop () {
   for (int i = 0; i < sizeof(text); i++) {
     morse(text[i]);
   }
}

and it goes ok.

I’m using the nomenklature from http://en.wikipedia.org/wiki/Morse_code but I get into trouble then it comes to the Non-English extensions.

For national reason I would like to add:

if (letter == 'æ' or letter == 'Æ')

but since ‘æ’ ain’t in the ASCII chart it ain’t working if æ is added to the

char text[] = "æ";

A quick survey with Serial.println(’‘æ’, DEC); showes that the letter has an value around -15 thousinde; so surley it’s way out of range for the char data type.

What can I do to include my national letters?

A possible workaround would be to use vacant ASCII letter for ‘æ’, ‘ø’ and ‘å’, but that would make the text look gibbish.

-Fletcher

How is the "æ" going to be entered as an input into your system? Whatever generates that will be communicating in binary. Just look for that value whatever it is.

I'm not sure how you're going to convert æ to a Morse-code though.

Since those special characters have the high bit set, when you put them in a char, which is an 8-bit signed integer, it will treat it as a negative number.

Change 'char text[]' to 'byte text[]'. The 'byte' says it's an unsigned char.

Regards,

-Mike

Hi
Thanks for the answers.

Mitch: The morse tekst in imbedded in the program; it’s the first line. An “æ” korrospond to dot dash dot dash according to wikipedia.

Mike: I changed from char to byte. When looking at Serialprint it seems like 2 numbers are transmittet. A 195 and another number. The 195 comes each time an æ/Æ/ø/Ø/å/Å is transmittet but the 2’th number is variading. I just sniffed the 2’th number for the letters I was interested in and used that in my code.

Btw, here is the full code:

byte text[] = "All your base are belong to us";         // Transmittet text

// Morse code generator for the Arduino
// Transmitted text is placed in the first line
// Tempo sets the speed of a dot etc.
// Morde code was tanken from http://en.wikipedia.org/wiki/Morse_code
// Text is looping and prior to transmitting the active pin blinks rapidly
// Version 1.0, made by Eivind Triel

int ledPin = 13;                       // Active led pin
int tempo = 500;                       // timing of one dot


void setup () {
  pinMode(ledPin, OUTPUT);
}

void start(){                         // rapid blink at startup
  for(int i = 0; i < 50; i++){
    digitalWrite(ledPin, HIGH);
    delay(25);
    digitalWrite(ledPin, LOW);
    delay(25);
  }
  delay(7 * tempo);
}

void dot() {                          // we need more dots
  digitalWrite(ledPin, HIGH);
  delay(1 * tempo);
  digitalWrite(ledPin, LOW);
  delay(1 * tempo);          
}

void dash() {                        // a dash and a splash
  digitalWrite(ledPin, HIGH);
  delay(3 * tempo);
  digitalWrite(ledPin, LOW);
  delay(1 * tempo);
}

void morse(byte letter) {           // time to transmit
  Serial.println(letter, DEC);
  if (letter == 'a' or letter == 'A') {dot(); dash();}
  if (letter == 'b' or letter == 'B') {dash(); dot(); dot(); dot();}
  if (letter == 'c' or letter == 'C') {dash(); dot(); dash(); dot();}
  if (letter == 'd' or letter == 'D') {dash(); dot(); dot();}
  if (letter == 'e' or letter == 'E') {dot();}
  if (letter == 'f' or letter == 'F') {dot(); dot(); dash(); dot();}
  if (letter == 'g' or letter == 'G') {dash(); dash(); dot();}
  if (letter == 'h' or letter == 'H') {dot(); dot(); dot(); dot();}
  if (letter == 'i' or letter == 'I') {dot(); dot();}
  if (letter == 'j' or letter == 'J') {dot(); dash(); dash(); dash();}
  if (letter == 'k' or letter == 'K') {dash(); dot(); dash();}
  if (letter == 'l' or letter == 'L') {dot(); dash(); dot(); dot();}
  if (letter == 'm' or letter == 'M') {dash(); dash();}
  if (letter == 'n' or letter == 'N') {dash(); dot();}
  if (letter == 'o' or letter == 'O') {dash(); dash(); dash();}
  if (letter == 'p' or letter == 'P') {dot(); dash(); dash(); dot();}
  if (letter == 'q' or letter == 'Q') {dash(); dash(); dot(); dash();}
  if (letter == 'r' or letter == 'R') {dot(); dash(); dot();}
  if (letter == 's' or letter == 'S') {dot(); dot(); dot();}
  if (letter == 't' or letter == 'T') {dash();}
  if (letter == 'u' or letter == 'U') {dot(); dot(); dash();}
  if (letter == 'v' or letter == 'V') {dot(); dot(); dot(); dash();}
  if (letter == 'w' or letter == 'W') {dot(); dash(); dash();}
  if (letter == 'x' or letter == 'X') {dash(); dot(); dot(); dash();}
  if (letter == 'y' or letter == 'Y') {dash(); dot(); dash(); dash();}
  if (letter == 'z' or letter == 'Z') {dash(); dash(); dot(); dot();}
  if (letter == '1') {dot(); dash(); dash(); dash(); dash();}
  if (letter == '2') {dot(); dot(); dash(); dash(); dash();}
  if (letter == '3') {dot(); dot(); dot(); dash(); dash();}
  if (letter == '4') {dot(); dot(); dot(); dot(); dash();}
  if (letter == '5') {dot(); dot(); dot(); dot(); dot();}
  if (letter == '6') {dash(); dot(); dot(); dot(); dot();} 
  if (letter == '7') {dash(); dash(); dot(); dot(); dot();}
  if (letter == '8') {dash(); dash(); dash(); dot(); dot();}
  if (letter == '9') {dash(); dash(); dash(); dash(); dot();}
  if (letter == '0') {dash(); dash(); dash(); dash(); dash();}
  if (letter == ' ') {delay(5 * tempo);}                        // This makes 7 * tempo for space

  // and now for some national/special letters
  // values were foundt with Serial.print(letter, DEC)
  
  if (letter == 166 or letter == 134) {dot(); dash(); dot(); dash();}     // æ/Æ is recognized as 166/134
  if (letter == 184 or letter == 152) {dash(); dash();dash();dot();}      // ø/Ø is recognized as 184/152
  if (letter == 165 or letter == 133) {dot();dash();dash();dot();dash();} // å/Å is recognized as 165/133
  
  delay(2 * tempo);      // this makes 3 * tempo for letter end, and 7 * tempo for space    
}

  
void loop () {
  start();
  for (int i = 0; i < sizeof(text); i++) {
    morse(text[i]);
  }
}

-Fletcher