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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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++) {
  30. ptr[foo] = 0;
  31. }
  32. digitalWrite(LED_BUILTIN, HIGH);
  33. for (pass=0; pass<NB_PASSE; pass++) {
  34. for (foo=0; foo<NBVAL; foo++) {
  35. ptr[foo] += analogRead(adc_pins[foo]);
  36. delay(100);
  37. }
  38. }
  39. for (foo=0; foo<NBVAL; foo++) {
  40. ptr[foo] /= NB_PASSE;
  41. }
  42. digitalWrite(LED_BUILTIN, LOW);
  43. }
  44. /* -------------------------------------------------- */
  45. void sendvalues(short *ptr)
  46. {
  47. int foo;
  48. Serial.print("T");
  49. for (foo=0; foo<NBVAL; foo++) {
  50. Serial.print(" ");
  51. Serial.print(ptr[foo]);
  52. }
  53. Serial.print("\n");
  54. }
  55. /* -------------------------------------------------- */
  56. void update_and_send(void)
  57. {
  58. short values[NBVAL];
  59. updatevalues(values);
  60. sendvalues(values);
  61. }
  62. /* ================================================== */
  63. void loop() {
  64. update_and_send();
  65. delay(DELAI);
  66. }
  67. /* -------------------------------------------------- */