NIKITA PAWAR
New Coder
Hello guys I need to convert convert character pointer into floating point please share the code for it.
Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.
SignUp Now!
char * p; float f = (float)p;char * cp; float f; f = *(float *)cp;char * cp; float * fp = (float *)cp;Thanks for your replay. I've tried this before but didn't work for my project.Please describe your question in more detail.
If you want to convert char pointer into floating point, here is a way:
char * p; float f = (float)p;
If you want to convert char into float through pointer, this is the solution:
char * cp; float f; f = *(float *)cp;
If you want to convert char pointer to float pointer, here it is:
char * cp; float * fp = (float *)cp;
Distance should be convert into a floating number.Hello guys I need to convert convert character pointer into floating point please share the code for it.
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte ROWS = 4; /* four rows */
const byte COLS = 4; /* four columns */
/* define the symbols on the buttons of the keypads */
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'}, //A - Forward
{'4', '5', '6', 'B'}, //B - Reverse
{'7', '8', '9', 'C'}, //* -Start Again
{'*', '0', '#', 'D'} //# - Emmergency STOP
};
byte rowPins[ROWS] = {10, 11, 12, 13}; /* connect to the row pinouts of the keypad */
byte colPins[COLS] = {6, 7, 8, 9};
/* initialize an instance of class NewKeypad */
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
#define Reset 14
#define sw 2
int isObstaclePin = 3; // pin for sensor input
int motor_RW_control = 4; //reverse direction
int motor_FW_control = 5; //forward direction
int isObstacle = LOW; // HIGH MEANS NO OBSTACLE
static int Gnd_Data = 0, First_Data, Second_Data, Third_Data, Fourth_Data, Fifth_Data, Sixth_Data;
int Reset_state = 0, FSW_state = 0, RSW_state = 0, First_Floor_state = 0, Second_Floor_state = 0, Third_Floor_state = 0, Fourth_Floor_state = 0, Fifth_Floor_state = 0, Sixth_Floor_state = 0;
int count = 0, check_flag, Serial_Data = 0, key_flag = 0, sw_state = 0, test_sw_state = 0, flag_init = 1, FLAG = 1, start = 0;
char Floor, *Distance, key;
static int No_Count, lastread;
int Value, flr_select = 0, Floor_Count, icursor = 0;
char *Emmergency = "EMMERGENCY BUTTON PRESSED";
int EmmergencyLen = strlen(Emmergency);
char *Resetmsg = "RESET BUTTON PRESSED";
int ResetmsgLen = strlen(Resetmsg);
void Init()
{
while (start == 0)
{
sw_state = digitalRead(sw);
if (sw_state == HIGH)
{
while (FLAG == 1)
{
Serial.print("Enter the floor count:");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("floor count: ");
while (1)
{
char customKey = customKeypad.getKey();
Floor = customKey;
Serial.print(Floor);
if (customKey)
{
lcd.setCursor(13, 0);
lcd.print(customKey); delay(150);
}
if (Floor > 0)
{
break;
}
delay(200);
}
Serial.print("Enter the distance:");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("distance:");
while (1)
{
char customKey = customKeypad.getKey();
Distance = chartoint(customKey); //This should be converted into float number
if (customKey)
{
if (customKey == '#')
{
lcd.print("mm"); Serial.print("mm"); delay(200);
FLAG = 0; break;
}
Serial.print(customKey);
lcd.print(customKey);
}
}
}
Serial.println("\nSelect the Motor Direcion : \n7.UP 8.DOWN");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("7.UP");
lcd.setCursor(0, 1);
lcd.print("8.DOWN");
while (1)
{
char customKey = customKeypad.getKey();
if (customKey == '7')
{
forward_init();
/****** RESET ******/
//char *resetmsg = "Press Reset switch for Reset back to ground";
//int resetlen = strlen(resetmsg);
while (1)
{
Serial.println("Press Reset switch for Reset back to ground ");
//scroll_display(resetmsg, resetlen);
Reset_state = digitalRead(Reset);
if (Reset_state == HIGH)
{
Serial.println("RESET BUTTON PRESSED");
scroll_display(Resetmsg, ResetmsgLen);
Serial.println("R/W Motor ON");
reverse_init();
return;
}
delay(350);
}
/*char *resetmsg = "Press 8 for Reset back to ground";
int resetlen = strlen(resetmsg);
lcd.clear();
while (1)
{
scroll_display(resetmsg, resetlen);
char customKey = customKeypad.getKey();
if (customKey == '8')
{
reverse_init(); start = 1;
return;
}
delay(350);
}*/
return;
}
}
}
if (start == 1)
{
break;
}
}
}
Code Forum is a community platform where coding enthusiasts can connect with other developers, engage in discussions, ask for help, and share their knowledge with a supportive community. It's a perfect place to improve your coding skills and to find a community of like-minded individuals who share your passion for coding.
We use essential cookies to make this site work, and optional cookies to enhance your experience.