November 21, 2024, 08:10:32 PM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Cylon Eyes with Prop-1 Trainer board & other alterations

Started by jukingeo, September 15, 2007, 06:50:00 PM

Previous topic - Next topic

jukingeo

September 15, 2007, 06:50:00 PM Last Edit: September 15, 2007, 07:25:13 PM by jukingeo
Hello Jon,

I was wondering if the "Cylon Eye" program could be adapted to run with the Prop-1 Trainer board installed.


Also, while I have you.   I have already made minor alteration to your 'runway' lights chaser.  The problem I had was that the button had to be pushed every time to advance the lights.  I commented out the references to the button and now I have a speed controllered chaser.

Now I want to do one better with the button.

I will copied the lower 'meat' part of the program here:

Main:
  DO ' WHILE (Trigger = IsOn)                     ' run when button pressed
    GOSUB Speed_Delay                           ' read speed setting
    FOR thePin = 8 TO 13                        ' loop through lamps/LEDs
      HIGH thePin                               ' LED on
      PAUSE delay                               ' hold
      LOW thePin                                ' LED off
    NEXT
  LOOP
  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

' Reads pot on Prop-1 Trainer, then sets delay to 50 to ~150 ms

Speed_Delay:
  HIGH Speed                                    ' charge RC circuit
  PAUSE 1
  RCTIME Speed, 1, delay                        ' read raw delay
  delay = delay / 3 + 30                        ' set new range
  PAUSE delay                                   ' hold a bit
  RETURN

Now what I want to do is change the button's function to change the direction of the chase.  I did an experiment and found out that if I change the "FOR the pin" line's value from 8 to 13 to 13 to 8, the pattern DOES reverse.  Now in doing this I know that I could put the button scan press within a IF THEN loop.  But I don't know how that would be done.

Idealistically, I would like the chase pattern to reverse direction with each push of the button.

Oh, yes, that is correct...I have altered the speed delay line as well to make the chase 'faster'.

Thanx,

Geo

JonnyMac

Many ways to skin a cat... here's one to consider as it uses a couple PBASIC tricks.

' =========================================================================
'
'   File...... Flip_Chaser.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Speed           PIN     15                      ' SETUP = DN, no ULN
Aspect          PIN     14                      ' SETUP = DN
Leds            VAR     OUTH

' -----[ Constants ]-------------------------------------------------------

IsOn            CON     1
IsOff           CON     0

Pressed         CON     1
NotPressed      CON     0


' -----[ Variables ]-------------------------------------------------------

direction       VAR     Bit
offset          VAR     Nib
pntr            VAR     Nib                     ' memory pointer
delay           VAR     Word


' -----[ Initialization ]--------------------------------------------------

Reset:
  DIRH  = %00111111                             ' make LEDs outputs


' -----[ Program Code ]----------------------------------------------------

Main:
  IF (Aspect = Pressed) THEN                    ' button pressed?
    direction = direction ^ 1                   ' yes, flip direction bit
    DO WHILE (Aspect = Pressed)                 ' force release
    LOOP
  ENDIF

  READ pntr, Leds                               ' get LED pattern
  LOOKUP direction, [1, 5], offset              ' get pointer offset
  pntr = pntr + offset // 6                     ' update the pointer

Speed_Delay:
  HIGH Speed                                    ' charge RC circuit
  PAUSE 1
  RCTIME Speed, 1, delay                        ' read raw delay
  delay = delay / 3 + 30                        ' set new range
  PAUSE delay                                   ' hold a bit
  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

Pattern         DATA    %000001, %000010, %000100
                DATA    %001000, %010000, %100000
Jon McPhalen
EFX-TEK Hollywood Office

jukingeo

Hello John,

This program is WAY cool, and I began playing around with it right away.  I started by playing around with the bits in the Data section and for the most part I got what I wanted.

