Shop OBEX P1 Docs P2 Docs Learn Events
PropBasic and the Hackable Badge — Parallax Forums

PropBasic and the Hackable Badge

Since it looks like there is some renewed interest in PropBasic, again, I downloaded PropBasic_1_42 for linux, and set up a somewhat cumbersome development system. This should be temporary until PropBasic shows up on the Propeller IDE for linux.

I use Geany as the editor and compiler, plus I run the generated Spin file on Propeller IDE; this is being done on my xubuntu set up. Although it is a little cumbersome, the end product seems to work, when run with Propeller IDE. So far so good.

My interest at the moment is the Hackable Badge, I would like to see if there could be another way of programming the Badge, aside from doing it in Spin or PropGCC. One thing of interest with PropBasic is that you can set up a program in LMM, which could allow for a fairly large Badge program, I think. Not even sure if this is the correct way of looking at the proper usage of PropBasic.

Now, that next big hurdle to overcome is, how do you set up drivers, in PropBasic, for the devices on the Badge. I am thinking, start with the charlieplexed LEDs, not even sure how to approach this using PropBasic. Maybe the buttons next, followed by the access to the oled, and then the IR. That should cover the main components, oh I forgot, another important item, setting up a datetime and access to the RC, just to name a few more items.

In the long run, I guess the experiment would be set up and find out if using PropBasic would be of any benefit, in using it to program the Badge. Since the PropBasic code being produced is PASM, even a large sized Badge program should run fairly quick, even if part of it is done in LMM. So, I am open to some discussion about this before I start coding, or going any further.

Ray

«13

