Go Down

#### ivnnvi

##### Nov 08, 2012, 02:00 pm
hi, im making a project with POV , what im trying to do is to show trough the LEDs (POV) what a NTC temperature sensor is reading.
The problem is how can i put an integer value(int) to a char. Thanks.
PD. Each program works perfectly independent.

Code: [Select]
`// defining the alphabet#include "alphabet.h" // define the Arduino LED pins in useconst int LEDpins[] = {1,2,3,4,5,6,7}; // number of LEDs character height and widthint charHeight = sizeof(LEDpins); //sizeof its value from arduino codeint charWidth = 5;//Temperature const float voltage = 5.00;        const float B = 4100;const float unodivr = 93.0;const float resistor = 105000;     //Resistorint sensorPin = A0;                // select the input pin for the potentiometerint sensorValue = 0; void setup(){   pinMode(1, OUTPUT);   pinMode(2, OUTPUT);   pinMode(3, OUTPUT);   pinMode(4, OUTPUT);   pinMode(5, OUTPUT);   pinMode(6, OUTPUT);   pinMode(7, OUTPUT);      Serial.begin(9600);} void loop() {   // Part 1:  Read the analog port 0 and convert the value to volts.     sensorValue = analogRead(sensorPin);//read analog 0    float v2 = (voltage*float(sensorValue))/1024.0f;    // calculate volts in an awesome world   // Part 2: Calculate the resistance with the volt value trough the voltage divider ecuation   float r1a = (voltage*float(resistor))/v2;     float r1 =r1a - resistor;   //Part 3: Calculate the temperature based on the Steinhart-Hart equation based on the B value equation.     float K = B/log(r1*unodivr);//Temperature in Kelvin   int C=K-273;//Temperature in Celsius   Serial.println(C);   //PRoblem    } //Function for print the letters  void printLetter(char ch){  // make sure the character is within the alphabet bounds (defined by the alphabet.h file)   // if it's not, make it a blank character   if (ch < 32 || ch > 126){ch = 32;}   ch -= 32;// subtract the space character (converts the ASCII number to the font index number)   // step through each byte of the character array   for(int i=0; i<charWidth; i++){byte b = font[ch][i];        // bit shift through the byte and output it to the pin       for(int j=0; j<charHeight; j++){digitalWrite(LEDpins[j], !!(b & (1 << j)));}          // space between columns          delayMicroseconds(3000);   }        //clear the LEDs    digitalWrite(1 , LOW);   // set the LED on    digitalWrite(2 , LOW);   // set the LED on    digitalWrite(3 , LOW);   // set the LED on    digitalWrite(4 , LOW);   // set the LED on    digitalWrite(5 , LOW);   // set the LED on    digitalWrite(6 , LOW);   // set the LED on    digitalWrite(7 , LOW);   // set the LED on       // space between letters    delayMicroseconds(100);            // printing every letter of the textString   for (int k=0; k<sizeof(textString); k++){printLetter(textString[k]);}}`

#### liuzengqiang

#1
##### Nov 08, 2012, 02:49 pm
Code: [Select]
`char msg[5];sprintf(msg,"%4d",sensorValue);byte i=0;while(msg[i]){printLetter(msg[i]);i++;}`

#### ivnnvi

#2
##### Nov 09, 2012, 01:44 am
Thank you very much lidr. Everything its working perfect, repeat, thank very very much.

#### liuzengqiang

#3
##### Nov 09, 2012, 03:15 am
You are welcome. I have not been working on my own POV system for a while but I still remember those tricks.