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

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