//********************************************************************** // // Program to run the K8055 from Windows using Borland BCC55 // and Toshiba numeric USB keyboard // ------- // //slidec // // Available for use under the open source license of the Milwaukee // Servo Electric Guitar Project www.servoelectricguitar.com. All other // rights reserved // //********************************************************************** #include #include #include #include #include #include #include #include "K8055D.h" //#include //********************************************************** //***global variables //********************************************************** //general variables int stringtuning[3][13]; clock_t now, later;//time variable for delaying delta-time //profiler variables clock_t starttime; //****************************************************** //***function prototypes //****************************************************** char chordmode(void); //chord mode plays chords //char normalmode(int); //normal mode plays note by striking keys char tunemode(int); //tune mode tunes the strings char playmode(void); //plays a midi file void waitabit(void); //delay to create sample and hold pulse void wait(float seconds); //a waiting function void profile(); void initializetuning(); void savetuning(); void loadtuning(); //***************************************************** //**** delay timer //***************************************************** void wait(float seconds)//wait integer number of seconds { //printf("the seconds at wait function is %f\n",seconds); //printf("clocks per tick is %d\n",CLOCKS_PER_SEC); clock_t endwait; endwait = clock() + seconds * CLOCKS_PER_SEC; //printf("endwait is %d\n\n",endwait); while (clock()='.' && inputkey<='9')) { switch (inputkey) { case '0': noteindex=0; break; case '.': noteindex=1; break; case '1': noteindex=2; break; case '2': noteindex=3; break; case '3': noteindex=4; break; case '4': noteindex=5; break; case '5': noteindex=6; break; case '6': noteindex=7; break; case '7': noteindex=8; break; case '8': noteindex=9; break; case '9': noteindex=10; break; case '/': noteindex=11; break; case '*': noteindex=12; break; default: noteindex=5; } }// play a note gotoxy(1,3); //persistantinputkey=inputkey; printf("pressed key = %c\n",inputkey); printf("noteindex = %d \n",noteindex); notenumber = stringtuning[wire-1][noteindex]; OutputAnalogChannel(1,notenumber); ClearDigitalChannel(wire); waitabit(); SetDigitalChannel(wire); gotoxy(1,5); printf("D/A out = %d \n",notenumber); //tune last note up if (inputkey=='+') { if (stringtuning[wire-1][noteindex]<255) { ++stringtuning[wire-1][noteindex]; } notenumber = stringtuning[wire-1][noteindex]; OutputAnalogChannel(1,notenumber); ClearDigitalChannel(wire); waitabit(); SetDigitalChannel(wire); gotoxy(1,5); printf("D/A out = %d \n",notenumber); }//end of tune up //tune last note down if (inputkey=='-') { if (stringtuning[wire-1][noteindex]>0) { --stringtuning[wire-1][noteindex]; } notenumber = stringtuning[wire-1][noteindex]; OutputAnalogChannel(1,notenumber); ClearDigitalChannel(wire); waitabit(); SetDigitalChannel(wire); gotoxy(1,5); printf("D/A out = %d \n",notenumber); }//end of tune down }//no mode change }//while return(inputkey); } //end of tuning mode //********************************************* //*** wait for a short while for the A/D converter //********************************************* void waitabit (void) { now=clock(); later=now+(50);//was 75 very close to 50 milliseconds while(now