November 22, 2024, 07:57:35 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.


Light Fade/Chaser not working--Prop-2 to Prop-1 conversion.

Started by jukingeo, April 25, 2010, 10:59:12 PM

Previous topic - Next topic

jukingeo

Hello all,

I finally have my new Prop-1 hooked up and I spent a good portion of the day doing Prop-2 to Prop-1 conversions for the really cool programs that I did on Prop-2, but knew I could get into a Prop-1.  The program below is one of them.

I THINK I did everything right, but apparently not.  I am getting an expected variable error on the first "IF - THEN" line.

I wonder if someone could tell me what I did wrong and how to correct it.

Thank You

Here is the code:

' =========================================================================
'
'   File...... Dim_Wave.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2007 EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... by Jukin'Geo
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
' This program demonstrates that it is possible to dim multiple channels
' using a look up table on the Prop-2

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


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

SYMBOL    speed          = PIN7
SYMBOL    switch         = PIN6


SYMBOL    Led6           = PIN5
SYMBOL    Led5           = PIN4
SYMBOL    Led4           = PIN3
SYMBOL    Led3           = PIN2
SYMBOL    Led2           = PIN1
SYMBOL    Led1           = PIN0


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

SYMBOL    IsOn           = 1
SYMBOL    IsOff          = 0

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

SYMBOL    level1         = B0                     'Led Level variables for
SYMBOL    level2         = B1                     'Loopup Table
SYMBOL    level3         = B2
SYMBOL    level4         = B3
SYMBOL    level5         = B4
SYMBOL    level6         = B5

SYMBOL    cycle          = B6                     'Look up table pointer
SYMBOL    hold           = B7                     'Output Delay loop

SYMBOL    direction      = B10                    'Sets switch status
SYMBOL    offset         = B11                    'Sets direction offset
SYMBOL    delay          = W4                     'Output Delay Value

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

Reset:
  DIRS = %00111111
  Direction = 0
' -----[ Program Code ]----------------------------------------------------

Main:

IF (switch = IsOn) THEN DIRECTION = DIRECTION ^ 1  'direction change

LOOKUP direction, [1, 9], offset               'Sets offset pointer for direction control
cycle = cycle + offset // 10                   'Up/Down counter

READ (cycle * 10), level1, level2, level3, level4, level5, level6   'Looks up level data

  FOR hold = 0 TO delay                        'Slows output via pot
    PWM Led1, level1, 3                        'LED PWM outputs
    PWM Led2, level2, 3
    PWM Led3, level3, 3
    PWM Led4, level4, 3
    PWM Led5, level5, 3
    PWM Led6, level6, 3
  NEXT

  HIGH Speed                                   ' charge RC circuit
  PAUSE 1
  RCTIME Speed, 1, delay                       ' read raw delay
  delay = delay / 30                           ' set new range

  GOTO Main                                    ' Rinse and repeat


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


' -------------------------------------------------------------------------


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

Levels    EEPROM     5,  30,  60,  100, 150, 255, 150, 100, 60, 30
              EEPROM     30,  60,  100, 150, 255, 150, 100, 60, 30, 5
              EEPROM     60,  100, 150, 255, 150, 100, 60, 30, 5, 30
              EEPROM     100, 150, 255, 150, 100, 60, 30, 5, 30, 60
              EEPROM     150, 255, 150, 100, 60, 30, 5, 30, 60, 100
              EEPROM     255, 150, 100, 60, 30, 5, 30, 60, 100, 150
              EEPROM     150, 100, 60, 30, 5, 30, 60, 100, 150, 255
              EEPROM     100, 60, 30, 5, 30, 60, 100, 150, 255, 150
              EEPROM     60, 30, 5, 30, 60, 100, 150, 255, 150, 100
              EEPROM     30, 5, 30, 60, 100, 150, 255, 150, 100, 60

JonnyMac

You have a lot of syntax errors -- shows that PBASIC2 is much more sophisticated than PBASIC1.  I don't want to deprive you of the opportunity fix the program and learn, so I'll just give these hints:

1. IF-THEN only does an implicit GOTO -- you cannot have code of the line as in your program
2. The BS1 does not use square braces [], only parenthesis ().
3. In the BS1 READ can only retrieve on value at a time.
4. The PWM is 5x slower in the BS1 versus the BS2
5. There is no RCTIME command (see POT)
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

And... your IO pin definitions and EEPROM table require updating, too.
Jon McPhalen
EFX-TEK Hollywood Office

jukingeo

Quote from: JonnyMac on April 26, 2010, 10:05:59 AM
You have a lot of syntax errors -- shows that PBASIC2 is much more sophisticated than PBASIC1.  I don't want to deprive you of the opportunity fix the program and learn, so I'll just give these hints:

1. IF-THEN only does an implicit GOTO -- you cannot have code of the line as in your program
2. The BS1 does not use square braces [], only parenthesis ().
3. In the BS1 READ can only retrieve on value at a time.
4. The PWM is 5x slower in the BS1 versus the BS2
5. There is no RCTIME command (see POT)


Yeah, I am still in that Prop-2 mindset...that coupled with my hiatus from this forum made me a bit rusty.

I remember you mentioning a book on syntax what was that called again?   I remember reading it for the Prop-2, but there should be one for the Prop-1 right?

I think it was this book:

http://www.parallax.com/Portals/0/Downloads/docs/prod/stamps/web-BSM-v2.2.pdf

