noob library problems

Hi guys,

I'm new to Arduino, and loving it so far!

I am having trouble importing the TextString library for use in my program. I'm also including the full sketch here, just in case you have any feedback for me! I haven't yet been able to compile it to test it out, since I can't figure out how to get the TextString lib to import. I've used C in the past, but I'm most familiar with PHP. So my understanding of how arrays work here may be totally whacked.

The lib/targets/libraries folder doesn't exist in my default installation. Creating one didn't seem to work, so I tried putting the library files inside the hardware/libraries folder. This seemed to work at a glance, but now when I try to compile I'm getting errors I don't understand... but then again, it could just be my code.

Here's my first rev. Let me know if I'm approaching this totally the wrong way!! Thanks!

Adam

//BlinkAO v0.1, by Adam OHern.
//Takes a string and echos it in morse code on an LED in pin 13.
//Requires TextString library

#include <TextString.h> 

char theString = "Drunkenness is his best virtue, for he will be swine drunk, and in his sleep he does little harm, save to his bedclothes about him.";

int ledPin = 13;

int dit = 100;

int dah = 3*dit;
int gap = dit;
int letter = dah;
int space = 7*dit;
loadMorseVars();

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

void loop()
{
  for(i=0;i<theString.length();i++)
  {
    char theChar[] = theString.getCharAt[i];
    if(theChar.equals(' '))
    {
      digitalWrite(ledPin, LOW);
      delay(space);
    }
    else
    {
      char theMorse[] = ascii[theString.getCharAt[i]-'0'];
      for(j=0;j<theMorse.length();j++)
      {
        theBit = theMorse.getCharAt[j];
        if(theBit.equals(' '))
        {
          digitalWrite(ledPin, LOW);
          delay(gap); 
        }
        else if(theBit.equals('·'))
        {
          digitalWrite(ledPin, HIGH);
          delay(dit);
          digitalWrite(ledPin, LOW);
        }  
        else if(theBit.equals('—'))
        {
          digitalWrite(ledPin, HIGH);
          delay(dah);
          digitalWrite(ledPin, LOW);
        }
      }
    }
  }
}
 
void loadMorseVars() 
{
  char ascii[127];
  ascii[65] = "· —"; //A
  ascii[66] = "— · · ·"; //B
  ascii[67] = "— · — ·"; //C
  ascii[68] = "— · ·"; //D
  ascii[69] = "·"; //E
  ascii[70] = "· · — ·"; //F
  ascii[71] = "— — ·"; //G
  ascii[72] = "· · · ·"; //H
  ascii[73] = "· ·"; //I
  ascii[74] = "· — — —"; //J
  ascii[75] = "— · —"; //K
  ascii[76] = "· — · ·"; //L
  ascii[77] = "— —       "; //M
  ascii[78] = "— ·"; //N
  ascii[79] = "— — —"; //O
  ascii[80] = "· — — ·"; //P
  ascii[81] = "— — · —"; //Q
  ascii[82] = "· — ·"; //R
  ascii[83] = "· · ·"; //S
  ascii[84] = "—"; //T
  ascii[85] = "· · —"; //U
  ascii[86] = "· · · —"; //V
  ascii[87] = "· — —"; //W
  ascii[88] = "— · · —"; //X
  ascii[89] = "— · — —"; //Y
  ascii[90] = "— — · ·"; //Z
  ascii[97] = "· —"; //a
  ascii[98] = "— · · ·"; //b
  ascii[99] = "— · — ·"; //c
  ascii[100] = "— · ·"; //d
  ascii[101] = "·"; //e
  ascii[102] = "· · — ·"; //f
  ascii[103] = "— — ·"; //g
  ascii[104] = "· · · ·"; //h
  ascii[105] = "· ·"; //i
  ascii[106] = "· — — —"; //j
  ascii[107] = "— · —"; //k
  ascii[108] = "· — · ·"; //l
  ascii[109] = "— —       "; //m
  ascii[110] = "— ·"; //n
  ascii[111] = "— — —"; //o
  ascii[112] = "· — — ·"; //p
  ascii[113] = "— — · —"; //q
  ascii[114] = "· — ·"; //r
  ascii[115] = "· · ·"; //s
  ascii[116] = "—"; //t
  ascii[117] = "· · —"; //u
  ascii[118] = "· · · —"; //v
  ascii[119] = "· — —"; //w
  ascii[120] = "— · · —"; //x
  ascii[121] = "— · — —"; //y
  ascii[122] = "— — · ·"; //z
  ascii[48] = "— — — — —"; //0
  ascii[49] = "· — — — —"; //1
  ascii[50] = "· · — — —"; //2
  ascii[51] = "· · · — —"; //3
  ascii[52] = "· · · · —"; //4
  ascii[53] = "· · · · ·"; //5
  ascii[54] = "— · · · ·"; //6
  ascii[55] = "— — · · ·"; //7
  ascii[56] = "— — — · ·"; //8
  ascii[57] = "— — — — ·"; //9
  ascii[46] = "· — · — · —"; //.
  ascii[44] = "— — · · — —"; //,
  ascii[63] = "· · — — · ·"; //?
  ascii[39] = "· — — — — ·"; //'
  ascii[33] = "— · — · — —"; //!
  ascii[47] = "— · · — ·"; ///
  ascii[40] = "— · — — ·"; //(
  ascii[41] = "— · — — · —"; //)
  ascii[38] = "· — · · ·"; //&
  ascii[58] = "— — — · · ·"; //:
  ascii[59] = "— · — · — ·"; //;
  ascii[61] = "— · · · —"; //=
  ascii[43] = "· — · — ·"; //+
  ascii[45] = "— · · · · —"; //-
  ascii[95] = "· · — — · —"; //_
  ascii[34] = "· — · · — ·"; //"
  ascii[36] = "· · · — · · —"; //$
  ascii[64] = "· — — · — ·"; //@
}

I doubt the TextString library will be of much help for what you want to do. but if you do want to get the TextString library going under Arduino version 0012, the library should be located in: hardware/libraries/TextString

You need to make some changes to the library code to get it to compile:
in TextString.h, comment out this line:
//#include "WConstants.h" <- comment this out for 0012 – mem

Add the following at the start of TextString.cpp:
#undef int // add this for 0012 – mem

But for what you want to do, I think it is easier just using C character arrays.

C strings are terminated by a null so pseudocode for parsing morse would be something like:

char * myString = “test string”;

for( int i=0; ; i++){
char c = myString ;

  • if( c!= 0)*
  • doMorse(c);*
  • else*
  • break; // end of string so exit the for loop*
    }
    void doMorse(char c){
  • // code added here to look up the morse values in morseMap for the given character*
  • // convert c to upper case, filter invalid chars and convert value so char 'A' starts as value 0, 'B' as 1 etc.*

}

char *morseMap[] = {

  • ".-",*
  • "-...",*
  • "-.-.",*
  • "-..",*
  • ".",*
  • "..-.",*
  • "—.",*
  • "....",*
  • "..",*
  • ".—-",*
  • "-.-",*
  • ".-..",*
  • "—",*
  • "-.",*
  • "—-",*
  • ".—.",*
  • "—.-",*
  • ".-.",*
  • "...",*
  • "-",*
  • "..-",*
  • "...-",*
  • ".—",*
  • "-..-",*
  • "-.—",*
  • "—.."*
    };
    good luck!

wow, thanks a ton!! I'll play with that and see where I end up. Thanks again!