DD2-monitor/simulator/rdtemp/rdtemp.ino

79 lines
1.7 KiB
Arduino
Raw Normal View History

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