DD2-monitor/simulator/rdtemp/rdtemp.ino

67 lines
1.5 KiB
Arduino
Raw Normal View History

/*
* lecture des capteurs de temperature LM35
*/
/* -------------------------------------------------- */
#define NBVAL 4
#define DELAI 12000
/* -------------------------------------------------- */
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
2019-02-24 02:39:04 +11:00
2019-01-28 00:59:26 +11:00
Serial.print("\n");
/* XXX */
/* changing the voltage reference of the ADC
* greatly increase the prcision on the limited
* range of our temperatures.
*/
analogReference(INTERNAL1V1); // Pour Arduino Mega2560
delay(1000);
2019-02-23 03:16:01 +11:00
Serial.print("M running\n");
}
/* -------------------------------------------------- */
2019-02-23 03:16:01 +11:00
/* ================================================== */
short adc_pins[] = { A0, A1, A2, A4 };
/* -------------------------------------------------- */
void updatevalues(short *ptr)
{
int foo;
2019-02-24 02:39:04 +11:00
digitalWrite(LED_BUILTIN, HIGH);
for (foo=0; foo<NBVAL; foo++) {
2019-02-23 03:16:01 +11:00
ptr[foo] = analogRead(adc_pins[foo]);
2019-02-24 02:39:04 +11:00
delay(200);
}
digitalWrite(LED_BUILTIN, LOW);
}
/* -------------------------------------------------- */
2019-02-23 03:16:01 +11:00
void sendvalues(short *ptr)
{
int foo;
Serial.print("T");
for (foo=0; foo<NBVAL; foo++) {
Serial.print(" ");
2019-02-23 03:16:01 +11:00
Serial.print(ptr[foo]);
}
Serial.print("\n");
}
/* -------------------------------------------------- */
2019-02-23 03:16:01 +11:00
void update_and_send(void)
{
short values[NBVAL];
updatevalues(values);
sendvalues(values);
}
/* ================================================== */
void loop() {
2019-02-23 03:16:01 +11:00
update_and_send();
delay(DELAI);
}
/* -------------------------------------------------- */