I have three analog sensors like voltage, temperature and pressure. I need to measure the voltage and temperature every 10 ms and I need to measure the pressure alone every 30 ms by using the timers in an Arduino.
How can I do this?
May this help as starting point! Not tested
void setup() {
Serial.begin(9600);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
}
unsigned long previousMillis1;
unsigned long previousMillis2;
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis1 >= 10) {
int val1 = analogRead(A0);
int val2 = analogRead(A1);
Serial.print("Values from A0 and A1: ");
Serial.print(val1);
Serial.print(" ");
Serial.println(val2);
previousMillis1 = currentMillis;
}
if (currentMillis - previousMillis2 >= 30) {
int val3 = analogRead(A2);
Serial.print("Value from A2: ");
Serial.println(val3);
previousMillis2 = currentMillis;
}
}
millis()ormicros()depending on the rest of your code. Please share that code and explain what it should do