ErfanDL
February 17, 2022, 9:10am
1
Hi guys. I want to print an integer with if(Serial) then starting the loop for ever but can't success. anyone can help ?
I want print "Customer1000", wait for 4 seconds then starting analog A0 in loop forever.
thanks and sorry for bad english.
String id = "Customer1000";
void setup()
{
Serial.begin(115200);
}
void loop()
{
int sensorValue = analogRead(A0);
if (Serial) {
Serial.print(id);
delay(4000);
}
Serial.println(sensorValue);
}
J-M-L
February 17, 2022, 9:25am
2
If you want to do something only once, have that in the setup
void setup() {
Serial.begin(115200);
while(!Serial); // only needed on some arduino. Will block if no serial link can be established
Serial.print(F("Customer1000"));
delay(4000);
}
void loop() {
Serial.println(analogRead(A0));
}
1 Like
I would suggest adding a delay in the loop otherwise you will flood the serial port.
J-M-L
February 17, 2022, 11:06pm
4
Not sure what you mean by flood
print() will block if the outgoing buffer is full, but there is probably little point reading that fast
1 Like
system
Closed
August 16, 2022, 11:06pm
5
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.