Answer the question
In order to leave comments, you need to log in
Why is the remainder of division not calculated in Arduino?
We have code written in Arduino IDE:
void setup() {
Serial.begin(4800);
}
void loop() {
Serial.write((7 % 5) + 65);
}
Answer the question
In order to leave comments, you need to log in
The question can be considered closed, because. the problem turned out to be in Proteus, which I used for simulation.
arduino.ru/Reference/Serial/Write
arduino.ru/Reference/Serial/Print
See the difference?
In the first case, you will send the result as a binary code. And the port monitor will display something completely different from what you expect.
In the second case, you will send the result as ASCII text. That is, what you send, you will see in the monitor.
Try just for comparison:
Serial.write(65);
Serial.write("65");
Serial.print(65);
Conclusion: the problem is not in mathematics, the problem is in the format of outputting the result to the port.
UPD: TS uses Proteus for verification, I use Arduino Leonardo
division is through / :)
read arduino.ru/Reference/Arithmetic is useful :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question