November 21, 2024, 04:11:20 PM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


John - please get your red marker out!

Started by steveo, August 10, 2007, 12:04:41 PM

Previous topic - Next topic

steveo

As I'm learning I wanted to challenge myself to re-creating your "fire flies" program.

My code seems to work great, and from I can perceive re-creates your original more or less. That bad part is after I finished I went back to see how you did it, and your approach seem (lack of better term) much fancier.

I was hoping you can take a look below, and basically tell me where I could have improved my thinking.

Thanks!

' {$STAMP BS1}
' {$PBASIC 1.0}
' {$PORT COM1}

SYMBOL      PIN           = B2
SYMBOL      Lottery       = W5
SYMBOL      Brightness    = B4
SYMBOL      PINCheck      = B3
SYMBOL      WaitTime      = W6


Main:

RANDOM Lottery
PIN = Lottery // 6

IF PINCheck = PIN THEN Main

  FOR Brightness = 0 TO 255 STEP 1
    PWM  PIN, Brightness, 1
  NEXT

HIGH PIN
PAUSE 300

  FOR Brightness = 255 TO 0 STEP -1
    PWM  PIN, Brightness, 1
  NEXT

RANDOM lottery
WaitTime = lottery // 200 * 20
PAUSE WaitTime

PINCheck = PIN

GOTO Main





JonnyMac

1) My name is spelled J-o-n -- there is no "h" to be found within.  I've tried dropping hints (e.g., "Stehvio") but that hasn't worked.
    -- in programming, noticing little details like this is important.   ;)

2) If your code works, use it.

3) My code probably looks fancier because I'm an anal-retentive nut when it comes to formatting.  My guidelines are contained in "The Elements of PBASIC Style"; a document I wrote while working for Parallax and that you can now find in the BASIC Stamp Editor Help file.

Suggestions
-- Use a template that divides the program into sections; this keeps thing orderly and prevents the whoopsies...
-- In my world, variable names start with a lowercase letter; constants and labels start with an uppercase letter (see the Elements doc)
-- Don't use the word "PIN" as this is a keyword in PBASIC 2.5; this could show up with the Prop-1 if PBASIC 1.5 ever happens (I'm pushing for it)
-- Labels are in column one, code should be indented by two spaces, blocks two additional spaces.

As you might imagine, I write a lot of programs for a lot of people, so I don't know which one of my originals you're referring to.  I can tell that your program is randomly selecting and then ramping up an output.  While it doesn't allow the same output to repeat, it may -- depending on how the numbers fall -- skip a given output for several cycles.  I often employ a "play list" technique to ensure that all outputs are played on a given cycle before restarting.
Jon McPhalen
EFX-TEK Hollywood Office

steveo

Jonn,

Thank you for the input. How would you implement said "play list"?


Thanks

Steve

p.s.
Subtle never works on me, ask my wife. Sorry about the name (mis)spelling!

JonnyMac

Apparently obvious doesn't work, either -- my name is still spelled J-o-n.  What's with the extra letter?.... first an h, now an errant n.   ;D

In this thread I implemented a play list in the program; note that it takes a little work and a few variables in the Prop-1; this process is a little easier in the [more advanced] Prop-2.

http://www.efx-tek.com/php/smf/index.php?topic=182.0
Jon McPhalen
EFX-TEK Hollywood Office

steveo

Considering my recent  misspellings of your name, and your correction thereof, I thought the extra "n" would be a bit of humor. Email is truly a terrible medium for sarcasm.

Seriously though, thanks for all the pointers.