add Loudness Block
This commit is contained in:
parent
d62201bd88
commit
0c360e9a5d
@ -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
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user