add Loudness Block

This commit is contained in:
Amerlander 2020-08-22 10:16:42 +02:00
parent d62201bd88
commit 0c360e9a5d

View File

@ -77,4 +77,29 @@ namespace input {
export function runningTimeMicros() {
return control.micros();
}
/**
* gets the level of loudness in 0-100%
*/
//% blockId="loudness"
//% block="Loudness"
export function loudness(): number {
let value = 0
let max = 0
let min = 1023
for (let index = 0; index < 32; index++) {
value = pins.analogReadPin(50)
if (value > max) {
max = value
} else if (value < min) {
min = value
}
}
value = (max - min) * 977 / 10000
return value
}
}