Electronic roulette with PIC microcontroller


+ Reply to Thread
Results 1 to 14 of 14
  1. #1
    Junior Member Broderic's Avatar
    Join Date
    Jan 2019
    Posts
    2
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    76.52 MB

    0 Not allowed!

    Default Electronic roulette with PIC microcontroller

    Hello.Does anyone know where I can find an example code (or an algorithm) to run an electronic controlled roulette (with 37 LED for example) with a PIC micro?Thank youBroderic

Attention

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

The advertisements we display are relevant to this web site and your browsing history

Please consider supporting us by disabling your ad blocker.


Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues


Thank you for your attention.

  • #2
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,419
    Thumbs Up
    Received: 295
    Given: 141
    Total Downloaded
    1.68 GB

    0 Not allowed!

    Default Re: Electronic roulette with PIC microcontroller

    Personally, I think the most economic and simplest way to produce a roulette with that many LEDs is to use a string of WS2812B RGB LEDs in a circle and create a true random number. Both of these are on the forum:

    WS2812B RGB LED controller library

    A true random number generator

    Then it is a simple matter of creating the code between the libraries, which will be a simple task. i.e. Press a button, get a random value, start the LEDs spinning, then stop the spinning when a random time ends. The LED that is illuminated is the number that has won. The winning LED has already been chosen with the first random value, but the random time LED spinning adds a bit of reality to it. It could also slow down the rate of spinning as the time progresses.

    With the WS2812B chips, only a couple of pins are required for a "lot" of LEDs, so it can be accomplished on any device that operates fast enough for the timings required by the WS2812B chips.
    Last edited by top204; 3rd August 2019 at 14:17.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #3
    Junior Member Dave Purola's Avatar
    Join Date
    Jul 2004
    Posts
    68
    Thumbs Up
    Received: 5
    Given: 0
    Total Downloaded
    223.72 MB

    0 Not allowed!

    Default Re: Electronic roulette with PIC microcontroller

    Actually I would use APA102C's as they are SPI driven so that eliminates the speed restrictions on the data output routine and the processor.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #4
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,419
    Thumbs Up
    Received: 295
    Given: 141
    Total Downloaded
    1.68 GB

    0 Not allowed!

    Default Re: Electronic roulette with PIC microcontroller

    I agree the APA102 chips are a lot better to control, and a lot easier and faster to operate because they are SPI. But, at this moment in time, they are also a lot more expensive than WS2812B chips.

    I got a small string of APA102 chips and they are a pleasure to use. :-) They are fast and responsive and their operating PWM frequency does not interfere with audio because they use about 19KHz. Also, most are RGBW which is excellent. i.e. Red, Green, Blue and White.
    Last edited by top204; 3rd August 2019 at 18:28.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #5
    Junior Member Broderic's Avatar
    Join Date
    Jan 2019
    Posts
    2
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    76.52 MB

    0 Not allowed!

    Default Re: Electronic roulette with PIC microcontroller

    Thank you very much for your kind answers, top204 and Dave.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #6
    Senior Member Stephen Moss's Avatar
    Join Date
    Jan 2006
    Posts
    510
    Thumbs Up
    Received: 31
    Given: 7
    Total Downloaded
    3.72 GB

    0 Not allowed!

    Default Re: Electronic roulette with PIC microcontroller

    Quote Originally Posted by top204 View Post

    Then it is a simple matter of creating the code between the libraries, which will be a simple task. i.e. Press a button, get a random value, start the LEDs spinning, then stop the spinning when a random time ends. The LED that is illuminated is the number that has won. The winning LED has already been chosen with the first random value, but the random time LED spinning adds a bit of reality to it. It could also slow down the rate of spinning as the time progresses.
    Would that produce a realistic roulette effect though? Sounds like it illuminates and number of LED's in sequence and would then just randomly jump to the winning led.

    I wrote this as a demo to show work experience kids with a view to getting them to try programming it. It only has 16 LED's but should be easily expended, the count up/down and toggling of PortC.3 & 4 was due to the PCB design splitting the led's into left & right banks and ease of wiring so that may need changing depending on your design.
    If you want a bit more randomisation in the spin you can do that but you don't want anything too long (people get bored) or too short. Here is the code I wrote, you should note there is a slight issue with the bank switch over though, IIRC when the winning number is the first in the bank it is not illuminated/flashed for some reason but apart from that is works fine and may give you some ideas.
    Code:
    Device=16F73
    Xtal=4
    
    TRISA=$FF   'Set PortA as Input
    TRISB=$00   'Set PortB as Output
    TRISC=$00   'Set PortC as Output
    
    All_Digital = True
    
    Dim Blink As Byte   'Variable for Flashing the winning number
    Dim Number As Word  'Variable holding the value of "ball" location
    Dim Value As Word  'Variable holding the Time delay between showing next "Ball" location
    Dim Buttons As Byte 'Variable Holding Button Status
    Dim UpDown As Byte  'Variable Indication Count Direction (Up or Down)
    Dim Rollit As Byte
    
    Number = 128  'Initial Number for "Ball"
    UpDown = 0  'Intial State of Count direction (0 = Down, 1= Up)
    Value = 100 'Initial Time interval between updating Ball position in mS (0.5s)
    PORTC = 0 : PORTC.3 = 1   'Intital State of Left/Right control pin
    
    PORTB = Number  'Display "Ball" at initial position
    DelayMS 500 'Display initial "Ball" position for 0.5s 
    
    Start:  'Silent "Ball" spin and test for Start Button press 
    Buttons = PORTA                 'Test Start Button
    If PORTA.4 = 0 Then GoTo Spin   'Start Button pressed
    If UpDown = 0 Then GoSub Count_Down : Else : GoSub Count_Up
    PORTB = Number                  'Display new "Ball" location
    DelayMS Value                   'Delay between updating "Ball" position (0.1S)
    GoTo Start
    
    
    Spin:
    Rollit = 0
    Repeat
    If UpDown = 0 Then GoSub Count_Down : Else : GoSub Count_Up
    PORTB = Number   'Display new "Ball" location
    Sound PORTC.5, [10,1]
    DelayMS Value   'Delay between updating "Ball" position (0.5S)
    Inc Rollit
    Until Rollit = 64
    
    Slow:   'Slow ball down to winning value
    If UpDown = 0 Then GoSub Count_Down : Else : GoSub Count_Up
    Value = Value + 10      'Increase time between updating "Ball" position (Slow "Ball" position update down)
    PORTB=Number            'Display "Ball" location
    Sound PORTC.5, [10,1]   'Make "Ball" sound for 10mS
    DelayMS Value           'Delay between updating "Ball" position
    If Value = 600 Then GoTo Win  'Stop the "Ball" at the winning position (1.0s) 7D0=2.0s
    GoTo Slow
    
    
    Win:    'Flash Wining Number 5 Times
    For Blink=1 To 5
    PORTB=$00
    DelayMS 1000
    PORTB=Number
    Sound PORTC.5, [1,50]   'Make sound for 0.5s
    DelayMS 500
    Next Blink
    DelayMS 5000            'Display winning number for 5 Seconds
    Value = 100             'Reset "Ball" position interval to 0.5s
    GoTo Start
    
    '#
    '#----- Subroutines -----
    '#
    Count_Down:
    If Number = 1 Then Toggle PORTC.3 : Toggle PORTC.4 : UpDown = 1 'Switch between Left and Right hand numbers
    If Number > 1 Then Number = Number / 2 'Update "Ball" location
    Return
    
    Count_Up:
    
    If Number = 256 Then Toggle PORTC.3 : Toggle PORTC.4 : UpDown = 0  'Switch between Left and Right hand numbers
    If Number < 256 Then Number = Number * 2 'Update "Ball" location
    Return

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #7
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,231
    Thumbs Up
    Received: 75
    Given: 181
    Total Downloaded
    5.15 GB

    0 Not allowed!

    Default Re: Electronic roulette with PIC microcontroller

    You absolutely have to throw in some sound effects, one of those super cheap mp3 modules.
    George.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #8
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,419
    Thumbs Up
    Received: 295
    Given: 141
    Total Downloaded
    1.68 GB

    0 Not allowed!

    Default Re: Electronic roulette with PIC microcontroller

    With the WS2812B chips, and the other RGB addressable chips, a single LED can be illuminated and all the rest extinguished. Then move the illuminated LED around the strip which is made into a a circle and slow down the spin rate when the timing is coming to an end. That will simulate the spinning wheel. The spin duration could be determing by adding a value to a random value based upon how long the user pressed the button before releasing it. This type of method could also be used with pseudo random values because the seed is based upon the button pressed duration, which is never the same.

    With a bit of extra programming, a few LEDs behind the fully illuminated one can dim so it simulates a spin even more. Remember, they are RGB LEDs so they can be many colours and brightness'

    That's a good idea Towlerg, but MP3 will probably not be required. A simple flash memory holding 8-bit sampled sounds could easily be used, then output via the PWM acting as a DAC. Although the MP3 PCBs are extremely inexpensive,as long as one is bought that has control of the files contained on the SD card. Not all of them have this feaure brought to the outside world.
    Last edited by top204; 5th August 2019 at 12:22.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #9
    Junior Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    90
    Thumbs Up
    Received: 3
    Given: 3
    Total Downloaded
    308.02 MB

    0 Not allowed!

    Default Re: Electronic roulette with PIC microcontroller

    I tried to elaborate the WS2812 with a 12F1822, with good results. But that excludes the Les library, because it's too slow

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #10
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,419
    Thumbs Up
    Received: 295
    Given: 141
    Total Downloaded
    1.68 GB

    0 Not allowed!

    Default Re: Electronic roulette with PIC microcontroller

    I'd be interested in seeing your timing code. For a device operating at 32MHz or over, no problems are encountered, but with slower devices, the timings are a bit too tight.

    I was looking into using a CCP peripheral for the timings and using PWM at the frequency required for a bit change, then alter the duty inside the timing for the 1 or 0, but with fast devies being plentiful, a software approach means it can be used on any device that has enough speed.

    Because Microchip have altered the way fundamental peripherals operate for virtually every family of the same architecture, using peripherals for libraries is something I try to avoid when possible, otherwise, multiple libraries are needed for different devices, or the code needs to be full of $if or $ifdef directives, which makes simple software look dreadful and over complex. Just look at some C code for PIC devices! :-( Ohhhhh...... The stupidity of Microchip has never ceased to astound me over the years.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #11
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,351
    Thumbs Up
    Received: 43
    Given: 39
    Total Downloaded
    3.36 GB

    1 Not allowed!

    Default Re: Electronic roulette with PIC microcontroller

    I used Les's code for a project with WS2182 and it worked beautifully. I can't see how speed could be a problem with the higher clock speeds now available.

    Charlie

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #12
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,419
    Thumbs Up
    Received: 295
    Given: 141
    Total Downloaded
    1.68 GB

    0 Not allowed!

    Default Re: Electronic roulette with PIC microcontroller

    Thanks Charlie.

    They are incredible to watch flashing around at different colours and patterns all from a single pin. :-) Their timings are a bit tight and the WS2812 has slightly different timings to the WS2812B, so if anyone gets a string of LEDs that doesn't quite work, make sure they are WS2812B types, otherwise, alter the DelayCs timings in the library code to match.

    My friend Richard came around one night and saw the WS2812B 60 LED ribbon making patterns and colours from my code, so he bought a string of them and I gave him an Amicus18 board to play with them, even though he is not a electronics or programmng person per-se. :-)

    The APA102 devices are really nice, and fast with their SPI interface! I've created a library for them and I'll upload it once I've gone through the code and made it more tidy. It's just a shame they are more expensive.
    Last edited by top204; 7th August 2019 at 10:54.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #13
    Member Oldhack's Avatar
    Join Date
    Aug 2010
    Posts
    169
    Thumbs Up
    Received: 6
    Given: 0
    Total Downloaded
    1.38 GB

    0 Not allowed!

    Default Re: Electronic roulette with PIC microcontroller

    Hello
    I am waiting for a true serial LED light strip, they would have to be single color or seperate RGB with seperate data lines and single clock.
    I have used both types of displays and a true serial display would open up a world of easy flowing word projects.

    Many Thanks
    Gary

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #14
    Junior Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    90
    Thumbs Up
    Received: 3
    Given: 3
    Total Downloaded
    308.02 MB

    0 Not allowed!

    Default Re: Electronic roulette with PIC microcontroller

    Quote Originally Posted by top204 View Post
    I'd be interested in seeing your timing code.
    I don't wish to hi-jack this discussion, you may follow up this one.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

       

    Similar Threads

    1. Suggestions for pic microcontroller
      By amod in forum Absolute Beginners Section
      Replies: 10
      Last Post: 15th January 2019, 22:07
    2. Don't know How to do this -Programming PIC Microcontroller in C
      By Maryli in forum Analog-to-Digital Converter Module
      Replies: 2
      Last Post: 24th November 2016, 13:56
    3. New Smallest and Lowest-Cost PIC Microcontroller
      By normnet in forum The Lounge
      Replies: 8
      Last Post: 28th March 2013, 20:27
    4. [SOLVED !] End of the microcontroller wars pic v avr?
      By pmcleod in forum The Lounge
      Replies: 3
      Last Post: 10th December 2008, 12:08
    5. PIC Microcontroller
      By pawanonline in forum Proton Plus Compiler v3
      Replies: 11
      Last Post: 5th January 2007, 02:26

    Posting Permissions

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