Afternoon from the UK, I know this has probably been asked millions of times but I cannot wrap my head around something. I have working code but I just dont like it, it doesnt look 'propper' (either is that grammar).
So a bit backwards but here is my working code:
if (subscription == &lightcontrol)
{
Serial.print(F("Got: "));
String valueReceivedS = String((char *)lightcontrol.lastread);
int valueReceived = valueReceivedS.toInt();
Serial.println(valueReceived);
switch (valueReceived)
{
case 1 //Calm
break;
case 2 //Bright
break;
case 3 //Disco
break;
case 4 //Off
break;
case 5 //Disco
}
}
lightcontrol.lastread Is an object which having a snoop within the class reveal that it retuns a uInt8_t variable. A byte right?
I convert it to a string of which i then convert it to a integer on the line below.
Now I thought the following would be 'nicer' and work: (im not too fussed about it becoming an int but not a string!)
char valueReceived = char((char *)lightcontrol.lastread);
or this?
char valueReceived = (char *) lightcontrol.lastread;
or this?
char valueReceived = char((char *) lightcontrol.lastread);
or this?
byte valueReceived = byte((char *) lightcontrol.lastread);
And could someone explain the use of asterix? I get its a pointer, but why?
another question, why cant i use (string) casting why do i have to encapsulate?
How would you guys about this? I have a solution im just not fond of it.