NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Sensors, Actuators, and Robotics » Game Show Style Buzzer

February 10, 2010
by sjpizzle
sjpizzle's Avatar

Hi I am in a college class, where we have to do a game show style quiz. I want to be able to give each group a button and whoever pushes it first would have a respective led light up to alert me who buzzed in first. I am thinking of just using 6 leds and 6 buttons, but am not sure how to program it. If/else statements should do it, but I can't seem to be able to figure out how to take input from the buttons and then display output with an led. It sounded easier than it is. I tried using some of the dip arithmetic code to get started but it didn't seem to work right. The led lights up randomly and is not bright at all.

Here is the code I have (just the revelant part):

// Set the 6 pins to input mode - Two 3 bit numbers  
  DDRC &= ~(1<<PC0); // set PC0 as input
// turn on the internal resistors for the pins
  PORTC |= (1<<PC0); // turn on internal pull up resistor for PC0
// declare the variables to represent each bit, of our two 3 bit numbers
  uint8_t a1;
while(1) {
  // (PINC & (1<<PC0)) returns 8 bit number, 0's except position PC0     which is
  // the bit we want
  // shift it back by PC0 to put the bit we want in the 0th position.
  a1 = (PINC & (1<<PC0)) >> PC0;
if (a1 = 0)
        {
    DDRC |= (1<<PC4);
    PORTC |= (1<<PC4);
    }
    else
    {
    PORTC &= ~(1<<PC4);
    }
February 10, 2010
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hi sjpizzle,

I think you are on the right track, but the one big piece you might be missing is that once a button is hit, your program should "stop" -- that is, it should stop looking for other button presses!

There are two ways you could do this:

  • you could use a timer of some sort, where maybe it holds that one LED on for 5 seconds (long enough to be seen unambiguously, and short enough to reset in time for the next question)
  • you could have a 7th button be a button that you have to hit to reset it back to wait again.

Does that make sense?

Mike

Post a Reply

Please log in to post a reply.

Did you know that you can use a transistor to interface between different voltage levels of digital logic? Learn more...