However, I wanted to do the Cylon Eye effect and I added more data lines to the program to accomodate this.  Now is where I ran into a few snags.  The first problem I found right away was in the "pntr + offset // 6"  line.  I figured this is the line that had to do with the stepping.  The Cylon Eye effect (or rather as I programmed it, KITT Trans-Am effect) has 20 data points.  So I simply bumped this number up to 20.

Here is what I did:

Main:
  IF (Aspect = Pressed) THEN                    ' button pressed?
    direction = direction ^ 1                   ' yes, flip direction bit
    DO WHILE (Aspect = Pressed)                 ' force release
    LOOP
  ENDIF

  READ pntr, Leds                               ' get LED pattern
  LOOKUP direction, [1, 5], offset              ' get pointer offset
  pntr = pntr + offset // 20                    ' update the pointer

Speed_Delay:
  HIGH Speed                                    ' charge RC circuit
  PAUSE 1
  RCTIME Speed, 1, delay                        ' read raw delay
  delay = delay / 3 + 500                        ' set new range
  PAUSE delay                                   ' hold a bit
  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

Pattern         DATA    %000001, %000011, %000111, %001111, %011111, %111111
                DATA    %111110, %111100, %111000, %110000, %100000
                DATA    %110000, %111000, %111100, %111110, %111111, %011111
                DATA    %001111, %000111, %000011


I have changed the delay to +500 so you can see what is happening at slow speed.

Two issues cropped up, it seems that after the 16th place (the highlighed string above), the rest of the data afterwards is ignored and the cycle goes back to the beginning.

The second issue is that the the button press is doing something weird.

So at this point I do not know what the solution would be to 'fix' the problem.

However, overall, I do think this is a nice template to work from and I think I will be working with this program alot.  For one I would like to expand on it.  Changing the buttons fuction from just plain reversing to cycling through a series of banks.  This way the program could be already set in the Prop-2 and then all I have to do is press the button and cycle through my data entries.

Of all the chaser programs I played around with thus far, I like this style the best.  I like the idea of the data bank and that I can alter the style.  However, I would like it to be in a way in which there are almost no limits to how many entries I can make in the data area (granted there are limits and you will always run out of programming lines).

As I said before with the button, I would like to set it to access multiple banks.  But I would even like to entertain a subroutine that would automatically chase these banks too.  So lets say we have a simple light chase in data bank one.  Let that cycle for about 1 min, then the program would select another bank, lets say a dark chase, and let that cyle for about 1 min.

This is fantastic...in the very least, I know I can use the Prop-2 to create really nice marquee displays.

I am going to play with this program some more.

Thanx again for your help and writing all the code out for me.  I would like to know more what is goin on.

For one, what line is the data referenced from?  I don't see where it is called from in the program itself.

So now if I find a Prop-1 program that references to EEPROM, I need to change the "EEPROM" lines to DATA, correct?

I think I saw a primer here in this forum on program conversions from Basic 1 to Basic 2.  I am going to have to find that and read it.

This is like sensory overload for me.  It is great that I am able to get the Prop-2 to do something, but what it is that I am doing I still would like to know.

Thanx again,

Geo















JonnyMac

Try this version -- it works, though reversing the direction of this pattern has no visual effect.

' =========================================================================
'
'   File...... Flip_Chaser_V2.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Speed           PIN     15                      ' SETUP = DN, no ULN
Aspect          PIN     14                      ' SETUP = DN
Leds            VAR     OUTH

' -----[ Constants ]-------------------------------------------------------

IsOn            CON     1
IsOff           CON     0

Pressed         CON     1
NotPressed      CON     0


' -----[ Variables ]-------------------------------------------------------

direction       VAR     Bit
offset          VAR     Byte
pntr            VAR     Byte                    ' memory pointer
delay           VAR     Word


' -----[ Initialization ]--------------------------------------------------

Reset:
  DIRH  = %00111111                             ' make LEDs outputs


' -----[ Program Code ]----------------------------------------------------

