from machine import Pin
import time
SD = Pin(0, Pin.OUT)
ST_CP = Pin(1, Pin.OUT)
SH_CP = Pin(2, Pin.OUT)
'''
#Test 01
SD.value(1)
time.sleep_ms(5)
SH_CP.low()
time.sleep_ms(5)
SH_CP.high()
time.sleep_ms(5)
ST_CP.low()
time.sleep_ms(5)
ST_CP.high()
'''
'''
#Test 02
SD.value(0)
time.sleep_ms(5)
SH_CP.low()
time.sleep_ms(5)
SH_CP.high()
time.sleep_ms(5)
ST_CP.low()
time.sleep_ms(5)
ST_CP.high()
'''
'''
#Test 03
for bit in range(8):
SD.value(1)
time.sleep_ms(5)
SH_CP.low()
time.sleep_ms(5)
SH_CP.high()
time.sleep_ms(5)
ST_CP.low()
time.sleep_ms(5)
ST_CP.high()
print("Bit latched...")
time.sleep_ms(500)
for bit in range(8):
SD.value(0)
time.sleep_ms(5)
SH_CP.low()
time.sleep_ms(5)
SH_CP.high()
time.sleep_ms(5)
ST_CP.low()
time.sleep_ms(5)
ST_CP.high()
print("Bit latched...")
time.sleep_ms(500)
'''
# Test 04 Setup MasterReset
MR = Pin(3, Pin.OUT)
MR.low()
SD.value(1)
time.sleep_ms(5)
SH_CP.low()
time.sleep_ms(5)
SH_CP.high()
time.sleep_ms(5)
ST_CP.low()
time.sleep_ms(5)
ST_CP.high()
print("master reset is active")
time.sleep(3)
MR.high()
SD.value(1)
time.sleep_ms(5)
SH_CP.low()
time.sleep_ms(5)
SH_CP.high()
time.sleep_ms(5)
ST_CP.low()
time.sleep_ms(5)
ST_CP.high()
print("master reset is disabled")
'''
Test #4.1
from machine import Pin
import time
SD = Pin(0, Pin.OUT)
ST_CP = Pin(1, Pin.OUT)
SH_CP = Pin(2, Pin.OUT)
MR = Pin(3, Pin.OUT)
MR.low()
time.sleep_ms(5)
MR.high()
ST_CP.low()
time.sleep_ms(5)
ST_CP.high()
time.sleep_ms(5)
'''
'''
#Test 05
from machine import Pin
import time
class ShiftRegisterController_74HC595:
SD = Pin(0, Pin.OUT)
ST_CP = Pin(1, Pin.OUT)
SH_CP = Pin(2, Pin.OUT)
MR = Pin(3, Pin.OUT)
MR.high()
def Run():
for bit in range(8):
ShiftRegisterController_74HC595.SD.value(1)
time.sleep_ms(5)
ShiftRegisterController_74HC595.SH_CP.low()
time.sleep_ms(5)
ShiftRegisterController_74HC595.SH_CP.high()
time.sleep_ms(5)
ShiftRegisterController_74HC595.ST_CP.low()
time.sleep_ms(5)
ShiftRegisterController_74HC595.ST_CP.high()
print("Bit latched...")
time.sleep_ms(500)
#END_FOR
for bit in range(8):
ShiftRegisterController_74HC595.SD.value(0)
time.sleep_ms(5)
ShiftRegisterController_74HC595.SH_CP.low()
time.sleep_ms(5)
ShiftRegisterController_74HC595.SH_CP.high()
time.sleep_ms(5)
ShiftRegisterController_74HC595.ST_CP.low()
time.sleep_ms(5)
ShiftRegisterController_74HC595.ST_CP.high()
print("Bit latched...")
time.sleep_ms(500)
#END_FOR
#END_DEF
#END_CLASS
ShiftRegisterController_74HC595.Run()
'''
'''
class ShiftRegisterController_74HC595:
def __init__(self, serial_data_pin, shift_register_clock_pin, store_register_clock_pin):
self.SD = Pin(serial_data_pin, Pin.OUT)
self.SH_CP = Pin(shift_register_clock_pin, Pin.OUT)
self.ST_CP = Pin(store_register_clock_pin, Pin.OUT)
MR = Pin(3, Pin.OUT)
MR.high()
#END_DEF
def CheckOutputLeds(self):
for bit in range(8):
self.SD.value(1)
time.sleep_ms(5)
self.SH_CP.low()
time.sleep_ms(5)
self.SH_CP.high()
time.sleep_ms(5)
self.ST_CP.low()
time.sleep_ms(5)
self.ST_CP.high()
print("Bit latched...")
time.sleep_ms(500)
#END_FOR
for bit in range(8):
self.SD.value(0)
time.sleep_ms(5)
self.SH_CP.low()
time.sleep_ms(5)
self.SH_CP.high()
time.sleep_ms(5)
self.ST_CP.low()
time.sleep_ms(5)
self.ST_CP.high()
print("Bit latched...")
time.sleep_ms(500)
#END_FOR
#END_DEF
def ClearOutputLeds(self):
self.SD.value(0)
time.sleep_ms(5)
for bit in range(8):
self.SH_CP.low()
time.sleep_ms(5)
self.SH_CP.high()
time.sleep_ms(5)
#END_FOR
self.ST_CP.low()
time.sleep_ms(5)
self.ST_CP.high()
time.sleep_ms(5)
print("Bits latched low...")
#END_DEF
def Latch8BitValue(self, value):
for bit in range(8):
shifted_value = value >> (7 - bit)
bit_value = 1 & shifted_value
self.SD.value(bit_value)
time.sleep_ms(5)
self.SH_CP.low()
time.sleep_ms(5)
self.SH_CP.high()
time.sleep_ms(5)
self.ST_CP.low()
time.sleep_ms(5)
self.ST_CP.high()
print("Bit latched...")
time.sleep_ms(500)
#END_DEF
#END_CLASS
#Test 06
# from 74HC595 import ShiftRegisterController_74HC595
#BEGIN_PROGRAM
Controller = ShiftRegisterController_74HC595(0, 2, 1)
Controller.ClearOutputLeds()
Controller.CheckOutputLeds()
Controller.ClearOutputLeds()
Controller.Latch8BitValue(int('10000000', 2))
#END_PROGRAM
# from machine import Pin
# import utime
# import random
# #define PINs according to cabling
# dataPIN = 0
# latchPIN = 1
# clockPIN = 2
# #set pins to output PIN objects
# dataPIN=Pin(dataPIN, Pin.OUT)
# latchPIN=Pin(latchPIN, Pin.OUT)
# clockPIN=Pin(clockPIN, Pin.OUT)
# #define shift register update function
# def shift_update(input,data,clock,latch):
# #put latch down to start data sending
# clock.value(0)
# latch.value(0)
# clock.value(1)
# #load data in reverse order
# for i in range(7, -1, -1):
# clock.value(0)
# data.value(int(input[i]))
# clock.value(1)
# #put latch up to store data on register
# clock.value(0)
# latch.value(1)
# clock.value(1)
# #main program, calling shift register function
# bit_string="00000000"
# while True:
# shift_update(bit_string,dataPIN,clockPIN,latchPIN)
# bit_string = str(random.randint(0, 1))+bit_string[:-1]
# utime.sleep(0.3)