Comments

  • Here is my first little PropBasic test program, PropBasic likes it, but Propeller IDE does not.
    PropBasic 1
    Propeller IDE 0

    Ray
    ' test1.pbas 
    ' Jan 24, 2016
    
    DEVICE P8X32A, XTAL1, PLL16X
    FREQ 80_000_000
    
    LED PIN 16 OUTPUT
    
    PROGRAM Start LMM
    
    Start:
      DO
    	HIGH LED
    	PAUSE 1000
    	LOW LED
    	PAUSE 1000
      LOOP
    

    Propeller IDE
    Build Manager
    "Build failed!"
    An open-source compiler for Propeller Spin
    Copyright © 2012-2015 Parallax, Inc.
    Compiling /home/ray/propbasic/test1.spin
    /home/ray/propbasic/test1.spin(28:35) : error : Expected "," or end of line
    Line:
    long @@@Start
    Offending Item: @

    Propeller IDE
    ''  *** COMPILED WITH PropBasic VERSION 00.01.42  Aug 25, 2013 ***
                                                                 '' test1.pbas 
                                                                 '' Jan 24, 2016
    
    
    
    CON                                                          'DEVICE P8X32A, XTAL1, PLL16X
      _ClkMode = XTAL1 + PLL16X                                 
    
      _XInFreq =   5000000                                       'FREQ 80_000_000
    
    
    ' LED PIN 16 OUTPUT                                          'LED PIN 16 OUTPUT
    
    
    PUB __Program | __VarsPtr                                    'PROGRAM Start LMM
      __VarsPtr := 0                                            
      __OFFSET := @__Init                                       
      CogInit(0, @_LMM_Entry, __VarsPtr)                        
                                                                
    DAT                                                         
                      org           0                           
    __Init                                                      
    __RAM                                                       
                      mov           dira,__InitDirA             
                      mov           outa,__InitOutA             
                      rdlong        __PC,__PC                   
                      long          @@@Start                    
    
    
    Start                                                        'Start:
    
    __DO_1                                                       '  DO
    
                      or            dira,LED                     '	HIGH LED
                      or            outa,LED                    
    
                      mov           __temp2,_1000                '	PAUSE 1000
                      mov           __temp1,_1mSec              
                      add           __temp1,cnt                 
    __L0001                                                     
                      waitcnt       __temp1,_1mSec              
                      djnz          __temp2,#_LMM_JUMP          
                      long          @@@__L0001                  
    
                      or            dira,LED                     '	LOW LED
                      andn          outa,LED                    
    
                      mov           __temp2,_1000                '	PAUSE 1000
                      mov           __temp1,_1mSec              
                      add           __temp1,cnt                 
    __L0002                                                     
                      waitcnt       __temp1,_1mSec              
                      djnz          __temp2,#_LMM_JUMP          
                      long          @@@__L0002                  
    
                      rdlong        __PC,__PC                    '  LOOP
                      long          @@@__DO_1                   
    __LOOP_1                                                    
    
                                                                 ''  GOTO Start
    DAT                                                         
      '-------------------------------------------------------------------------------------------
      'LMM Execution code                                       
      ' -------------------------------------------------------------------------------------------
                                                                
      ORG 0                                                     
                                                                
    _LMM_Entry                                                  
                      mov           __PC,__OFFSET               
                                                                
    _LMM_LOOP                                                   
                      rdlong        __INSTR1,__PC               
                      add           __PC,#4                     
    __INSTR1                                                    
                      nop           ' Placeholder for LMM instruction
                                                                
                      rdlong        __INSTR2,__PC               
                      add           __PC,#4                     
    __INSTR2                                                    
                      nop           ' Placeholder for LMM instruction
                                                                
                      rdlong        __INSTR3,__PC               
                      add           __PC,#4                     
    __INSTR3                                                    
                      nop           ' Placeholder for LMM instruction
                                                                
                      rdlong        __INSTR4,__PC               
                      add           __PC,#4                     
    __INSTR4                                                    
                      nop           ' Placeholder for LMM instruction
                                                                
                      jmp           #_LMM_LOOP                  
                                                                
    _LMM_JUMP                                                   
                      rdlong        __PC,__PC                   
                      jmp           #_LMM_LOOP                  
                                                                
    _LMM_CALL                                                   
                      movd          $+2,__STACKPTR              
                      add           __STACKPTR,#1               
                      mov           0-0,__PC                    
                      rdlong        __PC,__PC                   
                      jmp           #_LMM_LOOP                  
                                                                
    _LMM_RET                                                    
                      sub           __STACKPTR,#1               
                      movs          $+2,__STACKPTR              
                      mov           __PC,#4                     
                      add           __PC,0-0                    
                      jmp           #_LMM_LOOP                  
                                                                
    _LMM_MOVS                                                   
                      rdlong        __MOVS,__PC                 
                      movs          __MOVS,__INDEX              
                      add           __PC,#4                     
    __MOVS                                                      
                      nop           ' Placeholder for LMM instruction
                      jmp           #_LMM_LOOP                  
                                                                
    _LMM_MOVD                                                   
                      rdlong        __MOVD,__PC                 
                      movd          __MOVD,__INDEX              
                      add           __PC,#4                     
    __MOVD                                                      
                      nop           ' Placeholder for LMM instruction
                      jmp           #_LMM_LOOP                  
                                                                
                      '             Variables for LMM execution code
    __INDEX          LONG 0  ' Used by MOVS and MOVD            
    __OFFSET         LONG 0-0' Set by spin                      
    __PC             LONG 0  ' Program counter                  
    __STACKPTR       LONG __STACK  ' Stack pointer              
    __STACK          LONG 0[16] ' Return stack                  
    '**********************************************************************
    __InitDirA       LONG %00000000_00000001_00000000_00000000
    __InitOutA       LONG %00000000_00000000_00000000_00000000
    _1000            LONG 1000
    LED              LONG 1 << 16
    _1mSec           LONG 80000
    _FREQ            LONG 80000000
    
    ____STRING_adr   LONG 0
    __clkfreq_adr    LONG 0
    
    __remainder
    __temp1          RES 1
    __temp2          RES 1
    __temp3          RES 1
    __temp4          RES 1
    __temp5          RES 1
    __param1         RES 1
    __param2         RES 1
    __param3         RES 1
    __param4         RES 1
    __paramcnt       RES 1
    
    FIT 492
    
    CON
      LSBFIRST                         = 0
      MSBFIRST                         = 1
      MSBPRE                           = 0
      LSBPRE                           = 1
      MSBPOST                          = 2
      LSBPOST                          = 3
    
    DAT
    __DATASTART
    
    
  • PropBasic likes it, Propeller IDE does not.

    Ray

    ' test1.pbas 
    ' Jan 24, 2016
    
    DEVICE P8X32A, XTAL1, PLL16X
    FREQ 80_000_000
    
    LED PIN 16 OUTPUT
    
    
    PROGRAM Start
    
    Start:
     Blinker TASK
    
    
    TASK Blinker
      DO
    	HIGH LED
    	PAUSE 1000
    	LOW LED
    	PAUSE 1000
      LOOP
    ENDTASK
    

    Build Manager
    "Build failed!"
    An open-source compiler for Propeller Spin
    Copyright © 2012-2015 Parallax, Inc.
    Compiling /home/ray/propbasic/test1.spin
    /home/ray/propbasic/test1.spin(37:18) : error : Expected ":"
    Line:
    __InitDirA LONG %00000000_00000001_00000000_00000000
    Offending Item: LONG

    Propeller IDE
    ''  *** COMPILED WITH PropBasic VERSION 00.01.42  Aug 25, 2013 ***
                                                                 '' test1.pbas 
                                                                 '' Jan 24, 2016
    
    
    
    CON                                                          'DEVICE P8X32A, XTAL1, PLL16X
      _ClkMode = XTAL1 + PLL16X                                 
    
      _XInFreq =   5000000                                       'FREQ 80_000_000
    
    
    ' LED PIN 16 OUTPUT                                          'LED PIN 16 OUTPUT
    
    
    
    PUB __Program | __VarsPtr                                    'PROGRAM Start
      __VarsPtr := 0                                            
      CogInit(0, @__Init, __VarsPtr)                            
                                                                
    DAT                                                         
                      org           0                           
    __Init                                                      
    __RAM                                                       
                      mov           dira,__InitDirA             
                      mov           outa,__InitOutA             
                      jmp           #Start                      
    
    
    Start                                                        'Start:
    
    OBJ Blinker: "Blinker.spin"                                  ' Blinker TASK
    
    
    
    '**********************************************************************
    __InitDirA       LONG %00000000_00000001_00000000_00000000
    __InitOutA       LONG %00000000_00000000_00000000_00000000
    LED              LONG 1 << 16
    _FREQ            LONG 80000000
    
    ____STRING_adr   LONG 0
    __clkfreq_adr    LONG 0
    Blinker_COG      LONG 0-0
    
    __remainder
    __temp1          RES 1
    __temp2          RES 1
    __temp3          RES 1
    __temp4          RES 1
    __temp5          RES 1
    __param1         RES 1
    __param2         RES 1
    __param3         RES 1
    __param4         RES 1
    __paramcnt       RES 1
    
    FIT 492
    
    CON
      LSBFIRST                         = 0
      MSBFIRST                         = 1
      MSBPRE                           = 0
      LSBPRE                           = 1
      MSBPOST                          = 2
      LSBPOST                          = 3
    
    ' TASK Blinker                                               'TASK Blinker
    
    
    DAT
    __DATASTART
    
    
  • BeanBean Posts: 8,129
    The spin compiler must support @@@ to work with PropBASIC.
    BSTC is the compiler I use.

    Bean
  • The spin compiler must support @@@ to work with PropBASIC.
    BSTC is the compiler I use.

    Bean
    Hmmm, interesting.

    I believe the "@@@" for openspin was discussed in another forum, and it looks like openspin will NOT be adding that feature. So, where does that leave PropBasic, locked into BST?

    SimpleIDE is no longer a viable alternative for supporting PropBasic, and Propeller IDE might be questionable for supporting ProbBasic. Well what other options are available?

    I guess, maybe Geany could be an option, if somebody comes up with a plugin for running PropBasic. Geany is available for Windows, Linux, and not so sure about the Apple stuff. With a plugin that would definitely make PropBasic easy to use.

    We have had this discussion, about PropBasic at least three other times, and the outcome is always the same, a short flurry of activity and then PropBasic goes dormant. What would make the outcome different this time around?

    Ray
  • Hi
    I use Geany-
    instructions for setting up and using bat files etc are around somewhere, discussed some time ago.
    I have no colour coding, but that is not a problem for me.
    Uses BSTC
    Error reports can be confusing but a little head scratching sorts it out.
    Dave
  • Hi again
    Here are the instructions for Geany as an editor, with instruction for building/loading prop

    http://forums.parallax.com/discussion/118611/download-propbasic-here-00-01-14-last-version-for-bst/p27

    Dave
  • Any bstc.linux experts out there? I installed bstc on xubuntu 15.10 64-bit little box, and tired running a test program. It looks like it is loading, but my QuickStart board is not blinking P16. Is their some step that I missing here?

    I realize that bstc is a 32-bit program, but I would imagine that the program would not run to begin with if that was an issue. Anybody have a solution?

    Ray
    ray@raybrix:~/propbasic$ ./bstc.linux -d /dev/ttyUSB0 -p0 Blinker.spin
    Brads Spin Tool Compiler v0.15.3 - Copyright 2008,2009 All rights reserved
    Compiled for i386 Linux at 08:17:46 on 2009/07/20
    Loading Object Blinker
    Program size is 152 longs
    Compiled 56 Lines of Code in 0.005 Seconds
    We found a Propeller Version 1
    Propeller Load took 0.419 Seconds
    ray@raybrix:~/propbasic$
  • I got the thing to work, but this is really getting to be cumbersome. Now I might try to add the bstc command to the Geany Build or Execute line, then maybe I can have the thing run from one area.

    If anybody is playing along, be careful with the PropBasic manual, the latest that was pointed to for download, the documentation does not necessarily describe correctly how a command is supposed to work. For example, the way I set up the TASK, that is not exactly as the PropBasic manual describes it, unless of course there are multiple ways of doing it.

    Ray
    DEVICE P8X32A, XTAL1, PLL16X
    FREQ 80_000_000
    STACK 8
    
    LED PIN 16 OUTPUT
    
    Blinker TASK
    
    PROGRAM Start
    
    Start:
     COGSTART Blinker
      
    END
      
    TASK Blinker LMM
      DO
    	HIGH LED
    	PAUSE 1000
    	LOW LED
    	PAUSE 1000
      LOOP
    ENDTASK 
    
    ray@raybrix:~/propbasic$ ./bstc.linux -d /dev/ttyUSB0 -p 0 test1.spin
    Brads Spin Tool Compiler v0.15.3 - Copyright 2008,2009 All rights reserved
    Compiled for i386 Linux at 08:17:46 on 2009/07/20
    Loading Object test1
    Loading Object Blinker.spin
    Program size is 456 longs
    Compiled 166 Lines of Code in 0.017 Seconds
    We found a Propeller Version 1
    Propeller Load took 0.391 Seconds
    ray@raybrix:~/propbasic$
  • This for my Geany set up on an xubuntu 15.10 64-bit, little box. I added a "run bstc" label
    to run bstc. Probably has to be refined somewhat, but for a test run it should suffice.


    Build->Set Build Commands
    Bottom of window:
    Execute commands
    1 "Execute" | "%d/PropBasic.linux" %d/%e.pbas | /home/ray/propbasic
    2 "run bstc" | "%d/bstc.linux" -d /dev/ttyUSB0 -p 0 %d/%e.spin | /home/ray/propbasic

    Ray
  • I guess the temporary Geany solution seems to be working, the way I want it, at least. But, I must note that if PropBasic is to move forward, I think it has to be changed so it can run, completely, with openspin.

    With the temp Geany solution, if you want to do more, like have the program burned to EEPROM, '-p 1', you will have to make a manual change to the "run bstc" command. I guess this is a little better than working with a bash script. For your next challenge you will have to find and download bstc, happy searching.

    Ray
  • Rsadeika wrote: »
    For your next challenge you will have to find and download bstc, happy searching.

    Ray

    Brad's Spin Tool can be found here:

    http://www.fnarfbargle.com/bst.html
  • BeanBean Posts: 8,129
    IMO openspin needs to support the @@@ operator.
    It's kind of silly to not have a way to get the absolute address of a label.

    Bean
  • I started experimenting with the charlieplexing of the LEDs on the Hackable Badge. Below is a program that works, but I am not sure as to how too make this as efficient as as possible using PropBasic.

    Every LED will need a three state command to turn it on, HIGH, LOW, INPUT, and I think a one state command to turn it off. The specific pin will have to be declared either HIGH, LOW or INPUT, I do not know how this could be done in a workable manner.

    I guess you could try implementing something in PASM and then use ASM ... ENDASM, but even that is a little daunting at this stage. Anybody have any ideas?

    Ray
    'charlie1.pbas
    ' Jan 26, 2016
    
    DEVICE P8X32A, XTAL1, PLL16X
    FREQ 80_000_000
    
    
    
    Led0_on SUB
    LED0_off SUB
    
    PROGRAM Start
    
    
    Start:
    	Led0_on
    	PAUSE 3000
    	Led0_off
    
    END
    
    SUB Led0_off
    BLU_CP2 PIN 8 INPUT    ' Badge
    	INPUT BLU_CP2    ' P8	
    ENDSUB
    
    SUB Led0_on
    'BLU_CP2 PIN 8 OUTPUT    ' Badge
    BLU_CP1 PIN 7 OUTPUT    ' Badge
    BLU_CP0 PIN 6 INPUT    ' Badge
    
    	LOW BLU_CP2    ' P8
    	HIGH BLU_CP1   ' P7
    	INPUT BLU_CP0  ' P6
    ENDSUB
    
    
  • One idea... Have a PropBasic Task (which runs in it's own cog) looping and switching on or off the correct sequence of leds, according to some Hub vars. This will allow other cogs to feed the settings into the led Task(Cog) without being held up on running the actual led lighting loop.


    You could have a Hub byte for the blue LEDs, with each bit representing one LED.
    And either another 1 or 2 Hub bytes for the 2 RGB LEDs, again with 1 bit per color.
  • The program below seems to work as expected. This runs a basic test to see if all the LEDs turn on/off as required.

    I made all the SUBs LMM, not sure what that does for me, but it does run, as expected. I also ran the below program with Propeller IDE, that also ran as expected. This time, using LMM, did not produce an error, when run with Propeller IDE. Not sure what is going on, maybe when you run a TASK in LMM, that produces an error when run in Propeller IDE.

    I am hoping that one of the PropBasic experts will give me some hints in how to trim the fat, if there is any fat to be trimmed.

    Now I will give the Badge RGB LEDs a try, I think that will be somewhat harder than the plain LEDs. At some point I guess I will have to create lib file that will contain all the code for operating the Hackable Badge.

    Ray
    'charlie1.pbas
    ' Jan 26, 2016
    '
    ' Used to work the Hackable Badge LEDs
    
    DEVICE P8X32A, XTAL1, PLL16X
    FREQ 80_000_000
    
    BLU_LED8 PIN 8 OUTPUT    ' Badge
    BLU_LED7 PIN 7 OUTPUT    ' Badge
    BLU_LED6 PIN 6 OUTPUT    ' Badge
    
    Led0_on SUB
    Led0_off SUB
    Led1_on SUB
    Led1_off SUB
    Led2_on SUB
    Led2_off SUB
    Led3_on SUB
    Led3_off SUB
    Led4_on SUB
    Led4_off SUB
    Led5_on SUB
    Led5_off SUB
    
    
    PROGRAM Start
    
    
    Start:
    	Led0_on
    	PAUSE 1000
    	Led0_off
    	PAUSE 500
    	Led1_on
    	PAUSE 1000
    	Led1_off
    	PAUSE 500
    	Led2_on
    	PAUSE 1000
    	Led2_off
    	PAUSE 500
    	Led3_on
    	PAUSE 1000
    	Led3_off
    	PAUSE 500
    	Led4_on
    	PAUSE 1000
    	Led4_off
    	PAUSE 500
    	Led5_on
    	PAUSE 1000
    	Led5_off
    
    END
    
    
    SUB Led0_on LMM
    	LOW BLU_LED8    ' P8
    	HIGH BLU_LED7   ' P7
    	INPUT BLU_LED6  ' P6
    ENDSUB
    
    SUB Led0_off LMM
    	REVERSE BLU_LED8   ' P8	
    ENDSUB
    
    SUB Led1_on LMM
    	HIGH BLU_LED8
    	INPUT BLU_LED7
    	LOW BLU_LED6
    ENDSUB
    
    SUB Led1_off LMM
    	REVERSE BLU_LED8
    ENDSUB
    
    SUB Led2_on LMM
    	LOW BLU_LED8
    	INPUT BLU_LED7
    	HIGH BLU_LED6
    ENDSUB
    
    SUB Led2_off LMM
    	REVERSE BLU_LED6
    ENDSUB
    
    SUB Led3_on LMM
    	HIGH BLU_LED8
    	LOW BLU_LED7
    	INPUT BLU_LED6
    ENDSUB
    
    SUB Led3_off LMM
    	REVERSE BLU_LED7
    ENDSUB
    
    SUB Led4_on LMM
    	INPUT BLU_LED8
    	HIGH BLU_LED7
    	LOW BLU_LED6
    ENDSUB
    
    SUB Led4_off LMM
    	REVERSE BLU_LED7
    ENDSUB
    
    SUB Led5_on LMM
    	INPUT BLU_LED8
    	LOW BLU_LED7
    	HIGH BLU_LED6
    ENDSUB
    
    SUB Led5_off LMM
    	REVERSE BLU_LED6
    ENDSUB
    
    
  • jmgjmg Posts: 15,144
    Bean wrote: »
    IMO openspin needs to support the @@@ operator.
    It's kind of silly to not have a way to get the absolute address of a label.

    Yes. Does not sound like a hard feature to add to OpenSpin ?

  • Here is my interpretation for working the RED, GREEN, and BLUE RGBs, on the Badge. This seems pretty straight forward, BUT how do you implement the rest of the colors within the context of PropBasic?

    I am not sure what PropBasic command I would use to get, for instance, a yellow RGB, to show up. It seems the charlieplexing the RGBs for the other colors, needs a fourth state, which I do not understand. Any ideas out there?

    Ray
    'charlieRGB.pbas
    ' Jan 26, 2016
    '
    ' Used to work the Hackable Badge RGBs
    
    DEVICE P8X32A, XTAL1, PLL16X
    FREQ 80_000_000
    
    RGB_LED3 PIN 3 OUTPUT    ' Badge
    RGB_LED2 PIN 2 OUTPUT    ' Badge
    RGB_LED1 PIN 1 OUTPUT    ' Badge
    
    RgbL_on SUB   ' Left RED
    RgbL_off SUB
    RgbR_on SUB   ' Right RED
    RgbR_off SUB
    GgbL_on SUB   ' Left GREEN
    GgbL_off SUB
    GgbR_on SUB   ' Right GREEN
    GgbR_off SUB
    BgbL_on SUB   ' Left Blue
    BgbL_off SUB
    BgbR_on SUB   ' Right Blue
    BgbR_off SUB 
    
    
    PROGRAM Start
    
    Start:
    	RgbL_on
    	PAUSE 1000
    	RgbL_off
    	PAUSE 500
    	RgbR_on
    	PAUSE 1000
    	RgbR_off
    	PAUSE 500
    	GgbL_on
    	PAUSE 1000
    	GgbL_off
    	PAUSE 500
    	GgbR_on
    	PAUSE 1000
    	GgbR_off
    	PAUSE 500
    	BgbL_on
    	PAUSE 1000
    	BgbL_off
    	PAUSE 500
    	BgbR_on
    	PAUSE 1000
    	BgbR_off
    
    END
    
    ' Badge RGB Left RED
    SUB RgbL_on
    	HIGH RGB_LED3
    	LOW RGB_LED2
    	INPUT RGB_LED1
    ENDSUB
    
    ' Badge RGB Left RED
    SUB RgbL_off
    	REVERSE RGB_LED3
    ENDSUB
    
    ' Badge RGB Right RED
    SUB RgbR_on
    	LOW RGB_LED3
    	HIGH RGB_LED2
    	INPUT RGB_LED1
    ENDSUB
    
    ' Badge RGB Right RED
    SUB RgbR_off
    	REVERSE RGB_LED3
    ENDSUB
    
    SUB GgbL_on   ' Left GREEN
    	INPUT RGB_LED3
    	LOW RGB_LED2
    	HIGH RGB_LED1
    ENDSUB
    
    SUB GgbL_off SUB
    	REVERSE RGB_LED2
    ENDSUB
    
    SUB GgbR_on   ' Right GREEN
    	INPUT RGB_LED3
    	HIGH RGB_LED2
    	LOW RGB_LED1
    ENDSUB
    
    SUB GgbR_off
    	REVERSE RGB_LED2
    ENDSUB
    
    SUB BgbL_on   ' Left Blue
    	LOW RGB_LED3
    	INPUT RGB_LED2
    	HIGH RGB_LED1
    ENDSUB
    
    SUB BgbL_off
    	REVERSE RGB_LED3
    ENDSUB
    
    SUB BgbR_on   ' Right Blue
    	HIGH RGB_LED3
    	INPUT RGB_LED2
    	LOW RGB_LED1
    ENDSUB
    
    SUB BgbR_off
    	 REVERSE RGB_LED3
    ENDSUB
    
    
  • Yellow might be a challenge (given its primary-ness), but generally you just mix colors like you would paint. So light Red and Green at the same time to create something Brown-ish.

    Provided you have a loop flashing both colors on and off fast enough (I'd aim faster than 50-60Hz), your eye should see the colors as mixed.
  • Below is my PropBasic program for turning on LED(P25) when the Badge is turned on. Now all I need is the Voltage displayed on the bottom line.

    When I created the SUBs I was keeping in mind the fact that I did not want to lock in the SUBs functionality to the Badge. Trying to make it as easy as possible to be able to apply it too some other charlieplexed scenario.

    I really took notice of how terse the latest documentation is, and I am also wondering if the docs are really describing the latest PropBasic release. I think that when some new people look at the PropBasic docs, they are wondering if they should really get involved with working with PropBasic, but that is just my opinion.

    Ray
    ' Base_badge.pbas
    ' Jan 27, 2016
    '
    ' Turn on P25 associated LED
    ' to give visual that the Badge is on.
    '
    ' Layout of Hackable Badge LEDs
    '
    '      led                       led
    '     5 |O| (P17)|   O   |(P27) |O| 0
    '     4 |O| (P16)|   L   |(P26) |O| 1
    '     3 |O| (P15)|   E   |(P25) |O| 2 
    '                |   D   |
    
    DEVICE P8X32A, XTAL1, PLL16X
    FREQ 80_000_000
    
    ' charlieplexed LEDs configuration 
    ' for the Parallax Hackable Badge
    CPin0 PIN 6 OUTPUT
    CPin1 PIN 7 OUTPUT
    CPin2 PIN 8 OUTPUT
    
    CPled SUB 2
    
    Pled0 SUB
    Pled1 SUB
    Pled2 SUB
    Pled3 SUB
    Pled4 SUB
    Pled5 SUB
    
    ''''''''''''''''''''
    PROGRAM Start
    ''''''''''''''''''''
    
    ' Start up code 
    Start:
    '       led,state = 0-on, 1-off
    	CPled 2,0    ' Turn on Blue LED 2 (P25)
    
    Main:
    
    
    END
    
    
    ' SUBs FUNCs TASKS
    '
    
    ''''''''''''''''''''
    ' CPled led, state
    ''''''''''''''''''''
    SUB CPled
    '	__param1 = led
    '	__param2 = state, 0 = on, 1 = off
    
    	IF __param2 = 1 THEN  ' state is off
    		INPUT CPin0  ' Turn off LED
    		INPUT CPin1
    		INPUT CPin2
    		GOTO Stop
    	ELSEIF __param1 = 0 THEN
    		Pled0
    	ELSEIF __param1 = 1 THEN
    		Pled1
    	ELSEIF __param1 = 2 THEN
    		Pled2
    	ELSEIF __param1 = 3 THEN
    		Pled3
    	ELSEIF __param1 = 4 THEN
    		Pled4
    	ELSEIF __param1 = 5 THEN
    		Pled5
    	ENDIF
    	Stop:
    ENDSUB
    
    SUB Pled0
    	INPUT CPin0  'Pin 6
    	HIGH CPin1   'Pin 7
    	LOW CPin2    'Pin 8
    ENDSUB
    
    SUB Pled1
    	LOW CPin0
    	INPUT CPin1
    	HIGH CPin2
    ENDSUB
    
    SUB Pled2
    	HIGH CPin0
    	INPUT CPin1
    	LOW CPin2
    ENDSUB
    
    SUB Pled3
    	INPUT CPin0
    	LOW CPin1
    	HIGH CPin2
    ENDSUB
    
    SUB Pled4
    	LOW CPin0
    	HIGH CPin1
    	INPUT CPin2
    ENDSUB
    
    SUB Pled5
    	HIGH CPin0
    	LOW CPin1
    	INPUT CPin2
    ENDSUB
    
    
  • This is very interesting, the below program, PropBasic compiles with no errors, but bstc comes up with a bunch of errors. I guess maybe Bean will have to look at it to see what is going on.

    I also ran it with Propeller IDE which also comes up with errors, since I do not really know PASM at all, somebody proficient in that area will have to make some comments.

    I tried to attach some file(s), not sure what is there.

    Ray


    ' Base_badge.pbas
    ' Jan 27, 2016
    '
    ' Turn on P25 associated LED
    ' to give visual that the Badge is on.
    '
    ' Layout of Hackable Badge LEDs
    '
    '      led                       led
    '     5 |O| (P17)|   O   |(P27) |O| 0
    '     4 |O| (P16)|   L   |(P26) |O| 1
    '     3 |O| (P15)|   E   |(P25) |O| 2 
    '                |   D   |
    
    DEVICE P8X32A, XTAL1, PLL16X
    FREQ 80_000_000
    
    ' charlieplexed LEDs configuration 
    ' for the Parallax Hackable Badge
    CPin0 PIN 6 OUTPUT
    CPin1 PIN 7 OUTPUT
    CPin2 PIN 8 OUTPUT
    
    ' charlieplexed RGB configuration
    ' for the Parallax Hackable Badge
    CPrgb0 PIN 1 OUTPUT
    CPrgb1 PIN 2 OUTPUT
    CPrgb2 PIN 3 OUTPUT
    
    ' charlieplex LED library
    LOAD "/home/ray/propbasic/CPled_lib.pbas"
    ' charlieplex RGB library
    LOAD "/home/ray/propbasic/CPrgb_lib.pbas"
    
    ''''''''''''''''''''
    PROGRAM Start
    ''''''''''''''''''''
    
    ' Start up code 
    Start:
    '       led,state = 0-on, 1-off
    	CPled 2,0    ' Turn on Blue LED 2 (P25)
    '         loc,col,state  loc = R or L, col = color, R,G,B, state =0 or 1	
    	CPrgb 0,  0,  0
    
    Main:
    
    
    END
    
    
    ' SUBs FUNCs TASKS
    '
    

  • A smaller program to isolate a problem, I think. The program below compiles without errors when run through PropBasic, but bstc shows an error.

    The culprit, I use Stop: in the SUBs, I guess PropBasic says it's OK, but bstc thinks otherwise. I am not sure what the work around is, use Stop1:, Stop2:, and so on?

    Ray
    ' test_subs.pbas
    ' Jan 28,2016
    '
    '
    DEVICE P8X32A, XTAL1, PLL16X
    FREQ 80_000_000
    
    Cled16 PIN 16 OUTPUT
    Cled17 PIN 17 OUTPUT
    Cled18 PIN 18 OUTPUT
    
    CledOff SUB
    
    CledCtrl SUB 3
    CledC1 SUB 2
    
    PROGRAM Start
    
    
    Start:
    '          led,on/off
    	CledCtrl 0,0,1
    	CledC1 0,0
    	
    
    END
    
    
    ' SUBs FUNCs TASKS
    '
    SUB CledCtrl
    	if __param2 = 1 Then
    		low Cled16
    		goto Stop
    	elseif __param1 = 0 Then  ' High
    		high Cled16
    		if __param3 = 1 then
    			pause 3000
    			low Cled16
    		endif
    	endif
    	Stop:
    ENDSUB
    
    SUB CledC1
    	If __param1 = 1 Then
    		Low Cled18
    		Goto Stop
    	ElseIf __param2 = 0 Then
    		High Cled18
    		pause 3000
    		Low Cled18
    	EndIf
    	Stop:
    ENDSUB
    
    SUB CledOff
    	low Cled16
    	low Cled17
    	low Cled18
    ENDSUB
    
    
  • BeanBean Posts: 8,129
    You cannot use the same label name in two places within one task.
    The main code and all of it's SUBs and FUNCs are one task.

    Bean
  • Thanks Bean, just to get this straight, the concept of global and local does not apply here, or is that just for labels when you use the GoTo? If their is such a thing as globals and locals concept, in PropBasic, maybe a deeper explanation would be nice.

    While were on the subject of PropBasic details, I was trying to use the branch command within an if statement, and the compiler kept coming up with an error, not enough variables. In fact I had setup the branch just like what you show in the docs. The reason I ask is because I wanted to set up something like a switch command.

    Ray
  • BeanBean Posts: 8,129
    edited 2016-01-28 17:52
    Everything is global per task. Again the main code and all of it's SUBs and FUNCs are one task.

    Defined TASKs can have SUB and FUNCs too. But they need to be fully declared within the TASK..ENDTASK body.

    Can you submit a small program that uses BRANCH in an IF that shows the problem. To be honest I've not used BRANCH hardly ever.

    P.S. Of course HUB variables are global for all tasks.

    Bean
  • tritoniumtritonium Posts: 540
    edited 2016-01-28 18:55
    Hi


    Edit oops made a mistake- was going to suggest using the EXIT command (rather then GOTO) but it seems that does not work in 'IF' commands ...
    EXIT

    Ends the current DO...LOOP or FOR...NEXT loop.
    EXIT
    IF var cond value THEN EXIT

    Edit again
    It seems to me the goto and exit are uneccesary anyway in this case

    Dave
  • I just started to write a rebuttal for the existence of a NEXT for the IF loop, when I noticed there was a revision in the post, disclaiming that feature. For a minute I thought I was loosing more memory cells.

    Well that makes life a little harder, now if I have to keep control of multiple same labels, how many variations on the word stop are their, amongst the SUBs, and with in TASKS.

    Ray

  • I added the Bled SUB, and I get an error, maybe I am using the branch command incorrectly.

    Ray
    ' test_subs.pbas
    ' Jan 28,2016
    '
    '
    DEVICE P8X32A, XTAL1, PLL16X
    FREQ 80_000_000
    
    Cled16 PIN 16 OUTPUT
    Cled17 PIN 17 OUTPUT
    Cled18 PIN 18 OUTPUT
    
    CledOff SUB
    CledOn SUB
    
    CledCtrl SUB 3
    CledC1 SUB 2
    Bled1 SUB 1
    
    PROGRAM Start
    
    
    Start:
    '          led,on/off
    	CledCtrl 0,0,1
    	CledC1 0,0
    	Pause 2000
    	CledOff
    	
    	
    
    END
    
    
    ' SUBs FUNCs TASKS
    '
    SUB Bled1
    	If __param1 = 0 Then
    		branch __param1, CledOn
    	EndIf
    ENDSUB
    
    SUB CledCtrl
    	if __param2 = 1 Then
    		low Cled16
    		goto Stop
    	elseif __param1 = 0 Then  ' High
    		high Cled16
    		if __param3 = 1 then
    			pause 3000
    			low Cled16
    		endif
    	endif
    	Stop:
    ENDSUB
    
    SUB CledC1
    	If __param1 = 1 Then
    		Low Cled18
    		Goto Stop1
    	ElseIf __param2 = 0 Then
    		High Cled18
    		pause 3000
    		Low Cled18
    	EndIf
    	Stop1:
    ENDSUB
    
    SUB CledOn
    	high Cled17
    ENDSUB
    
    SUB CledOff
    	low Cled16
    	low Cled17
    	low Cled18
    ENDSUB
    
    
    36 SUB Bled1
    37 If __param1 = 0 Then
    38 branch __param1, CledOn
    ERROR 7 INVALID NUMBER OF PARAMETERS ; branch __param1, CledOn
    39 EndIf
    40 ENDSUB
  • I've not used branch, but the problem may be that it expects a label, not a subroutine. But what's the point of the branch statement anyway? Why not just
    if __param1 = 0 then 
       CledOn
    endif
    

    That is, if the test is true, call the sub. You've already tested the variable, so any test by branch is redundant.

    I don't know if branch will allow the use of a subroutine, I would think if you're selecting between subs the better choice would be On.... GOSUB. But when you've already tested, even that is redundant.

    -Bob
  • Originally I had all the SUBs and related items, in a .pbas file and used the LOAD command to get them into the program. That effort led to a bunch of errors reported by bstc and Propeller IDE. Once I put all the SUBs back into the program, now it runs without errors. The LOAD command is not working as expected. Maybe there is a highly structured format that has to be used, a good example might be needed.

    In the docs "IF var cond value THEN label", this format did not work, the bstc compiler came up with an error, something along the lines of needs a unique name. I changed back to the format I have below, and now it works without any errors. Again some detailed examples might be in order.

    Ray
    ' Base_badge.pbas
    ' Jan 27, 2016
    '
    ' Turn on P25 associated LED
    ' to give visual that the Badge is on.
    '
    ' Layout of Hackable Badge LEDs
    '
    '      led                       led
    '     5 |O| (P17)|   O   |(P27) |O| 0
    '     4 |O| (P16)|   L   |(P26) |O| 1
    '     3 |O| (P15)|   E   |(P25) |O| 2 
    '                |   D   |
    
    DEVICE P8X32A, XTAL1, PLL16X
    FREQ 80_000_000
    
    ' charlieplexed LEDs configuration 
    ' for the Parallax Hackable Badge
    CPin0 PIN 6 OUTPUT
    CPin1 PIN 7 OUTPUT
    CPin2 PIN 8 OUTPUT
    
    CPled SUB 2
    Pled0 SUB
    Pled1 SUB
    Pled2 SUB
    Pled3 SUB
    Pled4 SUB
    Pled5 SUB
    ' charlieplex LED library
    'LOAD "/home/ray/propbasic/CPled_lib.pbas"
    
    
    ''''''''''''''''''''
    PROGRAM Start
    ''''''''''''''''''''
    
    ' Start up code 
    Start:
    '       led,state = 0-on, 1-off
    	CPled 2,0    ' Turn on Blue LED 2 (P25)
    
    
    Main:
    
    
    END
    
    
    ' SUBs FUNCs TASKS
    '
    ''''''''''''''''''''
    ' Usage CPled led, state
    ' led = 0 - 5
    ' state = 0-on, 1-off
    ''''''''''''''''''''
    SUB CPled
    '	__param1 = led
    '	__param2 = state, 0 = on, 1 = off
    
    	IF __param2 = 1 THEN  ' state is off
    		INPUT CPin0  ' Turn off LED
    		INPUT CPin1
    		INPUT CPin2
    		GOTO CPledStop
    	ELSEIF __param1 = 0 THEN 
    		Pled0
    	ELSEIF __param1 = 1 THEN
    		Pled1
    	ELSEIF __param1 = 2 THEN
    		Pled2
    	ELSEIF __param1 = 3 THEN
    		Pled3
    	ELSEIF __param1 = 4 THEN
    		Pled4
    	ELSEIF __param1 = 5 THEN
    		Pled5
    	ENDIF
    	CPledStop:
    ENDSUB
    
    SUB Pled0
    	INPUT CPin0  'Pin 6
    	HIGH CPin1   'Pin 7
    	LOW CPin2    'Pin 8
    ENDSUB
    
    SUB Pled1
    	LOW CPin0
    	INPUT CPin1
    	HIGH CPin2
    ENDSUB
    
    SUB Pled2
    	HIGH CPin0
    	INPUT CPin1
    	LOW CPin2
    ENDSUB
    
    SUB Pled3
    	INPUT CPin0
    	LOW CPin1
    	HIGH CPin2
    ENDSUB
    
    SUB Pled4
    	LOW CPin0
    	HIGH CPin1
    	INPUT CPin2
    ENDSUB
    
    SUB Pled5
    	HIGH CPin0
    	LOW CPin1
    	INPUT CPin2
    ENDSUB
    
    
  • Looking at one of your examples above, you have the snippet:
    IF __param2 = 1 THEN  ' state is off
    		INPUT CPin0  ' Turn off LED
    		INPUT CPin1
    		INPUT CPin2
    		GOTO Stop
    	ELSEIF __param1 = 0 THEN
    		Pled0
    	ELSEIF __param1 = 1 THEN
    		Pled1
    	ELSEIF __param1 = 2 THEN
    		Pled2
    	ELSEIF __param1 = 3 THEN
    		Pled3
    	ELSEIF __param1 = 4 THEN
    		Pled4
    	ELSEIF __param1 = 5 THEN
    		Pled5
    	ENDIF
    

    Since that might be a place for something like a switch statement, based on my reading of the documentation, I think you could use:
    IF __param2 = 1 THEN  ' state is off
    		INPUT CPin0  ' Turn off LED
    		INPUT CPin1
    		INPUT CPin2
    		GOTO Stop
            ELSE 
                    ON __param1 GOSUB Pled0, Pled1, Pled2, Pled3, Pled4, Pled5
    	ENDIF
    
Sign In or Register to comment.