/////////// Lira Nikolovska, MIT Dept of Architecture, Design and Computation /////////// Independent study with Prof Chris Csikszentmihályi, MIT Media Lab Culture of Computing Group /////////// Spring 2003 /////////// lira@mit.edu #include <18f452.h> #include #fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,BORV45 //#use delay(clock=40000000) #use delay(clock=13333333) #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) #USE STANDARD_IO (A) #USE STANDARD_IO (B) #USE STANDARD_IO (C) #USE STANDARD_IO (D) #USE STANDARD_IO (E) #define NUMLEDS 12 // total number of LEDs is to be 12, for testing was is set to 4 #define TIMEONINMS 200 // time ON for the LEDs is 200 miliseconds #define NOISE_LEVEL_LEFT 3 #define NOISE_LEVEL_RIGHT 3 #define INSENSITIVE_INTERVAL 3 // cannot be larger than NUMLEDS; #define QUANTIZATION_LEVEL 16 /////////////////////////////////////////////// // global variables int myLeftMikeLEDs[NUMLEDS]; // array for the left mike int myRightMikeLEDs[NUMLEDS]; // array for the right mike int myLEDs[NUMLEDS]; // array that is sum of myLeftMikeLEDs+myRightMikeLEDs int myTempArray[NUMLEDS]; /////////////////////////////////////////////// // functions // void all_out() // turns 12 pins off / sets to output_low; // void cycle_forward (void) // light animation 1 // void cycle_backward (void) // light animation 2 // void initializeArrays (int myarrayPtr[], int initValue) // myarray[] is pointer to an array of ints // void printArray(int printArrayPtr[]) // function that prints an array // void shiftRight(int shiftPtr[]) // function that shifts array cell values to the RIGHT // void shiftLeft(int shiftPtrLeft[]) // function that shifts array cell values to the LEFT // int* addArraysBitwise(int onePtr[], int twoPtr[]) // function that ADDS arrays, returns pointer to an array // void setCorrespondingBits(int *myfinalarray, int value) // function that turns appropriate pins on and off // void main() /////////////////////////// intialize arrays function void initializeArrays (int myarrayPtr[], int initValue) // myarray[] is pointer to array of ints { //variable declarations int i; //counter //variable initialization for (i=0; i0; i--) { shiftPtr[i]=shiftPtr[i-1]; //printf("shift RIGHT index is: %u value is: %u\n\r", i, shiftPtr[i]); } shiftPtr[0]=0; } //////////////////// function that shifts cell values to the LEFT void shiftLeft(int shiftPtrLeft[]) { int i; for(i=0; i NOISE_LEVEL_LEFT ) leftMicOn=1; // end of check left mic // now check right mic set_adc_channel(1); //printf("set_adc channel A1 \n\r"); delay_us(10); mikeADC_right = read_adc(); //printf("mikeADC_right AD value = %2u\n\r", mikeADC_right); quantizedOutput_right = (int)((float)mikeADC_right/QUANTIZATION_LEVEL); // cast quantizedOutput to an integer value //printf("quantizedOutput_right is %2u\n\r", quantizedOutput_right); strcpy(mikeStringOutput_right, ""); for (j=0; j NOISE_LEVEL_RIGHT) rightMicOn=1; // end of check right mic // set first bit of array if "good" mic input if(leftMicOn) { count_interval_left++; // increment counter if(count_interval_left > INSENSITIVE_INTERVAL) { myLeftMikeLEDs[0]=1; // turn on the first LED in the array count_interval_left=0; // start the counter } } if(rightMicOn) { count_interval_right++; if(count_interval_right > INSENSITIVE_INTERVAL) { myRightMikeLEDs[NUMLEDS-1]=1; // turn on the last LED in the array count_interval_right=0; // start the counter } } /////////// now light on LEDs ////////////////// myPTR = addArraysBitwise(myLeftMikeLEDs, myRightMikeLEDs); // 2 arrays added //printf("RESULT array: \n\r"); //printArray(myPTR); setCorrespondingBits(myPTR, 1); // output_high //printf("i am at setCorrespondingBits 1 \n\r"); /////////////// pause so that LEDs stay on ////////////////// if(leftMicOn==1 || rightMicOn==1) delay_ms(TIMEONINMS); else delay_ms(10); // wait only a little time if both mics are off // so that it is ready to pick up a signal //////////////////// end pause /////////////////////////////// setCorrespondingBits(myPTR, 0); // output_low //printf("i am at setCorrespondingBits 0 \n\r"); //////////////////////// clean up ////////////////////// // shift array shiftRight(myLeftMikeLEDs); // printf("myLeftMikeLEDs SHIFTED RIGHT: \n\r"); // printArray(myLeftMikeLEDs); shiftLeft(myRightMikeLEDs); // printf("myRightMikeLEDs SHIFTED LEFT: \n\r"); // printArray(myRightMikeLEDs); /////////////////////////// // cleaning up flag values before the next loop //4. flag and counters management at the end of the loop leftMicOn = 0; rightMicOn = 0; } //end of while loop } // end of main