Jump to content

IO4 Interrupt interpretationshilfe bitte


Recommended Posts

Posted

Hallo

Ich möchte meine Lichtschranken über das IO4 auslesen, was im BrickViewer auch einwandfrei funktioniert. Mit dem Beispielcode bekomme ich auch die entsprechenden Ergebnisse, weiß aber nicht, wie ich sie dem Zustand oder dem richtigen Pin zuordnen soll. Kann mir das vielleicht jemand erklären?

Danke schon mal

 

The values are a bit mask that specifies which interrupts occurred and the current value bit mask of the port.

 

For example:

 

        (1, 1) means that an interrupt on pin 0 occurred and currently pin 0 is high and pins 1-3 are low.

        (9, 14) means that an interrupt on pins 0 and 3 occured and currently pin 0 is low and pins 1-3 are high.

 

 

Ergebnis vom Testlauf:

Interrupt by: 0b1
Value: 0b1110
Interrupt by: 0b1
Value: 0b1111
Interrupt by: 0b1
Value: 0b1110

Posted

Der Interrupt den du bei der IO4 bekommst besteht aus 2 Werten: Eine Bitmaske die angibt wer den Interrupt ausgelöst hat und eine Bitmaske die den momentanen Wert darstellt.

 

überprüfen kannst du die Werte folgendermaßen (ungetestet):

 

if bitmask & (1 << 0):
    print "pin 0 high"
else:
    print "pin 0 low"

if bitmask & (1 << 1):
    print "pin 1 high"
else:
    print "pin 1 low"

if bitmask & (1 << 2):
    print "pin 2 high"
else:
    print "pin 2 low"

if bitmask & (1 << 3):
    print "pin 3 high"
else:
    print "pin 3 low"

Posted

so weit so gut, vielen dank. ;D

 

Und schon kommt das zweite Problem. Mit :

io.set_interrupt(1 << 0)

setze ich den Interrupt für Pin 0 und das Kann ich auch durch 1 oder 3 für meine Lichtschranken ersetzen. Aber wie bekomme ich für alle drei Pinne einen Interrupt?

 

Okay, hab die Zeile jetzt durch:

io.set_interrupt(0b1111)

ersetzt...scheint so richtig zu sein, oder?  ;D

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...