Well I didn't think this would be difficult especially since I am not new at this, but I am having problems writing integer,long,double values to the Sparkfun Color LCD shield.
I have tried to typecast the int,long,double values to char and I get the error invalid conversion from 'char' to 'char*'
here is the code:
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "WProgram.h"
#include "HardwareSerial.h"
// External Component Libs
#include "LCD_driver.h"
void setup()
{
ioinit(); //Initialize I/O
LCDInit(); //Initialize the LCD
LCDContrast(45);
randomSeed(analogRead(0));
}
void loop()
{
char val1 = char(random(0,9));
LCDPutStr(val1,10,10,WHITE,BLACK);
}
Maybe I am just tired and I am doing something wrong any help is appreciated.
Thank You
Typecasting doesn't change the underlying data. For example, putting an orange into a bowl marked "apples" doesn't make it an apple.
I assume you want to see a number? So you need to convert from a number to a string (assuming the library doesn't support that). For example here is one way:
char buf [10];
sprintf (buf, "%i", random (0, 9));
LCDPutStr(buf,10,10,WHITE,BLACK);
Well I didn't think of that it worked like a charm though thank you so much
so what if I wanted to convert an analog input would it look like this?
char buf [100]; // I am assuming I would have to increase the buffer, or was ten used because I was using 0 through 9?
sprintf (buf, "%i", analogRead(2));
delay(250);
LCDPutStr(buf,10,10,WHITE,BLACK);
AnalogRead returns 0 to 1023, so you can see you only need 5 bytes to hold that (4 digits plus the terminating "null" at the end of the string). I used 10 simply to allow a bit of slack. The buffer "buf" just holds the converted string.
I just read that from a C++ reference so 10 should still work there thank you