microsoft / pxt-adafruit

Microsoft MakeCode editor for Adafruit Circuit Playground Express
https://makecode.adafruit.com
Other
81 stars 77 forks source link

Set Loud Sound Threshold field picker #1149

Closed Jaqster closed 4 years ago

Jaqster commented 4 years ago

When using the Set Loud Sound Threshold block, the field picker values go from 0 to 100. Yet, in our documentation, it says the values go from 0 to 1023. Which one is right?

SetLoudSound

ganicke commented 4 years ago

According to the function in the microphone lib I think it should be 0 - 255:

/**
* Sets the minimum threshold for a loud sound
*/
//% help=input/set-loud-sound-threshold
//% blockId=input_set_loud_sound_threshold block="set loud sound threshold %value"
//% parts="microphone"
//% value.min=1 value.max=100
//% group="More" weight=14 blockGap=8
void setLoudSoundThreshold(int value) {
    value = max(0, min(0xff, value));
    const int scaled = MICROPHONE_MIN + value * (MICROPHONE_MAX - MICROPHONE_MIN) / 0xff;
    getWMicrophone()->level.setHighThreshold(scaled);
}

I'll change it to that in my initial fix PR. The value.max attribute should be 255 instead of 100.