Checking a bit sequence



  • I'm working with SX1509 peripheral.

    0_1538361114777_c3c8be39-bd5a-4b63-bcfc-81b4dddb5fc6-image.png

    Based on this value '00000000 00000110' from 0x18+0x19 I know that pin 01 and pin 02 caused an interrupt. Now I need to read IO state for pin 01 and pin 02.

    Below code works, but can you suggest improvements?

    def digitalReadFromInterrupt(self,interruptSource):
            readResults = []
            
            for i in range(15,0,-1):
                if interruptSource & (1<<i):
                    readResults.append([i,self.digitalRead(i)])
    
            return readResults
    

 

Pycom on Twitter