Shop OBEX P1 Docs P2 Docs Learn Events
Need help with switch logic code — Parallax Forums

Need help with switch logic code

Don MDon M Posts: 1,653
edited 2011-11-08 15:43 in Propeller 1
Here is my code just for this discussions sake.
OBJ
  encdr      : "encoder"
  oled        : "oleddriver"
  
PUB main

   repeat

      case encdr.read 
        1 :
          oled.moveto(1, 4)
          oled.str(string("Routine 1           "))
          if encdr.ispushed == 1
            routine1
        2 :
          oled.moveto(1, 4)
          oled.str(string("Routine 2           "))
          if encdr.ispushed == 1
            routine2


pri routine1

  oled.moveto(1, 2)
  oled.str(string ("Routine 1           "))
  oled.moveto(1, 3)
  oled.str(string ("Select option....   "))

    repeat

      case encdr.read 
        1 :
          oled.moveto(1, 4)
          oled.str(string("Option 1          "))
          if encdr.ispushed == 1
            oled.moveto(1, 4)
            oled.str(string("Option 1 done..."))
            pause(1000)
        2 :
          oled.moveto(1, 4)
          oled.str(string("Exit to Main Menu   "))
          if encdr.ispushed == 1
            oled.moveto(1, 2)
            oled.str(string ("Main Menu           "))
            oled.moveto(1, 3)
            oled.str(string ("Select Routine....   "))
            return  

pri routine2  

  oled.moveto(1, 2)
  oled.str(string ("Routine 2           "))
  oled.moveto(1, 3)
  oled.str(string ("Select option....   "))

    repeat

      case encdr.read 
        1 :
          oled.moveto(1, 4)
          oled.str(string("Option 1         "))
          if encdr.ispushed == 1
            oled.moveto(1, 4)
            oled.str(string("Option 1 complete..."))
            pause(1000)
        2 :
          oled.moveto(1, 4)
          oled.str(string("Option 2         "))
          if encdr.ispushed == 1
            oled.moveto(1, 4)
            oled.str(string("Option 2 complete...      "))
            pause(1000)
        3 :
          oled.moveto(1, 4)
          oled.str(string("Option 3       "))
          if encdr.ispushed == 1
            oled.moveto(1, 4)
            oled.str(string("Option 3 complete...      "))
            pause(1000)
        4 :
          oled.moveto(1, 4)
          oled.str(string("Option 4       "))
          if encdr.ispushed == 1
            oled.moveto(1, 4)
            oled.str(string("Option 4 complete...     "))
            pause(1000)            
        5 :
          oled.moveto(1, 4)
          oled.str(string("Exit to Main Menu   "))
          if encdr.ispushed == 1
            oled.moveto(1, 2)
            oled.str(string ("Main Menu           "))
            oled.moveto(1, 3)
            oled.str(string ("Select Routine....   "))
            return 

What I am trying to figure out is when the button is pushed (encdr.ispushed == 1) how do you make it so that the "1" that is set is not carried into the next routine? For example when it is in the Main loop and you rotate the encoder to "Routine 1" and then push the button it goes into routine1 and invokes"Option 1" right away and shows "Option 1 done".

Thanks. Don

Comments

  • Don MDon M Posts: 1,653
    edited 2011-11-08 15:43
    Figured it out with help from a friend... added a routine called "release"
    PUB main
    
       repeat
    
          case encdr.read 
            1 :
              oled.moveto(1, 4)
              oled.str(string("Routine 1           "))
              if encdr.ispushed == 1
                release
                routine1
            2 :
              oled.moveto(1, 4)
              oled.str(string("Routine 2           "))
              if encdr.ispushed == 1
                release
                routine2
    
    
    pri routine1
    
      oled.moveto(1, 2)
      oled.str(string ("Routine 1           "))
      oled.moveto(1, 3)
      oled.str(string ("Select option....   "))
    
        repeat
    
          case encdr.read 
            1 :
              oled.moveto(1, 4)
              oled.str(string("Option 1          "))
              if encdr.ispushed == 1
                oled.moveto(1, 4)
                oled.str(string("Option 1 done..."))
                pause(1000)
            2 :
              oled.moveto(1, 4)
              oled.str(string("Exit to Main Menu   "))
              if encdr.ispushed == 1
                oled.moveto(1, 2)
                oled.str(string ("Main Menu           "))
                oled.moveto(1, 3)
                oled.str(string ("Select Routine....   "))
                return  
    
    pri routine2  
    
      oled.moveto(1, 2)
      oled.str(string ("Routine 2           "))
      oled.moveto(1, 3)
      oled.str(string ("Select option....   "))
    
        repeat
    
          case encdr.read 
            1 :
              oled.moveto(1, 4)
              oled.str(string("Option 1         "))
              if encdr.ispushed == 1
                oled.moveto(1, 4)
                oled.str(string("Option 1 complete..."))
                pause(1000)
            2 :
              oled.moveto(1, 4)
              oled.str(string("Option 2         "))
              if encdr.ispushed == 1
                oled.moveto(1, 4)
                oled.str(string("Option 2 complete...      "))
                pause(1000)
            3 :
              oled.moveto(1, 4)
              oled.str(string("Option 3       "))
              if encdr.ispushed == 1
                oled.moveto(1, 4)
                oled.str(string("Option 3 complete...      "))
                pause(1000)
            4 :
              oled.moveto(1, 4)
              oled.str(string("Option 4       "))
              if encdr.ispushed == 1
                oled.moveto(1, 4)
                oled.str(string("Option 4 complete...     "))
                pause(1000)            
            5 :
              oled.moveto(1, 4)
              oled.str(string("Exit to Main Menu   "))
              if encdr.ispushed == 1
                oled.moveto(1, 2)
                oled.str(string ("Main Menu           "))
                oled.moveto(1, 3)
                oled.str(string ("Select Routine....   "))
                return    
        
    
    pub  release   'wait for button release
    
      repeat until encdr.ispushed == 0
    
Sign In or Register to comment.