【问题标题】:Trying to get this to wait 1 second between readings (C++ Arduino)试图让它在读数之间等待 1 秒(C++ Arduino)
【发布时间】: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
}

【问题讨论】:

标签: c++ wait timing


【解决方案1】:

我认为你可以使用 delay函数

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-13
    • 2018-01-02
    • 1970-01-01
    • 1970-01-01
    • 2016-09-03
    • 2015-05-02
    • 2016-09-03
    • 1970-01-01
    相关资源
    最近更新 更多