Code: Select all
int level = 0;
int newlvl;
int maxlvl = 0;
int minlvl = 4095;
adc1_config_width(ADC_WIDTH_10Bit);
adc1_config_channel_atten(ADC1_CHANNEL_6, ADC_ATTEN_6db);
delay(2000);
// toggle led on each loop
// output values to terminal
while(1) {
level ^= 0x01;
gpio_set_level(LED_BUILTIN+1, level );
newlvl = adc1_get_voltage(ADC1_CHANNEL_6);
// update min/max
if(newlvl > maxlvl)
maxlvl = newlvl;
if(newlvl < minlvl)
minlvl = newlvl;
printf("***************************\n");
printf("level = %d\n", newlvl);
printf("max level = %d\n", maxlvl);
printf("min level = %d\n", minlvl);
printf("***************************\n");
delay(500);
}
Thank you.
Frank