美文网首页
S、RotationSensor

S、RotationSensor

作者: JXeddy | 来源:发表于2020-02-07 20:58 被阅读0次
    import time
    import RPi.GPIO as GPIO
     
     
    GPIO.setmode(GPIO.BOARD)
     
    SIA = 3
    SIB= 5
    SW = 7
     
    GPIO.setup(SW,GPIO.IN)
    GPIO.setup(SIA,GPIO.IN)
    GPIO.setup(SIB,GPIO.IN)
    flag = 0
    resetflag = 0
    globalCount = 0
    while 1:
            lastSib = GPIO.input(SIB)
            while not GPIO.input(SW):
                    resetflag = 1
            while not GPIO.input(SIA):
                    currentSib = GPIO.input(SIB)
                    flag =1
            if resetflag:
                            globalCount = 0
                            resetflag = 0
                            print('Count reset')
                            continue
            if flag:
                    if lastSib == 0 and currentSib == 1:
                            print('right rotate')
                            globalCount += 1
                    if lastSib == 1 and currentSib ==0:
                            print('left rotate')
                            globalCount -=1
                    flag =0
                    print('current = %s' % globalCount)
    

    相关文章

      网友评论

          本文标题:S、RotationSensor

          本文链接:https://www.haomeiwen.com/subject/jhyvxhtx.html