Main:
  IF (Aspect = Pressed) THEN                    ' button pressed?
    direction = direction ^ 1                   ' yes, flip direction bit
    DO WHILE (Aspect = Pressed)                 ' force release
    LOOP
  ENDIF

  READ pntr, Leds                               ' get LED pattern
  LOOKUP direction, [1, 19], offset             ' get pointer offset
  pntr = pntr + offset // 20                    ' update the pointer

Speed_Delay:
  HIGH Speed                                    ' charge RC circuit
  PAUSE 1
  RCTIME Speed, 1, delay                        ' read raw delay
  delay = delay / 3 + 50                        ' set new range
  PAUSE delay                                   ' hold a bit
  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

Pattern         DATA    %000001
                DATA    %000011
                DATA    %000111
                DATA    %001111
                DATA    %011111
                DATA    %111111
                DATA    %111110
                DATA    %111100
                DATA    %111000
                DATA    %110000
                DATA    %100000
                DATA    %110000
                DATA    %111000
                DATA    %111100
                DATA    %111110
                DATA    %111111
                DATA    %011111
                DATA    %001111
                DATA    %000111
                DATA    %000011


Fixes:
  - changed "offset" and "pntr" from Nib to Byte (extended maximum value from 15 to 255)
  - updated the LOOKUP line for revere direction (changed 5 [-1 for six entries] to 19 [-1 for 20 entries])

Answers:
  - The READ function is what pulls value(s) from a DATA statement; DATA is an update of the BS1 EEPROM directive (there are subtle differences)
Jon McPhalen
EFX-TEK Hollywood Office

jukingeo

Quote from: JonnyMac on September 16, 2007, 01:10:41 PM
Try this version -- it works, though reversing the direction of this pattern has no visual effect.


Fixes:
  - changed "offset" and "pntr" from Nib to Byte (extended maximum value from 15 to 255)
  - updated the LOOKUP line for revere direction (changed 5 [-1 for six entries] to 19 [-1 for 20 entries])

Answers:
  - The READ function is what pulls value(s) from a DATA statement; DATA is an update of the BS1 EEPROM directive (there are subtle differences)

The reverse still doesn't work if unless you use a symetrical pattern.  I think the best thing is to scrap the reverse idea and expand on this circuit to add a 'program change' function to the button instead.

As for the limitation, so changing the Nib to Byte is what keep the Data from reading past the 16th entry (0-15).  So the way you fixed it now, you can have 255 entries.  NICE!  I think that will keep me busy for a while.

You also refreshed my memory.  Yes, it WAS the READ function that I should have been looking for.  I remember now.  Memory is still foggy on my Basic.

However, I have found some nice information on the Parallax site and I am now reading up on some of the information you have already posted here on coversions from the Prop-1 to Prop-2.   I think Parallax has your book back in stock.  Going to put an order in for that.

Thanx again.

JonnyMac

September 16, 2007, 03:16:04 PM #5 Last Edit: September 16, 2007, 03:27:09 PM by JonnyMac
As the Prop-1 and Prop-2 are built with Parallax BASIC Stamp controllers, their site will have an enormous amount of information that is applicable to our controllers -- some of it written by yours truly.

Here's an update to your program that allows you to select between two patterns.  Yes, more patterns can be added, but with just one button you'd have to step through them sequentially.

' =========================================================================
'
'   File...... Flip_Chaser_v3.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Speed           PIN     15                      ' SETUP = DN, no ULN
PatSelect       PIN     14                      ' SETUP = DN
Leds            VAR     OUTH

' -----[ Constants ]-------------------------------------------------------

IsOn            CON     1
IsOff           CON     0

Pressed         CON     1
NotPressed      CON     0


' -----[ Variables ]-------------------------------------------------------

patNum          VAR     Bit
offset          VAR     Byte
delay           VAR     Word


' -----[ Initialization ]--------------------------------------------------

Reset:
  DIRH  = %00111111                             ' make LEDs outputs


' -----[ Program Code ]----------------------------------------------------

