PC Based Quiz Buzzer (Part 3)

By Harsha and Veena

<< Read previous part: PC Based Quiz buzzer: Project tutorial

Following function will be called when a keyboard key is pressed. Closes the program on press of 'esc' key, passes the option to the next priority team on enter and clears the screen on F5. The example source given to download( click here to download the source code ) contains an option to demonstrate the program using keyboard without connection the switches. That part is omitted here.

 ```void kbpress(int key) { int i; if(key==27) //ascci of esc { closegraph();restorecrtmode(); exit(0); } if(key==63) //F5: reset { j=0; setrgbpalette(4,20,20,0); flag[1]=0; ready(7); for(i=0;i<=5;i++) { qqqq(7,i); flag[i+2]=0; } } if(key==13 && j>0) { order[j]=7; j--; for(i=0;i<=j;i++) { order[i]=order[i+1]; if(i==0) ready(order[0]); else qqqq(order[i+1],i-1); } if( j== 0) { setrgbpalette(4,20,20,0); ready(7); for(i=1;i<=7;i++) { flag[i]=0; } } } }```

Before going to the next part of the code, have a look at the screen shot of out put screen. Thinking that team numbers 2, 1, 5, 3, 4 pressed the buzzer in order, now team 2 has to answer the question. Big number tells which team to answer, other numbers in the column right hand side are the next teams to answer in top to bottom order. Now, if you press enter, team 1 will come to center block.

 ```void showteam(int tn) { order[j]=tn; if(j==0) { sound(900); ready(order[j]); setrgbpalette(4,0,1,60); printf("\a");nosound(); } else if(j<7) que(order[j],j-1); flag[tn]=1; j++; } /************************************************************/ void setscreen(void) { int i; setcolor(4); rectangle(0,0,mx,my); setcolor(14); setfillstyle(1,8); bar(115,75,365,my-25); rectangle(99,49,351,my-49); setviewport(100,50,350,my-50,1); clearviewport(); setviewport(0,0,mx,my,1); setcolor(7); line(mx-200,0,mx-200,my); line(mx-100,0,mx-100,my); setcolor(4); /* line(mx-212,0,mx-212,my); line(mx-88,0,mx-88,my);*/ setfillstyle(1,4); bar(mx-210,0,mx-202,my); bar(mx-90,0,mx-98,my); setfillstyle(1,7); for(i=0;i<=50;i++) { bar(mx-208,i*10-5,mx-204,i*10); bar(mx-92,i*10-5,mx-96,i*10); } settextjustify(1,1); settextstyle(10,0,3); setcolor(14); outtextxy(220,20,"ElectroSofts Quiz Buzzer"); outtextxy(220,40," By www.ElectroSofts.com"); setrgbpalette(1,0,61,0); setrgbpalette(2,5,50,5); setrgbpalette(3,1,40,2); setrgbpalette(4,0,1,60); setrgbpalette(5,60,0,0); } /***********************************************************/ void ready(int no) { int i; setviewport(100,50,350,my-50,1); for(i=0;i<=8;i++) { setcolor(team[no][0]*(i+3)/3); line(50+i,55+i,50+i,180-i); line(50-i,55+i,50-i,180-i); } for(i=0;i<=8;i++) { setcolor(team[no][1]*(i+3)/3); line(50+i,190+i,50+i,320-i); line(50-i,190+i,50-i,320-i); } for(i=0;i<=8;i++) { setcolor(team[no][2]*(i+3)/3); line(55+i,50+i,200-i,50+i); line(55+i,50-i,200-i,50-i); } for(i=0;i<=8;i++) { setcolor( team[no][3]*(i+3)/3); line(55+i,185-i,200-i,185-i); line(55+i,185+i,200-i,185+i); } for(i=0;i<=8;i++) { setcolor(team[no][4]*(i+3)/3); line(55+i,325-i,200-i,325-i); line(55+i,325+i,200-i,325+i); } for(i=0;i<=8;i++) { setcolor(team[no][5]*(i+3)/3); line(205-i,55+i,205-i,180-i); line(205+i,55+i,205+i,180-i); } for(i=0;i<=8;i++) { setcolor(team[no][6]*(i+3)/3); line(205-i,190+i,205-i,320-i); line(205+i,190+i,205+i,320-i); } } /********************************************************/ void que(int no, int pos) { int i; setviewport( mx-190,pos*100,mx-50,my,1); for(i=0;i<=3;i++) { setcolor(team[no][0]*5); line(14+i,6+i,14+i,39-i); line(14-i,6+i,14-i,39-i); } for(i=0;i<=3;i++) { setcolor(team[no][1]*5); line(14+i,41+i,14+i,74-i); line(14-i,41+i,14-i,74-i); } for(i=0;i<=3;i++) { setcolor(team[no][2]*5); line(15+i,5+i,70-i,5+i); line(15+i,5-i,70-i,5-i); } for(i=0;i<=3;i++) { setcolor( team[no][3]*5); line(15+i,40-i,70-i,40-i); line(15+i,40+i,70-i,40+i); } for(i=0;i<=3;i++) { setcolor(team[no][4]*5); line(15+i,75-i,70-i,75-i); line(15+i,75+i,70-i,75+i); } for(i=0;i<=3;i++) { setcolor(team[no][5]*5); line(71-i,6+i,71-i,39-i); line(71+i,6+i,71+i,39-i); } for(i=0;i<=3;i++) { setcolor(team[no][6]*5); line(71-i,41+i,71-i,74-i); line(71+i,41+i,71+i,74-i); } }```