Go Down

Topic: Quiz / Buzzer system (Arduino + Processing) (Read 7214 times) previous topic - next topic

Z

Jan 26, 2011, 06:08 am Last Edit: Jan 26, 2011, 08:32 pm by Z Reason: 1
I spend part of the summer vacation building a quiz system that I can use in the classroom (I'm a science teacher). The buzzers are basically simple buttons and the processing sketch does most of the work.



Don't know if we can embed youtube but here it is in action: http://www.youtube.com/watch?v=QXka_UJgBVc
All files are available here.


sth77

Pretty nice! I think it could be better with a led inside the translucent boxes, so if someone is pressing the button, the box flashes or glows in red, yellow, green or blue.
Mein Arduino-Blog: http://www.sth77.de/ - letzte Eintr├Ąge: Teensy 3.0 - Teensyduino unter Window 7 - Teensyduino unter Windows 8

CrossRoads

Coincidentally, I just saw a similar system at instructables.com (was poking around waiting for the forum to re-open) using Staples Easy buttons.
http://www.instructables.com/id/Quiz-O-Tron-3000-Arduino-quiz-contestant-lockout-/
That one doesn't have the PC software to display scores tho.

How do you sample when buttons are pressed? Is it possible to have 2 pressed at the same time?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Z

I was just polling the pins, so it was triggering repeatedly when a button was pressed, but today at lunch I updated it to use the Bounce library and so it will only register the button once when it is pressed.

I want to clean it up, but,
Code: [Select]
#include <Bounce.h>

const int ledPin =  13;
const int buttonA = 2;
const int buttonB = 3;
const int buttonC = 4;
const int buttonD = 5;
const int buttonY = 6;
const int buttonN = 7;

Bounce bounceA = Bounce( buttonA,5 );
Bounce bounceB = Bounce( buttonB,5 );
Bounce bounceC = Bounce( buttonC,5 );
Bounce bounceD = Bounce( buttonD,5 );
Bounce bounceY = Bounce( buttonY,5 );
Bounce bounceN = Bounce( buttonN,5 );

boolean aPressed = false;
boolean bPressed = false;
boolean cPressed = false;
boolean dPressed = false;
boolean yPressed = false;
boolean nPressed = false;



void setup() {
  pinMode(ledPin, OUTPUT);     
  pinMode(buttonA,INPUT);
  pinMode(buttonB,INPUT);
  pinMode(buttonC,INPUT);
  pinMode(buttonD,INPUT);
  pinMode(buttonY,INPUT);
  pinMode(buttonN,INPUT);
  Serial.begin(9600);
}

void loop(){
  bounceA.update ( );
  bounceB.update ( );
  bounceC.update ( );
  bounceD.update ( );
  bounceY.update ( );
  bounceN.update ( );
  digitalWrite(ledPin, LOW);


if(aPressed == false){
  if (bounceA.read() == HIGH) {
    digitalWrite(ledPin, HIGH);
    Serial.println(String("2"));
    aPressed = true;
  }
}
if(aPressed == true){
  if (bounceA.read() == LOW) {
    digitalWrite(ledPin, LOW);
    //Serial.println(String("2"));
    aPressed = false;
  }
}

if(bPressed == false){
  if (bounceB.read() == HIGH) {
    digitalWrite(ledPin, HIGH);
    Serial.println(String("3"));
    bPressed = true;
  }
}
if(bPressed == true){
  if (bounceB.read() == LOW) {
    digitalWrite(ledPin, LOW);
    bPressed = false;
  }
}

if(cPressed == false){
  if (bounceC.read() == HIGH) {
    digitalWrite(ledPin, HIGH);
    Serial.println(String("4"));
    cPressed = true;
  }
}
if(cPressed == true){
  if (bounceC.read() == LOW) {
    digitalWrite(ledPin, LOW);
    cPressed = false;
  }
}

if(dPressed == false){
  if (bounceD.read() == HIGH) {
    digitalWrite(ledPin, HIGH);
    Serial.println(String("5"));
    dPressed = true;
  }
}
if(dPressed == true){
  if (bounceD.read() == LOW) {
    digitalWrite(ledPin, LOW);
    dPressed = false;
  }
}

if(yPressed == false){
  if (bounceY.read() == HIGH) {
    digitalWrite(ledPin, HIGH);
    Serial.println(String("6"));
    yPressed = true;
  }
}
if(yPressed == true){
  if (bounceY.read() == LOW) {
    digitalWrite(ledPin, LOW);
    yPressed = false;
  }
}

if(nPressed == false){
  if (bounceN.read() == HIGH) {
    digitalWrite(ledPin, HIGH);
    Serial.println(String("7"));
    nPressed = true;
  }
}
if(nPressed == true){
  if (bounceN.read() == LOW) {
    digitalWrite(ledPin, LOW);
    nPressed = false;
  }
}

}


In regard to "Is it possible to have 2 pressed at the same time?" , do you mean, register two simultaneous presses? No, so if buzzers A and B are pressed simultaneously, A will register as the button pressed unless you do it between polling A and B. So there is a slight benefit to being A over B, but also D over A. I calculate that the buttons are being polled at least every 10ms, so I think that is sufficient resolution, at least for my purposes.

CrossRoads

My thought was that it be more fair if there no advantage of one button press over another.
I think this could be done somewhat simply by doing 4 reads in row:
void loop(){
button1_state = digitalRead(button1);
button2_state = digitalRead(button2);
button3_state = digitalRead(button3);
button4_state = digitalRead(button4);
to capture all 4 nearly identically in time
then see if where any zeroes in that one read sequence
if (button1_state == low || button2_state == low || button3_state == low || button4_state == low){
if there was a low, then figure out which it was and take the appropriate action
could probably use the bounce() code here also
if (button1_state == low){do something}
if (button2_state == low){do something}
if (button3_state == low){do something}
if (button4_state == low){do something}
then reset the buttonx_states to high again for the next round
button1_state = high;
button2_state = high;
button3_state = high;
button4_state = high;
and add a bit of delay to debounce if your switches are still bouncig
} //otherwise go back to top of void loop again.
}
thus if there was a tie both button presses could get the credit due
but then you'd have to deal with that on the PC end too. Maybe in the next revision...
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Z

#5
Jan 28, 2011, 10:35 am Last Edit: Jan 28, 2011, 10:44 am by Z Reason: 1
I'm not really sure if there is a detectable bias, I'll try and test it over the weekend when a friend comes round, I don't think i can reliably test it by myself.

If I have a problem with bias, I think I will take your idea of polling the pins up front and measure which teams buzz in in each loop, but then pick the 'winner' at random. Or, at 'random'.

edit: I just had a go at 60 simultaneous button presses of adjacent buttons and it came up as 28/32 which i think is pretty good.

Z

An update:

I had caps printed for the buttons at shapeways.

CrossRoads

Looks sharp. Do they use a mold to give it the crisp shape and build up the plastic with 3D printing kind of thing?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy