### by Carole-Jean Wu & Yang Ching Chang

INTRODUCTION

HIGH LEVEL DESIGN

PROGRAM/HARDWARE DESIGN

RESULTS

CONCLUSION

APPENDIX A: CODE

APPENDIX B: SCHEMATICS

APPENDIX C: PARTS LISTING

REFERENCE

Carole-Jean Wu

Yang Ching Chang

Program/Hardware Design

Program Details

 In order to ensure completion of arithmetic calculation and drawing on the TV screen at the frame rate, we have to distribute tasks to different lines as follows: At LineCount == 225 , the keyboard mania checks whether or not users enter request from the HyperTerminal on the PC. If a user selects a valid piano score, the keyboard mania will display the chosen score on the TV screen. If the user enters ‘y’ to start, the keyboard mania enters the PLAYING state as described on the state transition diagram on the left. When the user finishes playing the chosen piano score, the keyboard mania will print an evaluation page to inform the user his/her level of piano skill, his/her score, and the highest score so far. At LineCount == 227 , the keyboard mania performs arithmetic calculations for note_x = score_x; note_y = score_y - ((score_stored[score_choice][display_score_index])<< 1) ; display_score_index++; display_duration = score_stored[score_choice][display_score_index]; score_x += ((display_duration<<2)+(display_duration<<1)); display_score_index++; where information about a music note’s position and its duration is stored in the pre-coded piano score, score_stored[score_choice][display_score_index]. score_x and score_y is the base position of each music note; note_x and note_y, indicating the position of a music note, are offsets. Then score_x and score_y are updated to calculate where to draw the next music note and its duration. At the same time, the keyboard mania increments pacer_x by 6 and update pacer_y , which indicate the position of the pacer; then it checks whether or not the user has played the right key. keystrike = r_buffer[strike_index]; notetable_index = score_stored[score_choice][score_index]; if ( keystrike == notetable[notetable_index] ) correct_strike = 1; else correct_strike = 0; Last but not the least; the keyboard mania has to calculate the position of the correctness mark whose position is always above the corresponding music note. check_x = pacer_x; check_y = pacer_y-30; At LineCount == 229 , the keyboard mania generate sounds corresponding to computer keys pressed by the user and outputs through the TV. if (soundarray_index>= 0 && soundarray_index <= 8) OCR0 = soundarray[soundarray_index]; where soundarray stores frequencies of music notes. We also implement few additional functions which help the keyboard mania display the piano score on the TV screen as follows. //=============================== void video_hline( char y ) //The function is optimized to plot a horizontal line //starting at y with color white   //=============================== void video_putnote( char x, char y, char c) //draw a note on the screen //c=0: space, c=1: eighth note, c=2: quarter note, //c=3: dotted quarter note, c=4: half note, //c=5: sixteenth note, c=6: dotted half note, //c=7: rest, c=8: whole note //x and y indicate the treble clef's position   //=============================== void video_puthigh( char x, char y, char c) //draw treble clef on the screen //c=0: right portion of treble clef, //c=1: left portion of treble clef //x and y indicate the treble clef's position   //=============================== void video_putsymbol( char x, char y, char c) //draw a symbol on the screen with index c //c=0: pacer, c=1: check mark, c=2: cross mark //x and y indicate the symbol's position At LineCount == 231 , the keyboard mania erases one line on the music piano which has been completed by the user and displays the next line on the TV screen. At the same time, the keyboard mania has to display the correctness mark above each music note, video_putsymbol(check_x, check_y,1) for check mark , video_putsymbol(check_x, check_y,2) for cross mark, and the pacer below each music note, video_putsymbol(pacer_x, pacer_y, 0) . If the user finishes playing the chosen piano score, the keyboard mania clears the TV screen and display an evaluation report, where the user receives a comment on his/her piano skill, his/her score, and the highest score for the chosen piece on the record. In order to ensure the keyboard mania completes drawing the evaluation page, we implement a state machine to separate drawing of treble clef, five horizontal lines, the evaluation message, the user’s score, the highest score on the record, and decoration music notes in different states. The user receives excellent when scoring more than 90%, good when scoring more than 70%, pass when scoring more than 50%, and fail when scoring below 50%. [Figure 5-8] After distributing tasks to different states, there is no visual artifact on the TV screen.

 Figure 1. Circuit layout on the breadboard Figure 2. A image snapshot of the user menu on HyperTerminal Figure 3. Welcome page of our keyboard mania Figure 4. Playing the chosen piano score Figure 5. Evaluation page for excellent performance (score higher than 90%) Figure 6. Evaluation page for good performance (score higher than 70%) Figure 7. Evaluation page for pass performance (score higher than 50%) Figure 8. Evaluation page for fail performance (score below 50%) Figure 9. Breadboard name tag Figure 10. Complete our keyboard mania design!!

Hardware Details

The hardware implementation of our keyboard mania is straight forward. Pin 0 and 1 of PORTD on the STK500 development board are connected RXD and TXD to communicate with the HyperTerminal on the PC; Pin 5 and 6 of PORTD are used to convert digital to analog signals output through the TV. Pin 3 of PORTB on the STK500 development board is the keyboard mania’s audio output which is connected to a low-pass filter with R = 10KΩ and C = 22nF, whose cutoff frequency is around 700 Hz, and then the TV. The circuit layout on the breadboard can be found below.

Things We Tried Did Not Work

One difficulty which we encountered was how to incorporate more than one interrupt-based I/O devices to our keyboard mania. However, we managed to overcome this problem using semaphores, counters, and distribute arithmetic calculation and drawing to different lines. [Program Details] Other design specifications are relatively easy to accomplish, so we did not have to drop any design for our keyboard mania.