Shop OBEX P1 Docs P2 Docs Learn Events
Case Statement — Parallax Forums

Case Statement

MSDTechMSDTech Posts: 342
edited 2012-10-15 15:50 in Propeller 1
I am building a Haloween display that will be operated by a remote control. The problem is the case statement that is used to determine the action when a specific code is received from the remote. If the case statement is present, I get wildly varing reads of the remote, comment it out and everything works fine.
What is going on??

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2012-10-15 13:04
    I'm not familiar with the BS2-function-object. I prefer coding in real spin.

    You should archive your code. IN the main-menu of the propeller-tool is an option archive project.

    This will put all files needed to compile your code into a zip-archive.

    Without having the complete code I can only do a guessing.

    Did you try it with just one case-value active?
    Pub MonitorRemote  
      repeat
        GetMessage
         Case Message
            1  : Play_Corpse
            {
            52 : HeadRight
            53 : HeadLeft
            102: HeadCenter
            117: JawClose
            118: JawOpen
           }
         BS2.DEBUG_STR(string("Code Read: "))
         BS2.DEBUG_DEC(Message)
         BS2.Debug_Char(13)
         timing.pause(1000)
    

    adding the second case-value testing again?
    adding the third case-value testing again?

    you have to narrow down the problem. When does the problem exactly ocure?

    Your method Play_Corpse starts a new cog which object starts how many cogs?
    are you sure that you don't run out of cogs?

    can't check this because the other objects are not included in your attachement
    best regards
    Stefan
  • MSDTechMSDTech Posts: 342
    edited 2012-10-15 13:44
    I've tried combinations and it appears to lose sync with the remote on the headright call only. If I avoid that it works fine?
    I've attached the full archive.
  • StefanL38StefanL38 Posts: 2,292
    edited 2012-10-15 14:20
    Hi MSDTech,

    thanks for the full code.
    If I avoid that it works fine?
    you wrote it as a question.
    You are the one who can test it. I haven't a setup including a SD-card and your soundfiles.

    Try one case-value at a time all others commented out

    Then add one after the other. Exclude headright only - all others included.

    How fast is the repeat function of your remote control?

    best regards
    Stefan
  • MSDTechMSDTech Posts: 342
    edited 2012-10-15 15:11
    Got it working. Seems if I change the headright from servos.set(servohead,300) to servos.set(servohead,250) it works. A little confused as to why, but that was enough to allow it to continue to read the remote.
  • StefanL38StefanL38 Posts: 2,292
    edited 2012-10-15 15:50
    Hi,

    if it is working now this is just another hint that something strange is going on.

    the BS2-method PulseIn calls PULSIN_Clk uses several waitpne and waitpeq-commands. This means the cog is stopped COMPLETELY until the matching-condition is true.

    see note in the BS2_functions.spin-file
    Note: Absence of pulse can cause cog lockup if watchdog is not used - See distributed example

    So it might be that your code gets locked up first and then if the repeating function of the IR-remote starts the rest of the bits is filled up.
    And then you get strange readings.

    Did you check ALL combinations of IR-commands?
    best regards
    Stefan
Sign In or Register to comment.