Advertisement
Guest User

baaaar

a guest
Jun 19th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  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 j=0;
  18. float sum =0;
  19. float new_temp = Tr; // TODO: update this line to read new temp!
  20. temp_avg_arr[temp_avg_ind] = new_temp;
  21. for(j=0;j<TEMP_AVG_SIZE;j++)
  22. {
  23. if(temp_avg_arr[j]==1)
  24. temp_avg_arr[j]=new_temp;
  25. }
  26.  
  27. if(temp_avg_ind== 9){ // wrap around to start of array
  28. temp_avg_ind=0;
  29. }
  30. else{
  31. temp_avg_ind++;
  32. }
  33. for (j=0;j<TEMP_AVG_SIZE ;j++){
  34. sum+=temp_avg_arr[j];
  35. }
  36.  
  37. float current_avg=sum/TEMP_AVG_SIZE;
  38.  
  39. return (current_avg);
  40. // TODO: use current_avg for whatever
  41. //dbSerialPrintln(temp_avg_arr[TEMP_AVG_SIZE ]);
  42. //dbSerialPrintln(sensorValue);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement