Loading...
Pages: [1]   Go Down
Author Topic: Quiz / Buzzer system (Arduino + Processing)  (Read 3767 times)
0 Members and 1 Guest are viewing this topic.
Z
Australia
Offline Offline
Newbie
*
Karma: 2
Posts: 15
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
All files are available here.

« Last Edit: January 26, 2011, 02:32:49 pm by Z » Logged

Germany
Offline Offline
Edison Member
*
Karma: 33
Posts: 1801
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Mein Arduino-Blog: http://www.sth77.de/ - neues Design, neues Projekt, neuer Eintrag

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 249
Posts: 16560
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

Z
Australia
Offline Offline
Newbie
*
Karma: 2
Posts: 15
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 249
Posts: 16560
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

Z
Australia
Offline Offline
Newbie
*
Karma: 2
Posts: 15
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: January 28, 2011, 04:44:24 am by Z » Logged

Z
Australia
Offline Offline
Newbie
*
Karma: 2
Posts: 15
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

An update:

I had caps printed for the buttons at shapeways.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 249
Posts: 16560
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Looks sharp. Do they use a mold to give it the crisp shape and build up the plastic with 3D printing kind of thing?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

Pages: [1]   Go Up
Print
 
Jump to: