78 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			78 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
/*
 | 
						|
 * lecture des capteurs de temperature LM35
 | 
						|
 */
 | 
						|
/* -------------------------------------------------- */
 | 
						|
 | 
						|
#define NBVAL   4
 | 
						|
#define DELAI   10000
 | 
						|
 | 
						|
/* -------------------------------------------------- */
 | 
						|
void setup() {
 | 
						|
  Serial.begin(9600);
 | 
						|
  pinMode(LED_BUILTIN, OUTPUT);
 | 
						|
  
 | 
						|
  Serial.print("\n");
 | 
						|
  /* XXX */
 | 
						|
  /*  changing the voltage reference of the ADC
 | 
						|
   *  greatly increase the prcision on the limited
 | 
						|
   *  range of our temperatures.
 | 
						|
   */
 | 
						|
  analogReference(INTERNAL1V1); // Pour Arduino Mega2560
 | 
						|
  
 | 
						|
  delay(1000);
 | 
						|
  Serial.print("M running\n");
 | 
						|
  
 | 
						|
}
 | 
						|
/* -------------------------------------------------- */
 | 
						|
/* ================================================== */
 | 
						|
short adc_pins[] = { A0, A1, A2, A4 };
 | 
						|
#define NB_PASSE  4
 | 
						|
/* -------------------------------------------------- */
 | 
						|
void updatevalues(short *ptr)
 | 
						|
{
 | 
						|
  short foo, pass;
 | 
						|
 | 
						|
  for (foo=0; foo<NBVAL; foo++) { 
 | 
						|
    ptr[foo] = 0;
 | 
						|
    }   
 | 
						|
  digitalWrite(LED_BUILTIN, HIGH);
 | 
						|
  for (pass=0; pass<NB_PASSE; pass++) {
 | 
						|
    for (foo=0; foo<NBVAL; foo++) {
 | 
						|
      ptr[foo] += analogRead(adc_pins[foo]);
 | 
						|
      delay(100);
 | 
						|
      }
 | 
						|
    }
 | 
						|
  for (foo=0; foo<NBVAL; foo++) { 
 | 
						|
    ptr[foo] /= NB_PASSE;
 | 
						|
    }   
 | 
						|
  digitalWrite(LED_BUILTIN, LOW);
 | 
						|
}
 | 
						|
/* -------------------------------------------------- */
 | 
						|
void sendvalues(short *ptr)
 | 
						|
{
 | 
						|
  int foo;
 | 
						|
 | 
						|
  Serial.print("T");
 | 
						|
  for (foo=0; foo<NBVAL; foo++) {
 | 
						|
    Serial.print(" ");
 | 
						|
    Serial.print(ptr[foo]);
 | 
						|
    }
 | 
						|
  Serial.print("\n");
 | 
						|
}
 | 
						|
/* -------------------------------------------------- */
 | 
						|
void update_and_send(void)
 | 
						|
{
 | 
						|
  short values[NBVAL];
 | 
						|
  
 | 
						|
  updatevalues(values);
 | 
						|
  sendvalues(values);
 | 
						|
  
 | 
						|
}
 | 
						|
/* ================================================== */
 | 
						|
void loop() {
 | 
						|
  update_and_send();
 | 
						|
  delay(DELAI);
 | 
						|
}
 | 
						|
 | 
						|
/* -------------------------------------------------- */
 |