学习以下伪代码:Input:Sampling frequency times,sum temp_val,average value temp_avrg,fractional result floathumidity Output: Soil moisture value humidity 1: for t←0 to times 2: do temp_val+= AD_GetValue 3: temp_avrg←temp_val/times 4: floathumidity←(4095-temp_avrg)/4095*100 5: humidity← (int)floathumidity 6: return humidity 然后编写这个OLED显示的伪代码:
时间: 2024-02-16 13:00:54 浏览: 199
以下是基于你提供的伪代码编写的OLED显示的伪代码:
Input: Sampling frequency times, sum temp_val, average value temp_avrg, fractional result float humidity
Output: Soil moisture value humidity
1: for t ← 0 to times
2: do temp_val += AD_GetValue
3: temp_avrg ← temp_val/times
4: float humidity ← (4095-temp_avrg)/4095*100
5: int soil_moisture ← (int)humidity
6: OLED_display("Soil moisture: " + soil_moisture + "%")
注意,这只是一个简单的伪代码示例,实际应用中需要根据具体情况进行修改和调整。
相关问题
改写这段代码:u16 Get_Adc(u8 ch) { //设置指定ADC的规则组通道,一个序列,采样时间 ADC_RegularChannelConfig(ADC1, ch, 1, ADC_SampleTime_239Cycles5 ); //ADC1,ADC通道,采样时间为239.5周期 ADC_RegularChannelConfig(ADC1, ch, 2, ADC_SampleTime_239Cycles5 ); //ADC1,ADC通道,采样时间为239.5周期 ADC_SoftwareStartConvCmd(ADC1, ENABLE); //使能指定的ADC1的软件转换启动功能 while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC )); //等待转换结束 return ADC_GetConversionValue(ADC1); //返回最近一次ADC1规则组的转换结果 } u16 Get_Adc_Average(u8 ch,u8 times) { u32 temp_val=0; u8 t; for(t=0;t<times;t++) { temp_val+=Get_Adc(ch); delay_ms(5); } return temp_val/times; }
uint16_t Get_Adc(uint8_t ch) {
// 设置指定ADC的规则组通道,一个序列,采样时间
ADC_RegularChannelConfig(ADC1, ch, 1, ADC_SampleTime_239Cycles5); // ADC1, ADC channel, sampling time of 239.5 cycles
ADC_RegularChannelConfig(ADC1, ch, 2, ADC_SampleTime_239Cycles5); // ADC1, ADC channel, sampling time of 239.5 cycles
ADC_SoftwareStartConvCmd(ADC1, ENABLE); // 使能指定的ADC1的软件转换启动功能
while (!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)); // 等待转换结束
return ADC_GetConversionValue(ADC1); // 返回最近一次ADC1规则组的转换结果
}
uint16_t Get_Adc_Average(uint8_t ch, uint8_t times) {
uint32_t temp_val = 0;
uint8_t t;
for (t = 0; t < times; t++) {
temp_val += Get_Adc(ch);
delay_ms(5);
}
return temp_val / times;
}
阅读全文