Main:
  IF (PatSelect = Pressed) THEN                 ' button pressed?
    patNum = patNum ^ 1                         ' yes, flip pattern bit
    offset = 0                                  ' reset to start
    DO WHILE (PatSelect = Pressed)              ' force release
    LOOP
  ENDIF

  BRANCH patNum, [Pat1, Pat2]
  GOTO Main

Pat1:
  READ Pattern1 + offset, Leds                  ' get LED pattern
  offset = offset + 1 // 10                     ' keep offset in bounds
  GOTO Speed_Delay

Pat2:
  READ Pattern2 + offset, Leds
  offset = offset + 1 // 20
  GOTO Speed_Delay

Speed_Delay:
  HIGH Speed                                    ' charge RC circuit
  PAUSE 1
  RCTIME Speed, 1, delay                        ' read raw delay
  delay = delay / 3 + 50                        ' set new range
  PAUSE delay                                   ' hold a bit
  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------


' -----[ User Data ]-------------------------------------------------------


Pattern1        DATA    %000001
                DATA    %000010
                DATA    %000100
                DATA    %001000
                DATA    %010000
                DATA    %100000
                DATA    %010000
                DATA    %001000
                DATA    %000100
                DATA    %000010


Pattern2        DATA    %000001
                DATA    %000011
                DATA    %000111
                DATA    %001111
                DATA    %011111
                DATA    %111111
                DATA    %111110
                DATA    %111100
                DATA    %111000
                DATA    %110000
                DATA    %100000
                DATA    %110000
                DATA    %111000
                DATA    %111100
                DATA    %111110
                DATA    %111111
                DATA    %011111
                DATA    %001111
                DATA    %000111
                DATA    %000011
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

September 16, 2007, 04:16:34 PM #6 Last Edit: September 16, 2007, 04:29:34 PM by JonnyMac
Here's how to do step through multiple patterns.

' =========================================================================
'
'   File...... Flip_Chaser_v4.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Speed           PIN     15                      ' SETUP = DN, no ULN
PatSelect       PIN     14                      ' SETUP = DN
Leds            VAR     OUTH


' -----[ Constants ]-------------------------------------------------------

IsOn            CON     1
IsOff           CON     0

Pressed         CON     1
NotPressed      CON     0


' -----[ Variables ]-------------------------------------------------------

patNum          VAR     Nib                     ' pattern, 0 - 3
pntr            VAR     Word                    ' start of pattern
offset          VAR     Byte                    ' offset into pattern
patLen          VAR     Byte                    ' length of pattern

delay           VAR     Word


' -----[ Initialization ]--------------------------------------------------

Reset:
  DIRH  = %00111111                             ' make LEDs outputs


' -----[ Program Code ]----------------------------------------------------

Main:
  IF (PatSelect = Pressed) THEN                 ' button pressed?
    Leds = %000000                              ' clear to indicate press
    patNum = patNum + 1 // 4                    ' point to next pattern
    offset = 0                                  ' reset to start
    DO WHILE (PatSelect = Pressed)              ' force release
    LOOP
  ENDIF

  LOOKUP patNum, [Pattern1, Pattern2, Pattern3, Pattern4], pntr
  LOOKUP patNum, [10, 20, 6, 6], patLen

  READ pntr + offset, Leds                      ' update LEDs
  offset = offset + 1 // patLen                 ' adjust offset

Speed_Delay:
  HIGH Speed                                    ' charge RC circuit
  PAUSE 1
  RCTIME Speed, 1, delay                        ' read raw delay
  delay = delay / 3 + 50                        ' set new range
  PAUSE delay                                   ' hold a bit
  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

Pattern1        DATA    %000001
                DATA    %000010
                DATA    %000100
                DATA    %001000
                DATA    %010000
                DATA    %100000
                DATA    %010000
                DATA    %001000
                DATA    %000100
                DATA    %000010

