Dear all,
I have been struggling now for a looong time with this code. I think that I am nearly there, but alas, something is still not working...
I am collecting input from the serial monitor, running it through a conversion function, and then returning the output to the serial monitor.
The input is three numbers separated by commas.
The conversion function is intended to return an array of three values. For now it is only multiplying each of the original values by 10 to keep it simple.
However, it seems to return only three 0s.
I am pretty sure that I am doing something wrong in passing the array, and have been reading up, but I just cannot see what is wrong.
I do not get any compilation errors.
See code below.
I hope to end up with a function, which can convert HSV values to RGB, but this is the first step. I need to be able to master the basics first, and then expand.
So I'd much appreciate if you can tell what is wrong with my code.
Steps to reproduce:
Connect your Arduino.
Upload the code.
Open the Serial Monitor.
Enter into the Serial Monitor: 15,15,15
The Serial Monitor Output will show:
F
F
F
0
0
0
(the F's are ok, they are the hex value of 15, but the 0's are just plain wrong)
Best regards,
Lars
// LM:
// Read input, calculate, post output
// Testing basis for HSV converter and other general testing
int result[3];
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
// Serial.setTimeout(3000);
}
void loop() {
Serial.println("Enter RGB values, separated by commas: ex: 123,123,123");
// if there's any serial available, read it:
if (Serial.available() > 0) {
// look for the next valid integer in the incoming serial stream:
int red = Serial.parseInt();
// do it again:
int green = Serial.parseInt();
// do it again:
int blue = Serial.parseInt();
// End of input is detected with newline
if (Serial.read() == '\n') {
// print the three numbers in one string as hexadecimal:
Serial.println(red, HEX);
Serial.println(green, HEX);
Serial.println(blue, HEX);
int ConversionFunction(int red, int green, int blue);
Serial.println(result[0]);
Serial.println(result[1]);
Serial.println(result[2]);
}
delay(10000);
}
}
int ConversionFunction(int x, int y, int z) {
result[0] = x * 10;
result[1] = y * 10;
result[2] = z * 10;
return result[3];
}