Announcement

Collapse
No announcement yet.

How to use bus_SetChangeInterrupt for end switches detection

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use bus_SetChangeInterrupt for end switches detection

    Hi,

    I need to detect the change in PA4 and PA5 (configured as digital inputs). They are connected to two end switches. I need to execute some actions when each switch is pressed and some actions when it is released.
    I was thinking to use bus_SetChangeInterrupt, could you provide me some example? I am using Designer and Diablo.

    Thanks

  • #2
    Hi,

    This is the simplest example I can come up with. It is important to note that it is a one time event so it will need to be re-armed which happens at the end of the function in the example.
    Code:
    bus_SetChangeInterrupt(checkSwitches, M_PA4 | M_PA5);
    
    
    func checkSwitches()
    
      if(pin_Read(PA4) == 0)
        
        // Do something
    
      endif
    
      if(pin_Read(PA4) == 1)
    
        // Do something
    
      endif
    
      if(pin_Read(PA5) == 0)
    
        // Do something
    
      endif
    
      if(pin_Read(PA5) == 1)
    
        // Do something
    
      endif
    
      bus_SetChangeInterrupt(checkSwitches, M_PA4 | M_PA5);
    
    endfunc
    You can find more information on page 36 of this datasheet https://www.4dsystems.com.au/product...ions_R_2_0.pdf

    Best regards

    Paul

    Comment


    • rafa
      rafa commented
      Editing a comment
      Thanks,

      It is working perfect now.
Working...
X