hi I am doing a course on Arduino programming and this code is supposed to print 40 infinite times in the serial monitor. Yet when I upload the code, it only gets printed once in the serial monitor. I am using an Arduino uno. Why is my code not working?
int encodeNumber(int number)
{
return (number + 3) * 5;
}
void printEncodedNumber(int number)
{
Serial.println(encodeNumber(number));
}
int number1 = 5;
int number2 = 6;
int encodedNumber1;
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
encodedNumber1 = encodeNumber(number1);
int encodedNumber2 = encodeNumber(number2);
printEncodedNumber(number1);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(encodedNumber1);
}
I am using one sent from my school (it says elegoo uno r3) and I am using windows 10 Arduino IDE (latest version which is from the windows store 1.8.15.
The elego uses the same TTL-to-USB converter as the genuine Uno; so I've removed the dust from my genuine Uno and tested your code; again it behaves as epected. Using IDE 1.8.13 but I don't think that that matters.
Maybe add a small delay (e.g. delay(100);) at the end of loop() might solve the problem.
Maybe changing to a normal install instead of the windows store version might do the trick; the windows store version seems to have some problems at occsion.
I reinstalled Arduino as suggested, same issue. I also implemented (delay 100); at the end of loop() as suggested and still did not fix the issue. Do you think the issue perhaps is on my end with my microcontroller and not the code/Arduino?
You can tick the solution checkbox under your last post so people that might encounter the same problem know that a (maybe not very satisfing) solution was provided.
It's not "very satifying" because we don't know what was wrong. But at least you can continue.