A little Quiz game (Two players + audience) with PIC12F675


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2011
    Location
    Guadalajara, México
    Posts
    28

    Default A little Quiz game (Two players + audience) with PIC12F675

    This is a little Quiz game requested by my little son to use in his classroom, there are 4 pushbuttons, one for each player ("Red Player" and "Blue Player") and the other two ("Correct" and "Incorrect" answer) are for the teacher. You can use a RGB LED (Red player, Blue player an Green audience) or three separate LEDs.

    The interesting part of this little and silly project is the use of an analog input to check the status of two pushbuttons.

    The schematic is included in the source code you can add a 9v bat. with a 7805 regulator and an on-off switch.

    Enjoy.

    Code:
    '****************************************************************
    '*  Name    : MaraTron+12F675                                   *
    '*  Author  : Ivan Rosales, Guadalajara México                  *
    '*  Notice  : Copyright (c) 2011 Ivan Rosales                   *
    '*          : All Rights Reserved                               *
    '*  Date    : 27/08/2011                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : Quiz Game (Two Players + Audience)                *
    '*          :                                                   *
    '*
    '*
    '*             Vdd
    '*              +
    '*              |
    '*              |
    '*             .-.
    '*             | |		             PIC12F675
    '*             | |1K                    ___      Red
    '*             '-'                   -o|°  |o-   LED   Green
    '*              |            .--------o|   |o---->|-.   LED    Blue
    '*         .----o----o-------)--------o|   |o-------)--->|-.   LED
    '*         |         |       |      .-o|___|o-------)------)--->|-.
    '*       | o       | o       |      |               |      |      |
    '*     |=|>      |=|>        |      |               |      |      |
    '*       | o       | o   Red |  Blue|               |      |      |
    '* Correct |Incorrect|       |      |               |      |      |
    '*         |         |     | o    | o               |      |      |
    '*         |         |   |=|>   |=|>                |      |      |
    '*         |         |     | o    | o               |      |      |
    '*         |        .-.      |      |               |      |      |
    '*         |        | |      |      |               |      |      |
    '*         |        | |1K    |      |               |      |      |
    '*         |        '-'      |      |               |      |      |
    '*         |         |       |      |               |      |      |
    '*         |         |       |      |               |      |      |
    '*         '----o----o-------o------o---------------o------o------'
    '*              |
    '*             ===
    '*             GND
    '****************************************************************
    @ Device PIC12F675,WDT_ON,PWRT_ON,PROTECT_OFF,MCLR_OFF,BOD_OFF
    ansel=%00111000     'Use GP4/AN3 (Pin 3) as analog input
    adcon0 = %00001101
    cmcon=7             'Don't use analog comparator
    trisio=%111000      '
    option_reg=0        'Enable Pull-Ups
    wpu=$FF             'Config Pull-Ups (GP3 DOESN'T have Pull-Up)
    
    DEFINE ADC_BITS 10 
    DEFINE ADC_CLOCK 3 
    DEFINE ADC_SAMPLEUS 50 
    
    'Definitions
    Rojo         VAR GPIO.0 
    Verde        var GPIO.1
    Azul         var GPIO.2
    Bot1         var GPIO.3
    Bot2         var GPIO.5
    Todos        var bit
    Cont         var byte
    Tiempo       var byte
    SiNo         var word
    
    gpio=0    'Turn off LEDs
    todos=0
    
    Pral:
    gosub do_adc   'Get ADC reading
    
    if !bot1 and !rojo and !Azul then     'If "Red" player is the fastest
    high Rojo
    gosub do_shuffle
    endif
    
    if !bot2 and !Rojo and !azul then     'If "Blue" player is the fastest
    high Azul
    gosub do_shuffle
    endif
    
    if sino=0 then                        'If the "Answer" is correct 
    gpio=0
    todos=0
    endif                   
    
    if sino=1 and !todos and (rojo or azul)then    'If the "Answer" is incorrect (First player fails)
    toggle azul
    toggle rojo
    repeat
    gosub do_adc
    until sino=3
    todos=1
    endif
    
    if sino=1 and todos and (rojo or azul)then    'If the "Answer" is incorrect (Both players fails)
    low azul
    low rojo  
    high verde                                    'Turn On Green (It's the audience turn's)
    repeat
    gosub do_adc
    until sino=3
    todos=0
    endif
    
    if sino=1 and verde then    'If the "Answer" is incorrect (Both players and audience fails)
    gpio=0
    repeat
    gosub do_adc
    until sino=3
    todos=0
    endif
    
    goto pral
    
    Do_ADC:
    PAUSEUS 50           ' Wait for A/D channel acquisition time
    ADCON0.1 = 1         ' Start conversion
    WHILE ADCON0.1       ' Wait for it to complete
    WEND
    sino = ADRESH>>6
    return
    
    Do_Shuffle:          'Just a little dramatic effect ;)
    tiempo=50
    for cont = 1 to 32
    toggle rojo
    toggle azul
    pause tiempo
    tiempo=tiempo+5
    next cont
    return
    
    end

  2. #2
    Join Date
    Aug 2011
    Location
    Guadalajara, México
    Posts
    28


    Did you find this post helpful? Yes | No

    Default Re: A little Quiz game (Two players + audience) with PIC12F675

    Ops!, there is a 1k pullup resistor missing in the schematic, so please add this to the pin 4...

    Errare humanum est

  3. #3
    Join Date
    Apr 2003
    Location
    Cambridge - UK
    Posts
    1,030


    Did you find this post helpful? Yes | No

    Default Re: A little Quiz game (Two players + audience) with PIC12F675

    Great, your code exaple is in the User Projects section, here. Thank you for taking time to post this project. We appreciate you taking time to post this.

  4. #4
    oldisgold's Avatar
    oldisgold Guest


    Did you find this post helpful? Yes | No

    Default Re: A little Quiz game (Two players + audience) with PIC12F675

    i wud like to extend it to more players [say, 4 players]. can u help me by showing how to extend ?

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: A little Quiz game (Two players + audience) with PIC12F675

    Good stuff, like Lester said good code EXAPLE
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Apr 2003
    Location
    Cambridge - UK
    Posts
    1,030


    Did you find this post helpful? Yes | No

    Default Re: A little Quiz game (Two players + audience) with PIC12F675

    olisgold..

    Please, at least try. Ivan has made a great example, try to read it understand it, ask questions about the code flow and try modification yourself.

    Its really unreasonable to ask Ivan to do the work for you....and you learn nothing by that process.

  7. #7
    Join Date
    Aug 2011
    Location
    Guadalajara, México
    Posts
    28


    Did you find this post helpful? Yes | No

    Default Re: A little Quiz game (Two players + audience) with PIC12F675

    Dear olisgold, you can count on me if you get stuck, but I would like to see at least one try, because as lester said, it's the best way to learn.

    As a little tip, you can expand the game with diferent approaches, one could be with charlieplexed LEDs (controling them with 3 pins) and then use the 3 remaining pins for the buttons (as in the example, using them as analog inputs to read 2 buttons per pin)

    Regards.
    My English doesn't sucks, it's just fugly...

  8. #8
    Join Date
    Aug 2011
    Location
    Guadalajara, México
    Posts
    28


    Did you find this post helpful? Yes | No

    Default Re: A little Quiz game (Two players + audience) with PIC12F675

    mister_e, I think lester is referring to Steve Jobs (Ex-Apple)
    My English doesn't sucks, it's just fugly...

  9. #9
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: A little Quiz game (Two players + audience) with PIC12F675

    Rofl! Win!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts