I tried to represent the values of TSL 2591 Adafruit light sensor on my Arduino Serial Monitor, but for some reason, I could not do that. The Arduino Serial Monitor just enters some blank values and scrolls down. Here is the code:
uint16_t x = tsl.getLuminosity(TSL2591_VISIBLE);
y = float(tsl.getLuminosity(TSL2591_VISIBLE));
z = (y, DEC);
Serial.write((byte)z);
x
, y
, and z
are floats initially.
1 Answer 1
Use Serial.println(x); to print a number as text. Function write() sends the raw byte and Serial Monitor shows the character with that ASCII code, which is not valid or a not visible control character.
For the z = (y, DEC);
from Wikipedia:
In the C and C++ programming languages, the comma operator (represented by the token ,) is a binary operator that evaluates its first operand and discards the result, and then evaluates the second operand and returns this value (and type).
so z
is always 10 (value of constant DEC), which is ASCII code for the new line character
-
Comments are not for extended discussion; this conversation has been moved to chat.Majenko– Majenko2018年11月16日 18:48:22 +00:00Commented Nov 16, 2018 at 18:48
Serial.begin(9600)
?z = (y, DEC);
supposed to do?