import Lib
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(17, GPIO.OUT)
GPIO.output(17, 1)

GPIO.setup(4, GPIO.IN)


try:
    SIG_prev = 0
    Lib.startup()
    while True:
        GPIO.output(Lib.DAC_nums, [0]*8)
        left = 0
        right = 255
        while right-left>1:
            curr_guess = left + (right-left)//2
            Lib.num2dac(curr_guess)
            time.sleep(0.01)
            if GPIO.input(4):
                left = curr_guess
            else:
                right = curr_guess
        SIG_new = curr_guess
        if abs(SIG_new - SIG_prev) > 2:
            SIG_prev = SIG_new
            level = SIG_new // (255//8)
            LEDs = [1]*level + [0]*(8-level)  #Norming on LED_nums order
            GPIO.output(Lib.LED_nums, LEDs)
except KeyboardInterrupt:
    GPIO.output(17, 0)
    Lib.shutdown()
    GPIO.cleanup()
finally:
    GPIO.output(17, 0)
    Lib.shutdown()
    GPIO.cleanup()
da5e30d580de227e53106bf702c1ede93d011717
<mask token>

<mask token>
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
GPIO.output(17, 1)
GPIO.setup(4, GPIO.IN)
try:
    SIG_prev = 0
    Lib.startup()
    while True:
        GPIO.output(Lib.DAC_nums, [0] * 8)
        left = 0
        right = 255
        while right - left > 1:
            curr_guess = left + (right - left) // 2
            Lib.num2dac(curr_guess)
            time.sleep(0.01)
            if GPIO.input(4):
                left = curr_guess
            else:
                right = curr_guess
        SIG_new = curr_guess
        if abs(SIG_new - SIG_prev) > 2:
            SIG_prev = SIG_new
            level = SIG_new // (255 // 8)
            LEDs = [1] * level + [0] * (8 - level)
            GPIO.output(Lib.LED_nums, LEDs)
except KeyboardInterrupt:
    GPIO.output(17, 0)
    Lib.shutdown()
    GPIO.cleanup()
finally:
    GPIO.output(17, 0)
    Lib.shutdown()
    GPIO.cleanup()

import Lib
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
GPIO.output(17, 1)
GPIO.setup(4, GPIO.IN)
try:
    SIG_prev = 0
    Lib.startup()
    while True:
        GPIO.output(Lib.DAC_nums, [0] * 8)
        left = 0
        right = 255
        while right - left > 1:
            curr_guess = left + (right - left) // 2
            Lib.num2dac(curr_guess)
            time.sleep(0.01)
            if GPIO.input(4):
                left = curr_guess
            else:
                right = curr_guess
        SIG_new = curr_guess
        if abs(SIG_new - SIG_prev) > 2:
            SIG_prev = SIG_new
            level = SIG_new // (255 // 8)
            LEDs = [1] * level + [0] * (8 - level)
            GPIO.output(Lib.LED_nums, LEDs)
except KeyboardInterrupt:
    GPIO.output(17, 0)
    Lib.shutdown()
    GPIO.cleanup()
finally:
    GPIO.output(17, 0)
    Lib.shutdown()
    GPIO.cleanup()

import Lib
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(17, GPIO.OUT)
GPIO.output(17, 1)

GPIO.setup(4, GPIO.IN)


try:
    SIG_prev = 0
    Lib.startup()
    while True:
        GPIO.output(Lib.DAC_nums, [0]*8)
        left = 0
        right = 255
        while right-left>1:
            curr_guess = left + (right-left)//2
            Lib.num2dac(curr_guess)
            time.sleep(0.01)
            if GPIO.input(4):
                left = curr_guess
            else:
                right = curr_guess
        SIG_new = curr_guess
        if abs(SIG_new - SIG_prev) > 2:
            SIG_prev = SIG_new
            level = SIG_new // (255//8)
            LEDs = [1]*level + [0]*(8-level)  #Norming on LED_nums order
            GPIO.output(Lib.LED_nums, LEDs)
except KeyboardInterrupt:
    GPIO.output(17, 0)
    Lib.shutdown()
    GPIO.cleanup()
finally:
    GPIO.output(17, 0)
    Lib.shutdown()
    GPIO.cleanup()