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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * lecture des capteurs de temperature LM35
  3. */
  4. /* -------------------------------------------------- */
  5. #define NBVAL 4
  6. #define DELAI 10000
  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. #define NB_PASSE 4
  25. /* -------------------------------------------------- */
  26. void updatevalues(short *ptr)
  27. {
  28. short foo, pass;
  29. for (foo=0; foo<NBVAL; foo++) { ptr[foo] = 0; }
  30. digitalWrite(LED_BUILTIN, HIGH);
  31. for (pass=0; pass<NB_PASSE; pass++) {
  32. for (foo=0; foo<NBVAL; foo++) {
  33. ptr[foo] += analogRead(adc_pins[foo]);
  34. delay(100);
  35. }
  36. }
  37. for (foo=0; foo<NBVAL; foo++) { ptr[foo] /= NB_PASSE; }
  38. digitalWrite(LED_BUILTIN, LOW);
  39. }
  40. /* -------------------------------------------------- */
  41. void sendvalues(short *ptr)
  42. {
  43. int foo;
  44. Serial.print("T");
  45. for (foo=0; foo<NBVAL; foo++) {
  46. Serial.print(" ");
  47. Serial.print(ptr[foo]);
  48. }
  49. Serial.print("\n");
  50. }
  51. /* -------------------------------------------------- */
  52. void update_and_send(void)
  53. {
  54. short values[NBVAL];
  55. updatevalues(values);
  56. sendvalues(values);
  57. }
  58. /* ================================================== */
  59. void loop() {
  60. update_and_send();
  61. delay(DELAI);
  62. }
  63. /* -------------------------------------------------- */