Settled on this being the best looking on the actual mask

This commit is contained in:
William Miceli
2020-08-27 23:46:48 -04:00
parent 290c40d288
commit 33eb3b9d80
7 changed files with 9722 additions and 8159 deletions

View File

@@ -620,34 +620,40 @@ static void MX_GPIO_Init(void)
/* USER CODE BEGIN 4 */
uint8_t getSoundLevel(void){
// Adjustment / Calibration
static uint8_t divisor = 2;
static uint8_t postscale_DownShift = 0;
static uint8_t prescale_DownShift = 180;
static uint8_t multiplier = 3;
static uint8_t cutoff = 90;
static uint16_t averagedDifferences = 0;
// By order of process
uint8_t samples[8];
uint16_t estimatedSoundLevel = 0;
static uint16_t averagedReturnValue = 0;
uint16_t returnValue;
uint8_t samples[16];
uint16_t sumOfDifferences = 0;
for(uint8_t i = 0; i < sizeof(samples); ++i){
HAL_Delay(1);
HAL_ADC_Start(&hadc3);
HAL_ADC_PollForConversion(&hadc3, (uint32_t) 20);
samples[i] = HAL_ADC_GetValue(&hadc3);
}
for(uint8_t i = 0; i < sizeof(samples) - 1; ++i){
sumOfDifferences += abs(samples[i] - samples[i + 1]);
for(uint8_t i = 0; i < sizeof(samples); ++i){
estimatedSoundLevel += samples[i];
}
estimatedSoundLevel /= sizeof(samples);
if(estimatedSoundLevel <= cutoff){
returnValue = 0;
}else{
returnValue = (uint16_t) (2 * (estimatedSoundLevel - cutoff));
}
averagedDifferences += ((int32_t) sumOfDifferences - (int32_t) averagedDifferences) / 4;
averagedReturnValue += ((int32_t) returnValue - (int32_t) averagedReturnValue) / 3;
if(averagedDifferences < prescale_DownShift){returnValue = 0;}else{returnValue = averagedDifferences - prescale_DownShift;}
returnValue = (returnValue / divisor) * multiplier;
if(returnValue < postscale_DownShift){returnValue = 0;}else{returnValue -= postscale_DownShift;}
if(returnValue >= 0xFF){return 0xFF;} else{return returnValue;}
if(averagedReturnValue >= 0xFF){
return 0xFF;
}else if(averagedReturnValue <= 10){
return 0x00;
}else{
return averagedReturnValue;
}
}
void LEDDesign_Off(void){
for(uint8_t i = 0; i < 64; ++i){