Newbie Question! (int and char*)

Hi all,
I'll post my code then explain:

// RADIO - HABE 1 - The Explorer
// Code to output "Hello World!" to NTX2
// 50 Baud, RTTY

int Power_out = 2; //Pin for 5V DC Out is pin 2
int running_time = millis(); // Timer counting how long program has been running
#define RADIO_SPACE 5
#define RADIO_MARK  4
#define ASCII_BIT 8

void rtty_txstring (char * string) {
  char c;
  c = *string++;
  while ( c != '\0') {
    rtty_txbyte (c);
    c = *string++;
  }
}

void rtty_txbyte (char c) {
  int i;
  rtty_txbit (0); // Start bit
  // Send bits for for char LSB first      
  for (i=0; i<ASCII_BIT; i++) {
    if (c & 1) 
      rtty_txbit(1); 
    else
      rtty_txbit(0);      
    c = c >> 1;
  }
  rtty_txbit (1); // Stop bit
  rtty_txbit (1); // Stop bit 2
}

void rtty_txbit (int bit) {
  if (bit) {
    digitalWrite(RADIO_SPACE, LOW);
    digitalWrite(RADIO_MARK,  HIGH);
  } else {    
    digitalWrite(RADIO_SPACE, HIGH);
    digitalWrite(RADIO_MARK,  LOW);
  }
  // This works out to a baud rate of 50 bps. Somehow.
  delay(19);
  delayMicroseconds(250);
}


void setup() {
  pinMode(Power_out, OUTPUT);
  pinMode(RADIO_SPACE, OUTPUT);
  pinMode(RADIO_MARK, OUTPUT);
}

void loop() {
  digitalWrite (Power_out, HIGH); // Set power output pin to supply power (5V)
  rtty_txstring("Hello World!"); // Broadcast "Hello World!"
  delay(1000);
  rtty_txstring(running_time);
  delay(1000);
}

What I want to do is output the time that the arduino has been running the program for (running_time) however when I put it into rtty_txstring(running_time) it gives me the following error:

In function 'void loop()':
error: invalid conversion from 'int' to 'char*

:S The code i'm using is from someone elses project who has let me use it, so i'm not exactly sure what everything does as i'm only a newbie! It's probably a really simple solution, but I'm not sure!?!

Any ideas?

Thanks! :slight_smile:

rtty_txstring(running_time);

"running_time" is an "int", but "rtty_txstring" is expecting a string.
You need to use something like "itoa" to write the ASCII representation of "running_time" into a buffer, and then print that.
http://www.cplusplus.com/reference/clibrary/cstdlib/itoa/

Thanks!
Would this be fine with arduino? Specifically the..

#include <stdio.h>
#include <stdlib.h>

.. bit?

Well, the 'running_time' variable is an int type and 'rtty_txstring()' takes a char pointer (char *). Hence the compiler cannot convert from 'int' to 'char *'.

Try converting 'running_time' integer value to a string value with the following:

char rt_array[20];
sprintf(rt_array, "%d", running_time);

Then pass 'rt_array' to 'rtty_txstring' and not 'running_time'. This will then transmit the running time value as a string.

Would this be fine with arduino? Specifically the.. Code:
#include <stdio.h>
#include <stdlib.h>

shouldn't be needed.

However, this:int running_time = millis(); // Timer counting how long program has been running
is both incorrect ("millis" returns an unsigned long), and misleading, because "running_time" will be initialised before "setup" has run.
This probably isn't what you want.

Thanks guys, managed to get it working now using above suggestions!