Arduino RTTY

#include <baudot.h>
#include <RTTY.h>
int val;

void setup() {

  RTTY.attach(12);

}

void loop()
{
  val = random(1, 10);
  delay(1000);
  RTTY.tx(val);
delay(1000);

}

I have this library where all I have to do is attach a speaker to the output and the code is as simple as RTTY.tx(string). This works just fine as long as I have RTTY.tx("string"). But whenever I try to output an int, I just get random letters on the receiving side. This really confused me. Is there something I'm doing wrong?

Which RTTY library are you using?
It looks to me like tx() only takes a string as an argument. It shouldn't compile if you try to tx an integer but if somehow it does take the integer, it will be treated as the address of a string and pick some area of memory and try to send garbage from there.

Pete

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags:
[code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool but it's still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.

Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into logical sections is fine but large spaces for no reason or random blank lines just make for more scrolling when we're trying to read your code.

Try this:

#include <baudot.h>
#include <RTTY.h>
int val;

void setup() {
  RTTY.attach(12);
}

void loop() {
  val = random(1, 10);
  char valString[1+5+1];  // sign + 5 digits + terminator
  itoa(val, valString, 10);  // convert integer to a string in base 10
  RTTY.tx(valString);
  delay(2000);
}

More information:
http://www.cplusplus.com/reference/cstdlib/itoa/

Thank you for the information, could I just put a analog sensor output into val? Would it still work or would I have to change the numbers?

By "the numbers" I assume you mean the size of the array. I sized the array so that it can hold a 5 digit number to allow you to use it for any value that an int will hold assuming an int is 16 bits (which it is on the AVR-based Arduinos but not on other architectures). If you're only going to be working with values 0-1023 then you could actually get by with 4 + 1 (4 digits + terminator) but there's no problem with 7, it just unnecessarily uses an extra 2 bytes of memory.

Hi,
How does this work?? Is the "Speaker" output a tone that is frequency-shifted bit by bit? Do you intend to transmit that as FSK data on some RF link?