Button Press Random True or false answer

Discussion in 'The Projects Forum' started by roro36, May 3, 2011.

  1. roro36

    Thread Starter Member

    Sep 7, 2010
    52
    0
    Simple project that I could do on a microcontroller, but thought I would give this a shot to see for simpler solutions. I want to have a unit that has a push switch and 2 leds on it. One red and the other green. When the button is pressed, one of the lights should turn on. This should be random or be able to set which one is prefeered. So say 80% red and 20% green? Any simple solutions?
     
  2. KMoffett

    AAC Fanatic!

    Dec 19, 2007
    2,574
    230
    Microcontroller. ;)

    Ken
     
    roro36 likes this.
  3. roro36

    Thread Starter Member

    Sep 7, 2010
    52
    0
    Yeah, I guess that must be the best and simplest. Shot
     
  4. John P

    AAC Fanatic!

    Oct 14, 2008
    1,634
    224
    No, for once this is easy without a microcontroller. Just have a fast oscillator driving a divide-by-2 circuit (I'd use a 74HC74, but there are lots of ways to do it). Push the button, and the clock stops, and with the fast input, you'd never be able to predict which way it would end up.

    The 74HC74 has two flipflops on the chip, so you could use the other one to implement a stop/run function.
     
  5. KMoffett

    AAC Fanatic!

    Dec 19, 2007
    2,574
    230
    John P,

    How do you implement the 80-20% weighting with a 74HC74?

    Ken
     
  6. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    I believe JohnP was suggesting a traditional heads/tails generator where the divide by 2 circuit is used to ensure a fair 50:50 coin toss?

    As for the weighted coin toss, you could do it in analogue with a 555 astable, set up with a pot for duty cycle adjust (to set heads/tails ratio).

    Then gate and capture the running 555's output with a logic latch controlled by the button.
     
  7. KMoffett

    AAC Fanatic!

    Dec 19, 2007
    2,574
    230
    Interesting. I like that RB. :)

    Ken
     
  8. KJ6EAD

    Senior Member

    Apr 30, 2011
    1,425
    363
    You can use the traditional wheel of fortune circuit (pushbutton, fast (to humans) clock, decade counter, decode logic). You can also find a variation of this circuit used for electronic dice. It's just a 555 and a 4017 with 8 of the 4017 outputs going to one LED and the other 2 going to the second LED.
     
    Last edited: May 5, 2011
  9. John P

    AAC Fanatic!

    Oct 14, 2008
    1,634
    224
    My earlier message just addressed the issue of a random red/green output, with a 50/50 chance of either. If you want a variable chance, it gets more complicated.

    Yes, the 555 (or other) oscillator would do it. Then you'd want to have the input to the flipflop get "frozen" by pressing a button, as Roman said. But with an analog technique, you'd never get an exactly even chance of either red or green coming up. Would it be feasible to have two different methods with a switch to select one? Or maybe use a radio-style volume control, where the knob would "click" at one end of its travel, where you'd get the 50/50 chance.

    Or there are digital schemes where you could have a multi-position knob that would select between various probabilities of getting each output. But then it starts to look as if the processor would be easier.
     
  10. KMoffett

    AAC Fanatic!

    Dec 19, 2007
    2,574
    230
Loading...