Monitoring du Phytotron
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rdtemp.ino 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * lecture des capteurs de temperature LM35
  3. */
  4. /* -------------------------------------------------- */
  5. #define NBVAL 4
  6. #define DELAI 12000
  7. /* -------------------------------------------------- */
  8. void setup() {
  9. Serial.begin(9600);
  10. pinMode(LED_BUILTIN, OUTPUT);
  11. Serial.print("\n");
  12. /* XXX */
  13. /* changing the voltage reference of the ADC
  14. * greatly increase the prcision on the limited
  15. * range of our temperatures.
  16. */
  17. analogReference(INTERNAL1V1); // Pour Arduino Mega2560
  18. delay(1000);
  19. Serial.print("M running\n");
  20. }
  21. /* -------------------------------------------------- */
  22. /* ================================================== */
  23. short adc_pins[] = { A0, A1, A2, A4 };
  24. /* -------------------------------------------------- */
  25. void updatevalues(short *ptr)
  26. {
  27. int foo;
  28. for (foo=0; foo<NBVAL; foo++) {
  29. ptr[foo] = analogRead(adc_pins[foo]);
  30. delay(200);
  31. }
  32. }
  33. /* -------------------------------------------------- */
  34. void sendvalues(short *ptr)
  35. {
  36. int foo;
  37. Serial.print("T");
  38. for (foo=0; foo<NBVAL; foo++) {
  39. Serial.print(" ");
  40. Serial.print(ptr[foo]);
  41. }
  42. Serial.print("\n");
  43. }
  44. /* -------------------------------------------------- */
  45. void update_and_send(void)
  46. {
  47. short values[NBVAL];
  48. updatevalues(values);
  49. sendvalues(values);
  50. }
  51. /* ================================================== */
  52. void loop() {
  53. update_and_send();
  54. delay(DELAI);
  55. }
  56. /* -------------------------------------------------- */