Wednesday, December 25, 2013

DIY Game: Glow All the LEDs First!


DIY Game: Glow All the LEDs First!


This is a 2 player game, based on 8051 microcontroller AT89S52. This game features two push buttons (one for each player) and an array of 8 LEDs for each. It demands high reflexes, as you have to push button as fast as you can. Each press would help the successive LED to glow until all the 8 LEDs are on.

The competition is about how fast you can toggle (Press and then un-press) the buttons, greater your speed of pressing push button, greater will be your chance of winning. As soon as any of the two players reach the last LED, the push button of another player will get deactivated, which means it will not respond to the push. Also the LEDs of the winner will start toggling. This will ensure the accurate after results. To restart the game, press the reset button (button connected to pin 9 on microcontroller).

Press the Button as Fast as You can
Press the Button Fast Game
LEDs corresponding to PLAYER 1 are connected to PORT 2 whereas for PLAYER 2, LEDs are connected to PORT 3. Push buttons are connected to pin P1.1 and P1.2 for PLAYER 1 and PLAYER 2 respectively. I have used integer variables “pressed[0] and pressed[1]”(in coding part) to ensure that microcontroller counts only those push which are done after the release of the button. This will ensure fair play.

I have also declared an array arr[], which comprises the hexadecimal values for the LEDs to glow successively. I have also created a delay function: delay_msec(), using TIMERS to provide delay (in milliseconds) wherever necessary.

Since 8051’s cannot multitask, thus to judge the 2 players individually I have written the code in such a manner that it seems to perform multitasking. This was needed to count each and every perfect push and hence result in a fair decision game.

No comments:

Post a Comment