investigate why variable delay is not working

This commit is contained in:
Vineet K 2024-04-15 22:38:55 -04:00 committed by kar
parent fc85413fa9
commit 9d751dc020

51
main.c
View File

@ -9,6 +9,7 @@
#include <avr/interrupt.h>
#define F_CPU 16000000UL
#define __DELAY_BACKWARD_COMPATIBLE__ /* to use variables with _delay_u/ms */
#include <util/delay.h>
#define P_RX 0
@ -16,29 +17,29 @@
#define P_SPKR 2
unsigned short freqs[] = {
100,
200,
250,
300,
350,
400,
500,
600,
700,
750,
1000,
1250,
1500,
1750,
2000,
3000,
4000,
5000,
6000,
7000,
8000
1 / 100 * 1e6 / 2,
1 / 200 * 1e6 / 2,
1 / 250 * 1e6 / 2,
1 / 300 * 1e6 / 2,
1 / 350 * 1e6 / 2,
1 / 400 * 1e6 / 2,
1 / 500 * 1e6 / 2,
1 / 600 * 1e6 / 2,
1 / 700 * 1e6 / 2,
1 / 750 * 1e6 / 2,
1 / 1000 * 1e6 / 2,
1 / 1250 * 1e6 / 2,
1 / 1500 * 1e6 / 2,
1 / 1750 * 1e6 / 2,
1 / 2000 * 1e6 / 2,
1 / 3000 * 1e6 / 2,
1 / 4000 * 1e6 / 2,
1 / 5000 * 1e6 / 2,
1 / 6000 * 1e6 / 2,
1 / 7000 * 1e6 / 2,
1 / 8000 * 1e6 / 2
};
unsigned char note = 0;
unsigned char note = 8;
unsigned char buttonpressed = 1;
int
@ -57,8 +58,10 @@ main(void)
//for (;;);
for (unsigned char n = 0;; n = (n + 1) % 2) {
if (!buttonpressed) continue;
_delay_us(71.43);
if (!buttonpressed && n == 0) continue;
_delay_us(freqs[note]);
// _delay_us(714.2857);
// _delay_us(70);
PORTD ^= 1 << P_SPKR;
}
}