Shop OBEX P1 Docs P2 Docs Learn Events
LED Random Generator HELP! — Parallax Forums

LED Random Generator HELP!

SpragmaticSpragmatic Posts: 59
edited 2008-12-14 16:49 in General Discussion
Pertaining to my last post.....

· I'm having·problems understanding how to use·the random generator function in the SX/B code.· I've looked through all the forums and the·help index in SX/B and still am not understanding how it actually works.· I'm trying at this point just to get 4 led's to randomly flash on and off.· I would then like to add PWM to the code to get them to fade in and out randomly, but I will take one step at a time.··I'm just not getting it.· Any help would be greatly appreciated.· Thanks!!· ·

Comments

  • JonnyMacJonnyMac Posts: 9,214
    edited 2008-12-14 04:35
    It's really bad form to start two threads on the same topic. Enough said.

    If you explained your requirements in better detail, those of us with a bit more experience could help you out. At the moment your requirements are so vague that anyone wanting to help with code could end up spending a lot of time spinning in circles -- and nobody has time to spin....
  • SpragmaticSpragmatic Posts: 59
    edited 2008-12-14 05:46
    Sorry about that.

    The project I'm working on is a set of eyes in a wooden owl that I'm building for my mother in-law for X-Mas. Each eye has (4) individual colored led's to light them up. Yellow, Orange, Green and Red. (I will be wiring the same color led for each eye in series so they come on at the same time) I will have a total of (4) toggle switches in the circuit. (3) to change to each color besides Yellow and (1) to put it in a random flash mode. So this being said, here's how I would like the program to work.

    1. Turn circuit to ON and the Yellow led's come on.
    2. Switch #1 turns off Yellow, turning on Orange.
    3. Switch #2 turns off Yellow, turning on Green.
    4. Switch #3 turns off Yellow, turning on Red.
    5. Switch #4 turns all led's into a random flash mode with led's fading in and out with PWM.
    6. Some way to keep eyes Yellow if (2) or more of the switches are turned on at the same time.

    That should do it. I am fairly new to this stuff, but I do understand adding the switches as inputs with pull-up resistors. I also have wrote a couple of simple PWM programs for another project, but I'm not sure on the random generator and adding all these together in one program. Hope this helps! Thanks JonnyMac!!
  • BeanBean Posts: 8,129
    edited 2008-12-14 13:48
    ·
    DEVICE SX28, OSC4MHZ, TURBO, OPTIONX, STACKX
    FREQ 4_000_000
     
    RedLED    PIN RB.0 OUTPUT
    OrangeLED PIN RB.1 OUTPUT
    YellowLED PIN RB.2 OUTPUT
    GreenLED  PIN RB.3 OUTPUT
     
    rnd       VAR BYTE
     
    PROGRAM Start
     
    Start:
      DO
        RANDOM rnd
     
        RedLED = rnd.0
        OrangeLED = rnd.1
        YellowLED = rnd.2
        GreenLED = rnd.3
        
        PAUSE 100
      LOOP
      
    END
    


    Bean


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    "The welfare of the people in particular has always been the alibi of tyrants." ~ Camus
    www.iElectronicDesigns.com

    ·
  • SpragmaticSpragmatic Posts: 59
    edited 2008-12-14 16:49
    Thank you Bean! Now I understand. Seems so much more easier when I see it.
Sign In or Register to comment.