import time

from pigredients.ics import ic74hc595 as ic74hc595

HIGH = ic74hc595.HIGH
LOW = ic74hc595.LOW

number_of_registers = 2

if __name__ == '__main__':

    my_register = ic74hc595.Shift_Register(registers_in_chain=number_of_registers)
    
    my_register.set_off()
    my_register.set_pin(pin_id=0, state=HIGH)
    my_register.write()
    time.sleep(0.5)
    my_register.set_off()
    my_register.set_pin(pin_id=1, state=HIGH)
    my_register.write()
    time.sleep(0.5)
    my_register.set_off()
    my_register.set_pin(pin_id=2, state=HIGH)
    my_register.write()
    time.sleep(0.5)
    my_register.set_off()
    my_register.set_pin(pin_id=3, state=HIGH)
    my_register.write()
    time.sleep(0.5)
    my_register.set_off()
    my_register.set_pin(pin_id=4, state=HIGH)
    my_register.write()
    time.sleep(0.5)
    my_register.set_off()
    my_register.set_pin(pin_id=5, state=HIGH)
    my_register.write()
    time.sleep(0.5)
    my_register.set_off()
    my_register.set_pin(pin_id=6, state=HIGH)
    my_register.write()
    time.sleep(0.5)
    my_register.set_off()
    my_register.set_pin(pin_id=7, state=HIGH)
    my_register.write()
    time.sleep(0.5)
    my_register.set_off()
    my_register.set_pin(pin_id=8, state=HIGH)
    my_register.write()
    time.sleep(0.5)
    my_register.set_off()
    my_register.set_pin(pin_id=9, state=HIGH)
    my_register.write()
    time.sleep(0.5)
    my_register.set_off()
    my_register.set_pin(pin_id=10, state=HIGH)
    my_register.write()
    time.sleep(0.5)
    my_register.set_off()
    my_register.set_pin(pin_id=11, state=HIGH)
    my_register.write()
    time.sleep(0.5)
    my_register.set_off()
    my_register.set_pin(pin_id=12, state=HIGH)
    my_register.write()
    time.sleep(0.5)
    my_register.set_off()
    my_register.set_pin(pin_id=13, state=HIGH)
    my_register.write()
    time.sleep(0.5)
    my_register.set_off()
    my_register.set_pin(pin_id=14, state=HIGH)
    my_register.write()
    time.sleep(0.5)
    my_register.set_off()
    my_register.set_pin(pin_id=15, state=HIGH)
    my_register.write()
    time.sleep(0.5)
    my_register.set_off()
    my_register.write()
    time.sleep(1)
    
    my_register.name_pin(pin_id=0, pin_name="Bob")
    my_register.set_pin(pin_id="Bob", state=HIGH)
    my_register.write()
    time.sleep(1)
    my_register.set_pin(pin_id="Bob", state=LOW)
    my_register.write()
    time.sleep(1)
    
    try:
        my_register.set_pin(pin_id="Berta", state=LOW)
    except Exception as e:
        print "Error : %s" % e
        
    my_register.all_off()
    time.sleep(0.5)
    my_register.all_on()
    time.sleep(0.5)
    my_register.all_off()
    time.sleep(0.5)
    my_register.all_on()
    time.sleep(0.5)
    my_register.all_off()
    time.sleep(0.5)
    my_register.all_on()
    time.sleep(0.5)
    my_register.all_off()
    time.sleep(0.5)
        
    my_register.binary_count()
    

