Advertisement
barohayon

Eden_readTemp_v3

Jun 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. float read_temp() {
  3.  
  4. const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
  5. //const int analogOutPin = 9; // Analog output pin that the LED is attached to
  6.  
  7. float sensorValue=0 ;        // value read from the pot
  8. float Tr = 0;        // value output to the PWM (analog out)
  9.    
  10.  
  11.   // read the analog in value:
  12.   sensorValue = analogRead(analogInPin);
  13.  
  14.   // map it to the range of the analog out:
  15.   Tr = mapfloat(sensorValue, 644, 530,  41.3,  27.3);
  16.  # define TEMP_AVG_SIZE 10
  17.     int first_run =1;
  18.     int j=0;
  19.     float sum =0;
  20.     float new_temp = Tr; // TODO: update this line to read new temp!
  21.     temp_avg_arr[temp_avg_ind] = new_temp;
  22.     if (first_rub ==1){
  23.         for(j=0;j<TEMP_AVG_SIZE;j++) {
  24.             if(temp_avg_arr[j]==1){
  25.                 temp_avg_arr[j]=new_temp;
  26.             }
  27.         }
  28.         first_run=0;
  29.     }
  30.    
  31.     if(temp_avg_ind== 9){ // wrap around to start of array
  32.         temp_avg_ind=0;
  33.     }
  34.     else{
  35.         temp_avg_ind++;
  36.     }
  37.     for (j=0;j<TEMP_AVG_SIZE ;j++){
  38.         sum+=temp_avg_arr[j];
  39.     }
  40.    
  41.     float current_avg=sum/TEMP_AVG_SIZE;
  42.  
  43.     return (current_avg);
  44.     // TODO: use current_avg for whatever
  45.      //dbSerialPrintln(temp_avg_arr[TEMP_AVG_SIZE ]);
  46. //dbSerialPrintln(sensorValue);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement