Sound4Calc/src/main.c

68 lines
1.2 KiB
C

#include "main.h"
#include "sound4calc.h"
#include <timer.h> // add timer's fonction
#include <display.h> // add display's fonction
#include <keyboard.h>
//#define PI 3.141592653584
unsigned char bincod[25] = {0};
unsigned char place = 0;
void lect()
{
static unsigned char range = 0;
if(bincod[range%place] != bincod[(range+1)%place])
{
SwitchPinState();
}
range++;
}
int main(void)
{
static int freq = 440;
unsigned int key = 0;
//unsigned int i=0;
InitPorts();
while(1)
{
dclear();
dprint(1, 1, "%d", freq);
dprint(1, 10, "%s", bincod);
dprint(1, 20, "%d", place);
dtext(1, 50, "F1 _ F2 -");
dupdate();
key = getkey();
switch(key)
{
case KEY_RIGHT : freq+=1; break;
case KEY_LEFT : freq-=1; break;
case KEY_UP : freq+=10; break;
case KEY_DOWN : freq-=10; break;
case KEY_F1 : *(bincod+place++) = '_'; break;
case KEY_F2 : *(bincod+place++) = '-'; break;
case KEY_DEL : place=(place>0 ? place - 1 : 0); *(bincod+place) = 0; break;
case KEY_EXE :
timer_start(TIMER_USER, freq*place, Clock_Hz, lect, 2*freq*place);
break;
case KEY_EXIT :
timer_stop(TIMER_USER);
return 1;
}
}
return 1; // this point is never reached
}