(I am at work right now and for some reason my machine doesn't like to open large .pdf files...it just crashes).

Thanx,

Geo

JonnyMac

The BASIC Stamp makes it easy: simply double-click on a keyword, press [F1], and you'll jump to the correct page in the help file.  To ease your transition, here's an update that [sort of] works -- speed is your enemy here; the BS1 is not as fast as the BS2 so the LEDs flicker.

' =========================================================================
'
'   File...... Dim_Wave.BS1
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated... by Jukin'Geo
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
' This program demonstrates that it is possible to dim multiple channels
' using a look up table on the Prop-2

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


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

SYMBOL    speed          = 7
SYMBOL    switch         = PIN6

SYMBOL    Led6           = 5
SYMBOL    Led5           = 4
SYMBOL    Led4           = 3
SYMBOL    Led3           = 2
SYMBOL    Led2           = 1
SYMBOL    Led1           = 0


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

SYMBOL    IsOn           = 1
SYMBOL    IsOff          = 0


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

SYMBOL    level1         = B0                     'Led Level variables for
SYMBOL    level2         = B1                     'Loopup Table
SYMBOL    level3         = B2
SYMBOL    level4         = B3
SYMBOL    level5         = B4
SYMBOL    level6         = B5

SYMBOL    cycle          = B6                     'Look up table pointer
SYMBOL    hold           = B7                     'Output Delay loop

SYMBOL    addr           = B8
SYMBOL    delay         = B9

SYMBOL    direction      = B10                    'Sets switch status
SYMBOL    offset         = B11                    'Sets direction offset


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

Reset:
  DIRS = %00111111
  Direction = 0


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

Main:
  IF switch = IsOff THEN Get_Offset
    direction = 1 - direction

Get_Offset:
  LOOKUP direction, (1, 9), offset              ' Sets offset pointer for direction control
  cycle = cycle + offset // 10                  ' Up/Down counter

  addr = cycle * 10
  READ addr, level1
  addr = addr + 1
  READ addr, level2
  addr = addr + 1
  READ addr, level3
  addr = addr + 1
  READ addr, level4
  addr = addr + 1
  READ addr, level5
  addr = addr + 1
  READ addr, level6

  FOR hold = 0 TO delay                        'Slows output via pot
    PWM Led1, level1, 1                        'LED PWM outputs
    PWM Led2, level2, 1
    PWM Led3, level3, 1
    PWM Led4, level4, 1
    PWM Led5, level5, 1
    PWM Led6, level6, 1
  NEXT

  POT Speed, 100, delay
  delay = delay / 50                           ' set new range

  GOTO Main                                    ' Rinse and repeat


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


' -------------------------------------------------------------------------


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

Levels:
  EEPROM (  5,  30,  60, 100, 150, 255, 150, 100,  60,  30)
  EEPROM ( 30,  60, 100, 150, 255, 150, 100,  60,  30,   5)
  EEPROM ( 60, 100, 150, 255, 150, 100,  60,  30,   5,  30)
  EEPROM (100, 150, 255, 150, 100,  60,  30,   5,  30,  60)
  EEPROM (150, 255, 150, 100,  60,  30,   5,  30,  60, 100)
  EEPROM (255, 150, 100,  60,  30,   5,  30,  60, 100, 150)
  EEPROM (150, 100,  60,  30,   5,  30,  60, 100, 150, 255)
  EEPROM (100,  60,  30,   5,  30,  60, 100, 150, 255, 150)
  EEPROM ( 60,  30,   5,  30,  60, 100, 150, 255, 150, 100)
  EEPROM ( 30,   5,  30,  60, 100, 150, 255, 150, 100,  60)
Jon McPhalen
EFX-TEK Hollywood Office

jukingeo

Quote from: JonnyMac on April 26, 2010, 11:11:18 AM
The BASIC Stamp makes it easy: simply double-click on a keyword, press [F1], and you'll jump to the correct page in the help file.

THAT is something I didn't know.   But I do remember the help file now that you mentioned it.  ...Rusty Rusty Rusty.  I definitely need some oil

Quote
  To ease your transition, here's an update that [sort of] works -- speed is your enemy here; the BS1 is not as fast as the BS2 so the LEDs flicker.

Thank You.  I do agree this was too ambitious of a program to jump into, but I DO remember that the BS-1 was slower than the BS-2 and one of the reasons I chose this program WAS to test the speed.  You mentioned the flicker...so I want to see how bad it really is.

Question:  How come the LED's do not need the PIN definitions?  And for the inputs PIN6 has the PIN designation, but for the other input for the pot PIN7 doesn't.  Why is that?

Thanx,

Geo

JonnyMac

When you get into the help file you'll see that some command requires an actual value, e.g., 7 for the POT command.  When using the PINx definition you are either reading from an input pin (when PINx is on the right of = ) or writing to a pin register (when PINx is on the left side of equal).  If you do something like this:

 POT PIN7, 100, delay

... what happens is that the BS1 reads the value from PIN7, resulting in 0 or 1, which is where the POT command is run -- not what you want.  Again, this is another advantage of the BS2: when we (I was part of it at Parallax at the time) were creating PBASIC 2.5 we made the syntax smart so you wouldn't have to worry so much about these details.
Jon McPhalen
EFX-TEK Hollywood Office

jukingeo

Hello Jon,

I just tried the program out tonight.  Yeah, it flickers badly.  It CAN do it though, but with that amount of flicker it isn't usable.  So this one is definitely a scratch.

The program was originally one that you created for me when we were trying to push the Prop-2 to mimic pseudo multi-tasking.

Thanx,

Geo