Using setTimeout()

Hello, I am trying to get my code to run every half second using the setTimeout() command. I keep getting the error 'setTimeout was not declared in this scope. I am confused as to what to do. I just want to use it as a timer and not a variable of any sort.

 #include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 3
#define bus2 4
OneWire ourWire(ONE_WIRE_BUS);
OneWire ourWire2(bus2);
DallasTemperature sensors(&ourWire);
DallasTemperature sensors2(&ourWire2);

 volatile byte rpmcount;
 unsigned int rpm;
 unsigned long timeold;
 
 void setup()
 {
   Serial.begin(9600);
   attachInterrupt(0, rpm_fun, RISING);
   rpmcount = 0;
   rpm = 0;
   timeold = 0;
 }
 
void loop(){}

void Results(){
   //if ((timeold % 500) == 0) 
   { 
     sensors.requestTemperatures();
     Serial.print(sensors.getTempCByIndex(0));
     Serial.print("  ");
     sensors2.requestTemperatures();
     Serial.print(sensors2.getTempCByIndex(0));
     Serial.print(",         ");
     
     rpm = 30*1000/(millis() - timeold)*rpmcount;
     timeold = millis();
     rpmcount = 0;
     Serial.print(rpm);
     Serial.print(",  ");
     Serial.println(timeold);
     
     setTimeout("Results()", 500);
     
   }
 }

 void rpm_fun()
 {
   rpmcount++;
   //Each rotation, this interrupt function is run twice
 }

Thank you!

What gave you the impression that there existed a setTimeout() "command" that would run something every half second?

Is this what you are referring to?

I thought that setTImeout would run in intervals of whatever the parameters were set to. How would you go about this to have the loop iterate every half second?

michael_davidson:
I thought that setTImeout would run in intervals of whatever the parameters were set to. How would you go about this to have the loop iterate every half second?

BlinkWithoutDelay example.

Ok, I changed it. But its not running continuously. It outputs one line and doesn't show anything else. Any suggestions?

 #include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 3
#define bus2 4
OneWire ourWire(ONE_WIRE_BUS);
OneWire ourWire2(bus2);
DallasTemperature sensors(&ourWire);
DallasTemperature sensors2(&ourWire2);

 volatile byte rpmcount;
 unsigned int rpm;
 unsigned long timeold;
 long interval = 500;
 
 void setup()
 {
   Serial.begin(9600);
   attachInterrupt(0, rpm_fun, RISING);
   rpmcount = 0;
   rpm = 0;
   timeold = 0;
 }
 
void loop()
{
     unsigned long currentTime = millis();
     if(currentTime - timeold > interval) {   
       sensors.requestTemperatures();
       Serial.print(sensors.getTempCByIndex(0));
       Serial.print("  ");
       sensors2.requestTemperatures();
       Serial.print(sensors2.getTempCByIndex(0));
       Serial.print(",         ");
     
       rpm = 30*1000/(currentTime - timeold)*rpmcount;
       timeold = millis();
       rpmcount = 0;
       Serial.print(rpm);
       Serial.print(",  ");
       Serial.println(timeold);
       
   }
 }

 void rpm_fun()
 {
   rpmcount++;
   //Each rotation, this interrupt function is run twice
 }

Nevermind, I figured it out. Thank you!!!!! XD