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

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