【发布时间】:2021-02-11 13:10:57
【问题描述】:
我有以下代码来记录某个地方的温度并打印数据,但我希望它在两次测量之间等待 1 秒。我怎样才能做到这一点? (C++ arduino Uno)
int sensePin = A0; //TMP36 is plugged into pin A0
int sensorInput; //used to store sensor input
double temp; //used to store temperature once converted to degrees Celcius
void setup()//Setup code that defines anything that needs to be defined
{
Serial.begin(9600); //default start is 9600 baud on the serial monitor
}
void loop()//Main loop code where everything is executed
{
sensorInput = analogRead(A0); //this commands the arduino to read the sensor (TMP36) and store the data
temp = (double)sensorInput / 1024; //this will find the percentage of the input reading
temp = temp * 5; //since I used arduino's built-in 5V supply , multiply by 5 to get voltage
temp = temp - 0.5; //subtracts the offset
temp = temp * 100; //multiply by 100 to convert to degrees
Serial.print("Current Temperature: ");//this means that the converted temperature will be printed after *
Serial.println(temp); //* "Current Temperature" for neatness and ease of use
}
【问题讨论】: