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 1000
  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. Serial.print("\n\n");
  19. delay(1000);
  20. Serial.print("M running now\n");
  21. }
  22. /* -------------------------------------------------- */
  23. /* ================================================== */
  24. short adc_pins[] = { A0, A1, A2, A4 };
  25. #define NB_PASSE 4
  26. /* -------------------------------------------------- */
  27. void updatevalues(short *ptr)
  28. {
  29. short foo, pass;
  30. for (foo=0; foo<NBVAL; foo++) { ptr[foo] = 0; }
  31. digitalWrite(LED_BUILTIN, HIGH);
  32. for (pass=0; pass<NB_PASSE; pass++) {
  33. for (foo=0; foo<NBVAL; foo++) {
  34. ptr[foo] += analogRead(adc_pins[foo]);
  35. delay(50);
  36. }
  37. }
  38. for (foo=0; foo<NBVAL; foo++) { ptr[foo] /= NB_PASSE; }
  39. digitalWrite(LED_BUILTIN, LOW);
  40. }
  41. /* -------------------------------------------------- */
  42. void sendvalues(short *ptr)
  43. {
  44. int foo;
  45. Serial.print("T");
  46. for (foo=0; foo<NBVAL; foo++) {
  47. Serial.print(" ");
  48. Serial.print(ptr[foo]);
  49. }
  50. Serial.print("\n");
  51. }
  52. /* -------------------------------------------------- */
  53. void update_and_send(void)
  54. {
  55. short values[NBVAL];
  56. updatevalues(values);
  57. sendvalues(values);
  58. }
  59. /* ================================================== */
  60. void loop() {
  61. update_and_send();
  62. delay(DELAI);
  63. }
  64. /* -------------------------------------------------- */