Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float read_temp() {
- const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
- //const int analogOutPin = 9; // Analog output pin that the LED is attached to
- float sensorValue=0 ; // value read from the pot
- float Tr = 0; // value output to the PWM (analog out)
- // read the analog in value:
- sensorValue = analogRead(analogInPin);
- // map it to the range of the analog out:
- Tr = mapfloat(sensorValue, 644, 530, 41.3, 27.3);
- # define TEMP_AVG_SIZE 10
- int first_run =1;
- int j=0;
- float sum =0;
- float new_temp = Tr; // TODO: update this line to read new temp!
- temp_avg_arr[temp_avg_ind] = new_temp;
- if (first_rub ==1){
- for(j=0;j<TEMP_AVG_SIZE;j++) {
- if(temp_avg_arr[j]==1){
- temp_avg_arr[j]=new_temp;
- }
- }
- first_run=0;
- }
- if(temp_avg_ind== 9){ // wrap around to start of array
- temp_avg_ind=0;
- }
- else{
- temp_avg_ind++;
- }
- for (j=0;j<TEMP_AVG_SIZE ;j++){
- sum+=temp_avg_arr[j];
- }
- float current_avg=sum/TEMP_AVG_SIZE;
- return (current_avg);
- // TODO: use current_avg for whatever
- //dbSerialPrintln(temp_avg_arr[TEMP_AVG_SIZE ]);
- //dbSerialPrintln(sensorValue);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement