DD2-monitor/simulator/rdtemp/rdtemp.ino

114 lines
2.3 KiB
Arduino
Raw Normal View History

/*
2019-04-29 11:40:22 +02:00
* Phytotron
* lecture des capteurs de temperature LM35
*/
/* -------------------------------------------------- */
#define NBVAL 4
2019-04-12 16:10:56 +02:00
#define DELAI 1000
2019-04-30 16:49:21 +02:00
typedef struct {
unsigned short magic;
char tag[4];
short delai;
} Global;
Global parametres;
/* -------------------------------------------------- */
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-29 11:40:22 +02:00
2019-04-29 17:46:14 +02:00
phytocli(); /* XXX */
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-14 11:33:52 +02:00
Serial.print("\n\n");
delay(1000);
2019-04-14 11:33:52 +02:00
Serial.print("M running now\n");
2019-03-27 21:52:16 +01:00
}
2019-02-22 17:16:01 +01:00
/* ================================================== */
2019-04-27 21:44:48 +02:00
/*
* the light captor is on A4 pin
*/
void readlight(void)
{
short value;
delay(100);
value = analogRead(A4);
Serial.print("L ");
Serial.print(value);
Serial.print('\n');
}
/* ================================================== */
short adc_pins[] = { A0, A1, A2, A3 };
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]);
}
2019-04-27 21:44:48 +02:00
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-27 21:44:48 +02:00
2019-02-22 17:16:01 +01:00
}
/* ================================================== */
void loop() {
2019-04-27 21:44:48 +02:00
static int foo = 0;
2019-02-22 17:16:01 +01:00
update_and_send();
2019-04-27 21:44:48 +02:00
if (foo++ > 5) {
readlight(); foo = 0;
2019-04-29 17:46:14 +02:00
}
/* check for CLI request */
if (Serial.available() && 0x55==Serial.read())
{
Serial.println("M cli request");
phytocli();
}
2019-04-27 21:44:48 +02:00
delay(DELAI);
}
/* -------------------------------------------------- */