I'm writing a sketch for the Arduino board and am using the following C++ code to do so. I'm trying to convert decimal numbers to binary by passing a decimal through the dec2bin function which is to return a character array that I will then print out. However, I'm getting the error:
"Incompatible types of assignment of 'char' to 'char [0]'"
at the function call to dec2bin and I'm receiving another error at the return inside of the dec2bin function that says:
"Invalid conversion from 'char*' to 'char' [-fpermissive]"
If anyone could please assist me with this it would be greatly appreciated. I need to use a character array here and not a string! Thank you!
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0){
char BinaryNum [0];
int Decimal = Serial.parseInt();
BinaryNum = dec2bin(Decimal);
Serial.println (BinaryNum);
}
}
char dec2bin (int Decimal){
int Remainder; // Remainder of Decimal%2
char Binary [0]; // Character array returned by dec2bin
int x = 0;
while (Decimal != 0 ){
Remainder = Decimal%2;
Decimal = Decimal/2;
Binary[x] = Remainder;
Serial.println(Binary[x]);
x+=1;
}
return Binary;
}