<commit_before>#! /usr/bin/env python
# rpiShiftReg
# Using the 595 shift register with the Raspberry Pi
# Copyright (C) 2014 <NAME>

import RPi.GPIO as GPIO
import random
from time import sleep

random.seed()

# Rpi Pin Definitions
CLOCK=11
LATCH=13
DS=15

# How many 595s are connected to Rpi
CHAIN=1
# Value store in 595's storage register
STORED=0x00

# Setup pins
GPIO.setmode(GPIO.BOARD)
GPIO.setup(DS, GPIO.OUT)
GPIO.setup(LATCH, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(CLOCK, GPIO.OUT, initial=GPIO.LOW)

# Push a single bit into the registers
# writeLatch must be called after 8*CHAIN pushes
def pushBit(state):
    GPIO.output(CLOCK, 0)
    sleep(0)
    GPIO.output(DS, state)
    GPIO.output(CLOCK, 1)

# Transfer bits from shift register to storage register
def writeLatch():
    GPIO.output(LATCH, 1)
    GPIO.output(LATCH, 0)

# Make sure everything is hooked up
def testFunc():
    for i in range(256):
        pushBit(random.getrandbits(1))
        if (i+1)%(8*CHAIN) == 0:
            writeLatch()
            sleep(.125)

testFunc()<commit_msg>Added writeByte function and modified testFunc to use it<commit_after>#! /usr/bin/env python
# rpiShiftReg
# Using the 595 shift register with the Raspberry Pi
# Copyright (C) 2014 <NAME>

import RPi.GPIO as GPIO
from time import sleep

# Rpi Pin Definitions
CLOCK=11
LATCH=13
DS=15

# How many 595s are connected to Rpi
CHAIN=1
# Value store in 595's storage register
STORED=0x00

# Setup pins
GPIO.setmode(GPIO.BOARD)
GPIO.setup(DS, GPIO.OUT)
GPIO.setup(LATCH, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(CLOCK, GPIO.OUT, initial=GPIO.LOW)

# Push a single bit into the registers
# writeLatch must be called after 8*CHAIN pushes
def pushBit(state):
    GPIO.output(CLOCK, 0)
    sleep(0)
    GPIO.output(DS, state)
    GPIO.output(CLOCK, 1)

# Transfer bits from shift register to storage register
def writeLatch():
    GPIO.output(LATCH, 1)
    GPIO.output(LATCH, 0)

# Write a byte of length 8*CHAIN to the 595
def writeByte(value):
    global STORED
    for i in range(8*CHAIN):
        bit = (value << i) & (0x80 << 2*(CHAIN-1))
        pushBit( bit )
    writeLatch()
    STORED=value

# Make sure everything is hooked up
def testFunc():
    for i in range(256**CHAIN):
        writeByte(i)
        writeLatch()
        sleep(.008)
    for i in range((256**CHAIN)-1,0,-1):
        writeByte(i)
        writeLatch()
        sleep(.008)
    writeByte(0xFF**CHAIN)
    sleep(.25)
    writeByte(0x0F**CHAIN)
    sleep(.25)
    writeByte(0xF0**CHAIN)
    sleep(2)
    
testFunc()
{'fraction_non_alphanumeric': 0.11115490737091052, 'fraction_numerical': 0.04059913283405597, 'mean_word_length': 3.413913043478261, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5166340', 'n_tokens_mistral': 967, 'n_tokens_neox': 877, 'n_words': 272}