Forum Update - Announcement about May 10th, 2018 update and your password.

UselessBox

13»

Comments

  • Mikeologist,
    Whatever your random number you can use modular division by 12 to get a value 0-11.
    That works well enough in some cases, is short on code and is quick.

    As long as it does not bother you that the result is no longer random. Even if the input really was random. There will be a bias in the output.

    That bias may or may not matter depending on your application and how you feel about throwing away precious randomness.
  • Heater. wrote: »
    Mikeologist,
    Whatever your random number you can use modular division by 12 to get a value 0-11.
    That works well enough in some cases, is short on code and is quick.

    As long as it does not bother you that the result is no longer random. Even if the input really was random. There will be a bias in the output.

    That bias may or may not matter depending on your application and how you feel about throwing away precious randomness.

    Agreed, risk sized to fit the useless box application. I should have mentioned that, though.

    Any com port in a storm.
    Floating point numbers will be our downfall; count on it.
    Imagine a world without hypothetical situations.
  • 72sonett72sonett Posts: 80
    edited February 4 Vote Up0Vote Down
    Use GOSUB ... RETURN instead of GOTO.
    Like this;
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    Btin            PIN     1                       ' button input pin
    action          VAR     Word                    ' a random number 0..65535
    bTNWRK          VAR     Byte                    ' workspace for BUTTON
    
    DEBUG CLS, "Press button to start"
    action = 32000                                  'init action seed
    DO
      DO
        RANDOM action                               ' randomize while waiting for button pressed
        BUTTON Btin,0,250,100,btnWrk,0,actions      ' on button press, then jump to actions
      LOOP
    
      actions:                                      ' action = 0..65535
    
      SELECT action DIG 15                          ' pick rightmost digit of 'action'  (0..9)
     ' SELECT action // 10                            ' or; action MOD 10 = 0..9
        CASE 0
          GOSUB action0
        CASE 2
          GOSUB action1
    
         ' ... other actions
    
        CASE 9
          GOSUB action9
    
        CASE ELSE
          GOSUB actionx
      ENDSELECT
    LOOP                                             ' forever
    END
    ' =========================
    action0:
      ' do something
    RETURN
    ' -------------------------
    action1:
      ' do something
    RETURN
    ' -------------------------
    ' ...
    ' -------------------------
    action9:
      ' do something
    RETURN
    ' -------------------------
    actionx:
      ' do something
    RETURN
    ' -------------------------
    ' =============================================================
    
    --
    MH
    BS2Sx
  • USB3.bs2 is my main program, all the rest are me trying to get things to work.

    I'm still working out my subroutines and then I will tackle the rest. My program is increasing in size and is becoming harder for me to manage. I was doing much better when I was writing code to do just ONE thing at a time, but now I'm struggling.
    72sonett:

    I will look into your suggestion if my idea doesn't pan out. You can look at my finished (partially finished) code USB3.bs2 to see where I'm trying to go.

    Right now I'm having an issue getting my EMIC2 to work within my program, It works fine otherwise.

    When my children were young I had ALL the patience in the world. Now my children are all grown and I think it's possible they took my patience with them when they left because I couldn't find any if my life depended on it, and then comes PBASIC, SPIN, BlocklyProp, and only GOD knows what language I'm going to attempt to learn in the distant future.
  • I was on a short hiatus, but now I have returned to finish this project. Sorry that this has taken as long as it has I should have been finished long ago.
  • ASKME wrote: »
    When my children were young I had ALL the patience in the world. Now my children are all grown and I think it's possible they took my patience with them when they left because I couldn't find any if my life depended on it, and then comes PBASIC, SPIN, BlocklyProp, and only GOD knows what language I'm going to attempt to learn in the distant future.

    There's a punch line in there somewhere about kids taking things.

    I forget which comedian said, "When I was sixteen, my father was the stupidest man on the planet, but he learned a whole lot every year after that."
    "When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you."

    - Pablo Picasso
  • Erco: Now that's funny......
  • 72sonett72sonett Posts: 80
    edited February 14 Vote Up0Vote Down
    ASKME wrote: »
    ... look at my finished (partially finished) code USB3.bs2 to see where I'm trying to go.

    First get some structure in the program and with the right syntax. Now you are using BS1 commands for a BS2 chip... that will not compile.

    --
    MH
    BS2Sx
  • 72Sonett:
    Please explain.
    On USB3.bs2 I'm getting an error EEPROM full, does this mean my program is too big?
    What commands am I using that are for BS1???
  • GenetixGenetix Posts: 1,250
    edited February 18 Vote Up0Vote Down
    ASKME,

    The BS2 only has 2K of EEPROM which gets eaten up quickly if you repeat the same code over and over again.
    All those servo movements should be in separate subroutines since they are the same. Same with the LEDs.

    Use DO...LOOP instead of Start and GOTO Start if you want an endless loop.
    Since you defined PIN variables for the I/O pins you should change all the pin numbers to their pin variable name. For example the LED on and off code.
    By the way I/O pins use a PIN variable type. CON was the old way of doing it.
    Constants should be mixed case, such as EmicBaud while variables should be lowercase, as in temp.

    SYMBOL is a BS1 command for assigning a variable, and B2 is one of the system variables of the BS1.
    Since foc goes from 1 to 12 it will fit into a BS2 NIB variable.
    foc VAR NIB ' A NIB variable holds a 4-bit value which can range from 0 to 15.
    

    Oh and speaking of the LEDs, there needs to be a PAUSE between the HIGH and LOW to make it blink, otherwise you won't see anything.
    And servos need 20 ms between pulses, not 2.

    Also, you only need 1 Initialization routine at the start of the program.
    If you need that call that code more than once then put it into a subroutine.
    Servo_Up:
      ' Move servo from 90 to 180 degrees
      FOR temp =  500 TO 1200     ' 1000 to 2400 us = 1 to 2.4 ms ---> 90 to 180
        PULSOUT Servo2_pin,temp
        PAUSE 20     ' Pause 20 ms between servo pulses
      NEXT
      RETURN     ' Return back to main program when done
    
    Other_Servo_Up:
      ' Move the other servo from about 120 to 180 degrees
      FOR temp =  800 TO 1200     ' 1600 to 2400 us = 1.6 to 2.4 ms ---> 120? to 180
        PULSOUT Servo_pin,temp
        PAUSE 20
      NEXT
      RETURN
    
    Other_Servo_Down:
      ' Move other servo from 180 to 90 degrees
      FOR temp =  1200 TO 500     ' 2400 to 1000 is = 2.4 to 1 ms ---> 180 to 90
        PULSOUT Servo2_pin,temp
        PAUSE 20
      NEXT
      RETURN
    
    Servo_Down:
      ' Move servo from 180 to about 120 degrees
      FOR temp =  1200 TO 800     ' 2400 to 1600 us = 2.4 to 1.6 ms ---> 180 to 120?
        PULSOUT Servo_pin,temp
        PAUSE 20
      NEXT
      RETURN
    
    You could add the servo position values to the constants so that you can tweak them.
    Servo1Start CON 500 ' 90 degrees
    Servo1Stop CON 1200 ' 180 degrees
    Servo2Start CON 800 ' 120 degrees
    Servo2End CON 1200 ' 180 degrees
    
  • Genetix wrote: »
    foc VAR BIT ' A BIT variable holds a 4-bit value which can range from 0 to 15.
    
    Genetix misspoke himself; of course he meant to say
    foc VAR NIB 'a NIB variable holds a 4-bit value which can range from 0 to 15
    

    Re-inventing the wheel is not a waste of time if, when you are done, you understand why it is round.
    Cool, CA, USA 95614
  • 72sonett72sonett Posts: 80
    edited February 15 Vote Up0Vote Down
    I rewrote your program;
    - retyped the pin variables from CON to PIN,
    - deleted the BS1 command (SYMBOL),
    - put the duplicate servo code in subroutines,
    - deleted most of the the LOW-HIGH command pairs as those do not have any effect,
    - used unique label names,
    - used declared pin name variables instead of absolute pin numbers.

    The code now compiles without errors but what it does is completely unclear to me... :-)
    (Use my earlier program snippet for the random number, and the SELECT .. CASE structure to execute tasks.)
    'File.......USB3.bs2 [Useless Senseless Box Version 4]
    'Purpose....UselessBox Demonstration
    'Author.....Paul Muzyka @ [ASKMEAKYZUM@Gmail.com]
    'Email......PMuzyka@Parallax.com
    'Updated....15 FEB 2018
    
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    
    'This program was written to control a Useless Box with two standard servo's, two LEDs, one vibration device, and one EMIC2.
    'This code will be WELL documented for any NEW Programers with little to NO experience.....
    'PLEASE READ ALL NOTES !!!!!!!
    '---------------------------[I/O PINS]------------------------------------------------------------------------
    'Under [I/O PINS] you can change the pin numbers to meet your needs.
    
    Servo1_pin PIN            12     'I/O Head/standard servo
    Servo2_pin PIN            13     'I/O foot/standard servo
    Buttn_pin  PIN            10     'I/O button/switch BLUE/begining of program when switch is pressed
    Move_pin   PIN            11     'I/O for vibrating device
    Lite1_pin  PIN            14     'I/O for LED to light up angry bird
    Lite2_pin  PIN            7      'I/O for LED to light up angry bird
    Ping_pin   PIN            15     'I/O for ping sensor
    Emictx_pin PIN            8      'I/O Tx for sending data to the EMIC2
    Emicrx_pin PIN            9      'I/O Rx for receiving data from the EMIC2
    
    '--------------------------[CONSTANTS]------------------------------------------------------------------
    
    t9600      CON            84      'EMIC2/???
    emicbaud   CON            t9600   'EMIC2/sets baud rate for EMIC2
    
    '-------------------------[VARIABLES]-------------------------------------------------------------
    
    Temp        VAR           Word     'Work space for FOR NEXT/SERVO_PIN/SERVO2_PIN/controls both servo's Work space for NEXT
    Btnspc      VAR           Byte     'work space for BUTTON command.
    '-------------------------[INI]----------------------------------------------------------------------
    start:
    
    LOW   buttn_pin                    'sends pin low for the BUTTON command to function correctly.
    INPUT buttn_pin                    'sets pin as an input for the BUTTON command.
    
    BUTTON buttn_pin, 1, 0, 0, Btnspc, 1, main '[Brnchcom] is a label where the program goes when switch is pressed/this will be where the
                                        ' REAL program code starts, ENJOY.
    
    '------------------[PROGRAM CODE]------------------------------------------------------
    main1:
     DEBUG "foc: ", B2, " "
     BRANCH B2, [Task_0, Task_1, Task_2, Task_3, Task_4, Task_5, Task_6, Task_7, Task_8, Task_9, Task_10, Task_11]  ' branch to task
     DEBUG "BRANCH target error..."        ' ... unless out of range
     DEBUG CR, CR
    
    Next_Task:
      B2 = B2 + 1 // 12                    ' force foc to be 0..11
      GOTO start
    ' --------------------------------------------------------------------
    Task_0: ' -----[ Program Code below ]-------[Head & foot up]----------------------------------------
    
      HIGH Lite1_pin
      HIGH Lite2_pin
      HIGH Move_pin
      '---------------------------------[ini]-------------------------------------------------
    init:
      DEBUG CLS, CR, CR
      DEBUG CR
      SEROUT emictx_pin, emicbaud, [CR]
      SERIN  emicrx_pin, emicbaud, 5000, no_response, [WAIT(":")]
      DEBUG CR
     '----------------------------------[program code]------------------------------------------------
    
      SEROUT emictx_pin, emicbaud, ["V", "18", CR]
      SEROUT emictx_pin, emicbaud, ["D", "1", CR]
      SERIN  emicrx_pin, emicbaud, [WAIT (":")]
    '________[Program Code below]___________________________[Head & foot down]_______________________________________
    
    LOW Move_pin
    LOW Lite2_pin
    LOW Lite1_pin
    
    GOSUB swipeleft
    GOSUB swiperight
    
    no_response:
      DEBUG "no response", CR, CR
      DEBUG "BRANCHed to Task_0", CR
      GOTO Next_Task
    
    Task_1:
    ' -----[ Program Code below ]-------[Head & foot up]---------------------------------------------
    
    start2:'GET RID OF THIS start WHEN ADDED TO PROGRAM !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      GOSUB swipeleft
      GOSUB swiperight
    
      HIGH Lite1_pin
      HIGH Lite2_pin
      HIGH Move_pin
      '---------------------------------[ini]-------------------------------------------------
    init2:
      DEBUG CLS, CR, CR
      DEBUG CR
      SEROUT emictx_pin, emicbaud, [CR]
      SERIN emicrx_pin, emicbaud, 5000, no_response, [WAIT(":")]
      DEBUG CR
    '----------------------------------[program code]------------------------------------------------
      SEROUT emictx_pin, emicbaud, ["V", "18", CR]
      SEROUT emictx_pin, emicbaud, ["N", "1", CR]
      SEROUT emictx_pin, emicbaud, ["S", "hello, Flap Jack.  thank you for comming, but please do not touch my switch", CR]
      SERIN  emicrx_pin, emicbaud, [WAIT (":")]
    
      SEROUT emictx_pin, emicbaud, ["N", "8", CR]
      SEROUT emictx_pin, emicbaud, ["S", "I hope you can tell by the sound of my voice I'm not kidding", CR]
      SERIN  emicrx_pin, emicbaud, [WAIT (":")]
    '________[Program Code below]___________________________[Head & foot down]_______________________________________
    
      LOW Move_pin
      LOW Lite2_pin
      LOW Lite1_pin
    
      GOSUB swipeleft
      GOSUB swiperight
    
    no_response2:
      DEBUG "no response", CR, CR
      DEBUG "BRANCHed to Task_1", CR
      GOTO Next_Task
    
    Task_2:
    '----------------------[PROGRAM]------------------------------------------------------
      GOSUB swipeleft
    
      HIGH Lite2_pin
      HIGH Lite1_pin
      PAUSE 1000
      LOW Lite2_pin
      LOW Lite1_pin
    
      GOSUB swiperight
    
      DEBUG "BRANCHed to Task_2", CR
      GOTO Next_Task
    
    Task_3:
    
    '----------------------------------[program code]------------------------------------------------
    main:
      SEROUT Emictx_pin, emicbaud, ["S", "helllloooooooooo?, Do NOT touch this switch or else,", CR]
      SERIN Emicrx_pin, emicbaud, [WAIT(":")]
      SEROUT Emictx_pin, emicbaud, ["L2", "S", "mary had a little lamb made of cheese and roe.", CR]
      SERIN Emicrx_pin, emicbaud, [WAIT(":")]
    
      GOSUB swiperight
      GOSUB swipeleft
    
    no_response3:
      DEBUG "no response", CR, CR
      DEBUG "BRANCHed to Task_0", CR
      GOTO Next_Task
    ' ---------------------------
    Task_4:
      SEROUT Emictx_pin, emicbaud, ["S", "hellllo   YYY,", CR]
      SERIN  Emicrx_pin, emicbaud, [WAIT(":")]
      SEROUT Emictx_pin, emicbaud, ["L2", "S", "mary .....", CR]
      SERIN  Emicrx_pin, emicbaud, [WAIT(":")]
    
      GOSUB swiperight
      PAUSE 6000             ' do nothing for 6 sec
      GOSUB swipeleft
    
      HIGH Lite2_pin         ' lights on
      HIGH Lite1_pin
      PAUSE 8000         ' do nothing for 8 sec
    
    no_response4:
      DEBUG "no response", CR, CR
      DEBUG "BRANCHed to Task_1", CR
      GOTO Next_Task
    ' --------------------------
    swipeleft:                ' swipe servo left
      FOR temp =  200 TO 1200
        PULSOUT Servo1_pin,temp
        PAUSE 50
      NEXT
    RETURN
    
    swiperight:               ' swipe servo right
       FOR temp =  1200 TO 200
        PULSOUT Servo1_pin,temp
        PAUSE 50
      NEXT
    RETURN
    ' ------------------------------
    Task_5:
    
      DEBUG "BRANCHed to Task_2", CR
      GOTO Next_Task:
    
    Task_6:
      DEBUG "BRANCHed to Task_1", CR
      GOTO Next_Task
    
    Task_7:
      DEBUG "BRANCHed to Task_2", CR
      GOTO Next_Task
    
    Task_8:
      DEBUG "BRANCHed to Task_0", CR
      GOTO Next_Task
    
    Task_9:
      DEBUG "BRANCHed to Task_1", CR
      GOTO Next_Task
    
    Task_10:
      DEBUG "BRANCHed to Task_2", CR
      GOTO Next_Task
    
    Task_11:
      DEBUG "BRANCHed to Task_0", CR
      GOTO Next_Task
    

    --
    MH
    BS2Sx
  • Forcing a variable (B2) rather than declaring it normally is a mistake.
    Re-inventing the wheel is not a waste of time if, when you are done, you understand why it is round.
    Cool, CA, USA 95614
  • 72sonett72sonett Posts: 80
    edited February 17 Vote Up0Vote Down
    Yes, among other flaws...
    OK, 2nd edit, rewrite the emic parts yourself and add other tasks as you please...
    'File.......USB3.bs2 [Useless Senseless Box Version 5]
    'Updated....15 FEB 2018
    
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    ' ------------------------------ [ declarations ] ------------------------------
    Servo1_pin PIN            12     'I/O Head/standard servo
    Servo2_pin PIN            13     'I/O foot/standard servo
    Buttn_pin  PIN            10     'I/O button/switch BLUE/begining of program when switch is pressed
    Move_pin   PIN            11     'I/O for vibrating device
    Lite1_pin  PIN            14     'I/O for LED to light up angry bird
    Lite2_pin  PIN            7      'I/O for LED to light up angry bird
    Ping_pin   PIN            15     'I/O for ping sensor
    Emictx_pin PIN            8      'I/O Tx for sending data to the EMIC2
    Emicrx_pin PIN            9      'I/O Rx for receiving data from the EMIC2
    
    t9600      CON            84     'EMIC2/???
    emicbaud   CON            t9600  'EMIC2/sets baud rate for EMIC2
    
    Temp       VAR            Word   'Work space for FOR NEXT/SERVO_PIN/SERVO2_PIN/controls both servo's Work space for NEXT
    Btnspc     VAR            Byte   'work space for BUTTON command.
    task       VAR            Word   'task based on a random number 0..65535
    
    '-------------------------------------------[INIT]------------------------------------------------------------------------------------------
    LOW   buttn_pin                  'sends pin low for the BUTTON command to function correctly.
    INPUT buttn_pin                  'sets pin as an input for the BUTTON command.
    task = 32000                     'init task seed
    
    '------------------------------------------[MAIN PROGRAM]----------------------------------------------------------------------------
    DO
      DEBUG CLS, "Press button to start"
      DO
        RANDOM task                   ' randomize a number 0..65353 while waiting for button pressed
        BUTTON buttn_pin,0,250,100,btnspc,0,selecttask    ' on button pressed jump to task
      LOOP
    
      selecttask:                     ' task = 0..65535
      SELECT task // 10              ' task MOD 10 = 0..9
        CASE 0                       ' Statement(s) to execute task 0
          DEBUG "BRANCHed to Task 0", CR
          HIGH Lite1_pin             ' turn led1 on
          HIGH Lite2_pin             ' turn led2 on
          HIGH Move_pin              ' vibrator on
          SEROUT emictx_pin, emicbaud, [CR]
          SERIN  emicrx_pin, emicbaud, 5000, no_response0, [WAIT(":")]
          SEROUT emictx_pin, emicbaud, ["V", "18", CR]
          SEROUT emictx_pin, emicbaud, ["D", "1", CR]
          SERIN  emicrx_pin, emicbaud, [WAIT (":")]
          no_response0:
    
        CASE 1                       ' Statement(s) to execute task 1
          DEBUG "BRANCHed to Task 1", CR
          ' more statements
    
        CASE 2
          DEBUG "BRANCHed to Task 2", CR
          GOSUB swipeleft            ' move servo 1 left
          HIGH Lite2_pin             ' lights on
          HIGH Lite1_pin
          PAUSE 1000                 ' wait 1 sec
          LOW Lite2_pin              ' lights off
          LOW Lite1_pin
          GOSUB swiperight           ' move servo 1 right
    
        CASE 3
          DEBUG "BRANCHed to Task 3", CR
          SEROUT Emictx_pin, emicbaud, ["S", "helllloooooooooo?, Do NOT touch this switch or else,", CR]
          SERIN  Emicrx_pin, emicbaud, [WAIT(":")]
          SEROUT Emictx_pin, emicbaud, ["L2", "S", "mary had a little lamb made of cheese and roe.", CR]
          SERIN  Emicrx_pin, emicbaud, [WAIT(":")]
    
          GOSUB swiperight            ' swipe servo 1 right
          GOSUB swipeleft             ' swipe servo 1 left
    
        CASE 4
          DEBUG "BRANCHed to Task 4", CR
          SEROUT Emictx_pin, emicbaud, ["S", "hellllo   YYY,", CR]
          SERIN  Emicrx_pin, emicbaud, [WAIT(":")]
          SEROUT Emictx_pin, emicbaud, ["L2", "S", "mary .....", CR]
          SERIN  Emicrx_pin, emicbaud, [WAIT(":")]
    
          GOSUB swiperight            ' swipe servo 1 right
          PAUSE 6000                  ' do nothing for 6 sec
          GOSUB swipeleft             ' swipe servo 1 left
    
          HIGH Lite2_pin              ' lights on
          HIGH Lite1_pin
          PAUSE 8000                  ' do nothing for 8 sec
    
        CASE 5
          DEBUG "BRANCHed to Task 5", CR
          LOW Move_pin                ' vibrator off
          LOW Lite2_pin               ' lights off
          LOW Lite1_pin
          GOSUB swipeup               ' move servo up
          GOSUB swipedown             ' move servo down
    
        CASE 6
          DEBUG "BRANCHed to Task 6", CR
          SEROUT emictx_pin, emicbaud, ["V", "18", CR]
          SEROUT emictx_pin, emicbaud, ["N", "1", CR]
          SEROUT emictx_pin, emicbaud, ["S", "hello, Flap Jack.  thank you for comming, but please do not touch my switch", CR]
          SERIN  emicrx_pin, emicbaud, [WAIT (":")]
    
          SEROUT emictx_pin, emicbaud, ["N", "8", CR]
          SEROUT emictx_pin, emicbaud, ["S", "I hope you can tell by the sound of my voice I'm not kidding", CR]
          SERIN  emicrx_pin, emicbaud, [WAIT (":")]
          LOW Move_pin
          LOW Lite2_pin
          LOW Lite1_pin
    
          GOSUB swipeup
          GOSUB swiperight
    
        CASE 7
          DEBUG "BRANCHed to Task 7", CR
          ' more statements
    
        CASE 8
          DEBUG "BRANCHed to Task 8", CR
          ' more statements
    
        CASE 9
          DEBUG "BRANCHed to Task 9", CR
          ' more statements
    
        CASE ELSE
          DEBUG "BRANCHed to unknown task...", CR
          ' Statement(s) to execute all other tasks
    
      ENDSELECT
    LOOP                               ' forever
    END
    ' ====================================== [ end main program ] ====================
    '----------------------------------------- [ Subroutines  ] ----------------------
    swipeleft:                   ' swipe servo 1 left
      FOR temp =  200 TO 1200    ' adjust values to each servo
        PULSOUT Servo1_pin,temp
        PAUSE 20
      NEXT
    RETURN
    ' -------------------------------------------------
    swiperight:               ' swipe servo 1 right
      FOR temp =  1200 TO 200
        PULSOUT Servo1_pin,temp
        PAUSE 20
      NEXT
    RETURN
    ' -------------------------------------------------
    swipeup:                  ' swipe servo 2 up
      FOR temp =  200 TO 1200
        PULSOUT Servo2_pin,temp
        PAUSE 20
      NEXT
    RETURN
    ' -------------------------------------------------
    swipedown:               ' swipe servo 2 down
      FOR temp =  1200 TO 200
        PULSOUT Servo2_pin,temp
        PAUSE 20
      NEXT
    RETURN
    ' =================================== [ program end ] ==============================
    


    I do not like how the BUTTON command jumps out of the loop, it is like a hidden GOTO. I prefer code like this:
    ...
      DO
        RANDOM task                  ' randomize a number 0..65535 while waiting for button pressed
      LOOP UNTIL (buttn_pin = 1)
    
      SELECT task // 10              ' task MOD 10 = 0..9
    ...
    
    --
    MH
    BS2Sx
  • Thanks for catching that goof-up, Tom.
  • Thanks to ALL for the help. I was able to compile my code but it definitely was not doing what I intended.
    I did finally see where I was using BS1 code, my mistake.
    I feel like I've spent so much time coding and I completely fouled it up.
    I recently had a life changing event (layed off) and am trying to recoup, but it shouldn't be too long before I'm back on my feet making more coding mistakes.
    Once again. Thank you for all of your help..

    Paul
  • I wanted to take a moment to thank all the people that were nice enough to share their knowledge openly, with no charge, and asking for nothing in return.

    To teach is a Noble profession and all of you if not teachers already should be.

    I have attempted to learn both PBasic and SPIN and for all the work I put into this project I failed miserably but throughout it all I learned more then I
    thought I would and owe allot to each and everyone of you for your assistance throughout this project. I also owe a tremendous amount to Parallax, Inc. and it's employees, including but not limited to Ken Gracey, Jeff Martin, Andy Lindsay, and Kenneth Glass.

    In closing I would like to add that as soon as I return from a well deserved vacation I will be completing my UseLess Box and placing it into a real box and post the results on YouTube.
  • Once again thank you to everyone for your help, but I seem to be having a problem with the code that was written recently by 72sonett.
    Unfortunately that code does not work at all as in my code was working, but it was not working as intended.

    I'm going to reinstall my code and see if it's still working and all the connections are working properly and then I'll reinstall the code that 72sonett wrote and try to figure out why it's not doing anything.

    Any help would be much appreciated.
  • UPDATE:
    My first assessment was wrong, I claimed that 76sonett's code did not work at all, but upon further inspection it's I who is not working. 5v supply was disconnected.

    76sonett:
    Your program is doing exactly the same as mine was doing it is just running through each different scenario one after the other regardless of whether the button is pushed or not. It's almost like the button command is not working, any suggestions?
  • Here's a guess...check your wiring on the button. His code checks to see if the button is pressed - if you have a short then it might see the button as being pressed all the time, so it would just keep looping.
    San Mateo, CA
  • 72sonett72sonett Posts: 80
    edited March 3 Vote Up0Vote Down
    How did you wire the button switch? With a pull up resistor switching to gnd or with a pull down resistor switching to V+ ?
    See schematic in BASIC Stamp Help on the BUTTON command.

    The first snippet assumes 'active low', switch to gnd (DownState parameter = 0):
    ...
    BUTTON buttn_pin,  0  ,250,100,btnspc,0,selecttask
    ...
    

    This assumes 'active high', switch to V+:
    ...
    LOOP UNTIL (buttn_pin = 1)
    ...
    
    --
    MH
    BS2Sx
  • ASKMEASKME Posts: 172
    edited March 4 Vote Up0Vote Down
    That's funny my first guess was the switch. I disconnected the switch and used a pull down resistor connected to ground through the I/O pin because I knew the program was looking for a low and when that didn't work I change the button command parameter so that the program would look for a high instead of a low. I'm positive it's something I'm doing wrong that's causing this problem so today I will look into it again and try to figure this one out, but thank you for all the help.
Sign In or Register to comment.