void loop() {
while (sample_count < MAX_SAMPLES) {
while (!R_ADC_Get_Result(ADC_RES_FIFO_16, &samples[sample_count]));
sample_count++;
}
R_TAU0_Channel0_Stop();
uint16_t max_sample = 0;
for (uint16_t i = 0; i < MAX_SAMPLES; i++) {
if (samples[i] > max_sample) {
max_sample = samples[i];
}
}
for (uint16_t i = 0; i < MAX_SAMPLES; i++) {
samples[i] = samples[i] * 4096 / max_sample;
}
R_PORT_Write(GPIO_PD1_PIN, 1);
for (uint16_t i = 0; i < MAX_SAMPLES; i++) {
while (!R_SAU0_Send((uint8_t*)&samples[i], 2));
}
R_PORT_Write(GPIO_PD1_PIN, 0);