Pattern2        DATA    %000001
                DATA    %000011
                DATA    %000111
                DATA    %001111
                DATA    %011111
                DATA    %111111
                DATA    %111110
                DATA    %111100
                DATA    %111000
                DATA    %110000
                DATA    %100000
                DATA    %110000
                DATA    %111000
                DATA    %111100
                DATA    %111110
                DATA    %111111
                DATA    %011111
                DATA    %001111
                DATA    %000111
                DATA    %000011

Pattern3        DATA    %000000
                DATA    %001100
                DATA    %010010
                DATA    %100001
                DATA    %010010
                DATA    %001100

Pattern4        DATA    %000000
                DATA    %001100
                DATA    %011110
                DATA    %111111
                DATA    %110011
                DATA    %100001
Jon McPhalen
EFX-TEK Hollywood Office

jukingeo

Hello Jon,

WOW, this is totally amazing.  Perfect!

I am going to look over the program carefully to see how you did this.  There are certain things I am grasping, but other things just slip by me (<<Skipper, I just don't know the codes!!!>>).

Now what would I have to do to alter this to take it to an 8 channel or (heaven forbid) the whole enchilada, a 16 channel chase?

I figure that the

Reset:
  DIRH  = %00111111

line has something to do with that, right?

For now I am going to have a little fun with this program :).

Thanx again.

Geo

JonnyMac

September 17, 2007, 08:08:45 AM #8 Last Edit: September 17, 2007, 08:11:01 AM by JonnyMac
If you really want to learn, Geo, what you'll do is crack open the help file and read about the keywords you don't quite grasp.  What you'll learn about DIRH is that it sets the input/output state of P0-P7; a 0 bit makes a pin an input, a 1 bit makes a pin an output.  Yes, you will have to modify this for 8 or 16 channels.

Updating to 16 channels involves other changes: in addition to making 16 outputs:

  DIRS = $FFFF

You have to store 16-bit patterns (note the Word modifier):

Chaser          DATA    Word %0000000000000001
                DATA    Word %0000000000000010
                DATA    Word %0000000000000100
                DATA    Word %0000000000001000


Then you have to pull these values from memory (note the Word modifier):

  READ (Chaser + (2 * pntr)), Word LEDs

Let me suggest you spend more time on your essential programming skills before moving on.
Jon McPhalen
EFX-TEK Hollywood Office

jukingeo

Hello Jon,

Ok, I was just asking about that "bit" (or rather byte (pun intended)) back there if that is what controlled how 'large' I can make the chase in terms of number of channels.

I know I am not going to go that far yet.  I do really have to still learn the commands and how they apply to everything you written here thusfar.

You mentioned a help file...is that here on your site?  I was looking for it earlier.  I basically need to know what all the commands are and the proper syntax.  I need to know how to set the variables and constants.  Well, really, I need to learn just about everything :(.

Well, you did give me alot to digest here and alot to play with in regards to the programs you written for me.  So I probably will hit the books and do my own research to learn more about PBasic.

I do, of course, would like to start to do things on my own.  (Besides you are probably going to have your plate full because Halloween is coming up).

Thanx for getting me started, though.  Well, actually thanx for helping out with the programming.  It was Vern that actually got me started on this Basic Stamp thing with his Spider's Preyground.

Geo


JonnyMac

The Help file is part of the BASIC Stamp Editor.

Let me also suggest that you read "What's a Microcontroller" (written by Andy Lindsay) and "StampWorks" (written by me) -- these books will give you a really firm grip on BS2 programming.
Jon McPhalen
EFX-TEK Hollywood Office

jukingeo

Quote from: JonnyMac on September 17, 2007, 07:10:49 PM
The Help file is part of the BASIC Stamp Editor.

Let me also suggest that you read "What's a Microcontroller" (written by Andy Lindsay) and "StampWorks" (written by me) -- these books will give you a really firm grip on BS2 programming.

Hello Jon,

Yeah, I am going to get your StampWorks book.  I see that Parallax has it available again.  Plus there is some information on that site I am going to look into as well.

Thanx,

Geo