def show(self, number):
        firstDigit = (number % 100) / 10
        secondDigit = number % 10

        shiftpi.digitalWrite(shiftpi.ALL, shiftpi.LOW)
        self._writeDigit(firstDigit)
        self._writeDigit(secondDigit, 1)
def allOnorAllOff(turnOff, localDelayTime):
    if turnOff:
        shiftpi.digitalWrite(shiftpi.ALL, shiftpi.LOW)
        shiftpi.delay(localDelayTime)
    else:
        shiftpi.digitalWrite(shiftpi.ALL, shiftpi.HIGH)
        shiftpi.delay(localDelayTime)
    def _writeDigit(self, value, position=0):
        pins = []

        if value == 0:
            pins = [6, 1, 2, 3, 4, 5]
        if value == 1:
            pins = [1, 2]
        if value == 2:
            pins = [6, 1, 7, 3, 4]
        if value == 3:
            pins = [6, 1, 7, 2, 3]
        if value == 4:
            pins = [5, 7, 1, 2]
        if value == 5:
            pins = [6, 5, 7, 2, 3]
        if value == 6:
            pins = [6, 5, 4, 3, 2, 7]
        if value == 7:
            pins = [6, 1, 2]
        if value == 8:
            pins = [1, 2, 3, 4, 5, 6, 7]
        if value == 9:
            pins = [1, 6, 5, 7, 2]

        for pin in pins:
            shiftpi.digitalWrite(pin + position * 8, shiftpi.HIGH)
    def write(self):
        for k, p in enumerate(self.pinsRed):  # first the red lights
            val = shiftpi.LOW if k <= self.step else shiftpi.HIGH
            shiftpi.digitalWrite(p, val)

        for k, p in enumerate(self.pinsGreen):  # then the green ones
            val = shiftpi.LOW if k + len(
                self.pinsRed) <= self.step else shiftpi.HIGH
            shiftpi.digitalWrite(p, val)
Beispiel #5
0
	def check(self, key):
		valueSet = float(getattr(self, key + "_set"))
		valueMeasured = float(getattr(self, key))
		logging.info("check {0} '{1}' current/set: {2}/{3}'C".format(key, self.name, valueMeasured, valueSet))
		if valueSet >= valueMeasured:
			logger.info("setting relays {0}/{1} to OPEN".format(self.section, getattr(self, key + "_relays")))
			for i in range(len(getattr(self, key + "_relays"))):
				relay = int(getattr(self, key + "_relays")[i])
				shiftpi.digitalWrite(relay, shiftpi.HIGH)
				#time.sleep(0.1)
		else:
			logger.info("setting relays {0}/{1} to CLOSE".format(self.section, getattr(self, key + "_relays")))
			for i in range(len(getattr(self, key + "_relays"))):
				relay = int(getattr(self, key + "_relays")[i])
				shiftpi.digitalWrite(relay, shiftpi.LOW)
Beispiel #6
0
def get_distance_7():
    start = 0
    stop = 0
    time.sleep(0.1)
    digitalWrite(_TRIG_7, HIGH)
    time.sleep(0.00001)
    digitalWrite(_TRIG_7, LOW)
    temp = time.time()
    while GPIO.input(_ECHO_7) == 0 and time.time() - temp < 4:
        start = time.time()
    while GPIO.input(_ECHO_7) == 1 and time.time() - temp < 4:
        stop = time.time()
    distance_7 = int((stop - start) * 17000)
    print("Distance_7 = ", distance_7, " cm")
    #print("Start time: ",start)
    #print("Stop time: ",stop)
    return distance_7
Beispiel #7
0
def get_distance_9():
    GPIO.setup(_ECHO_9, GPIO.IN)
    start = 0
    stop = 0
    time.sleep(0.1)
    digitalWrite(_TRIG_9, HIGH)
    time.sleep(0.00001)
    digitalWrite(_TRIG_9, LOW)
    #print("Start time: ",start)
    temp = time.time()
    while GPIO.input(_ECHO_9) == 0 and time.time() - temp < 4:
        start = time.time()
        #print(time.time()-start)
    while GPIO.input(_ECHO_9) == 1 and time.time() - temp < 4:
        stop = time.time()
    distance_9 = int((stop - start) * 17000)
    print("Distance_9 = ", distance_9, " cm")
    #print("Start time: ",start)
    #print("Stop time: ",stop)
    return distance_9
def christmasKnightrider(localDelayTime):
    for index in range(8):
        if index > 0:
            # turn off previous LED
            shiftpi.digitalWrite(index - 1, shiftpi.LOW)

        # turn on the current LED
        shiftpi.digitalWrite(index, shiftpi.HIGH)
        shiftpi.delay(localDelayTime)

    for index in range(7, 0, -1):
        shiftpi.digitalWrite(index, shiftpi.LOW)
        shiftpi.digitalWrite(index - 1, shiftpi.HIGH)
        shiftpi.delay(localDelayTime)
Beispiel #9
0
def switch(leds, on, off):
    sort_indices = np.argsort(on)
    leds = np.array(leds)[sort_indices]
    on = np.array(on)[sort_indices]
    if len(sort_indices) > 1:
        sleep_diffs = np.diff(on)

    for led in leds:
        shiftpi.digitalWrite(led.pin(), shiftpi.HIGH)

    time.sleep(on[0])
    shiftpi.digitalWrite(leds[0].pin(), shiftpi.LOW)

    for i, led in enumerate(leds[1:]):
        time.sleep(sleep_diffs[i])
        shiftpi.digitalWrite(led.pin(), shiftpi.LOW)

    time.sleep(off.min())
 def turnSegOn(self, pinId):
     #print "Turn on seg {}".format(pinId)
     shiftpi.digitalWrite(pinId, shiftpi.HIGH)
Beispiel #11
0
#testing shiftpi
#this program uses the outputs to a do a binary counter from 0 to the total number of bits

from shiftpi import HIGH, LOW, digitalWrite, delay

bits = 8  #hard coded to 8 (one chip) for now

#loop from 0 to the max value of the bits available
for x in range(0, 2**bits):
    temp = x
    print 'setting binary ' + str(temp)
    for b in range(bits - 1, -1, -1):
        if temp >= 2**b:
            y -= 2**b
            digitalWrite((bits - 1) - b, HIGH)
        else:
            digitalWrite((bits - 1) - b, LOW)
    delay(250)
Beispiel #12
0
#testing shiftpi 
#this program uses the outputs to a do a binary counter from 0 to the total number of bits

from shiftpi import HIGH, LOW, digitalWrite, delay

bits = 8  #hard coded to 8 (one chip) for now

#loop from 0 to the max value of the bits available
for x in range(0, 2 ** bits):
    temp = x
    print 'setting binary ' + str(temp)
    for b in range(bits - 1, -1,-1):
        if temp >= 2 ** b:
            y -= 2 ** b
            digitalWrite((bits-1)- b, HIGH)
        else:
            digitalWrite((bits-1)- b, LOW)
    delay(250)
Beispiel #13
0
def go():
    shiftpi.digitalWrite(0, shiftpi.HIGH)
Beispiel #14
0
def stop():
    shiftpi.digitalWrite(0, shiftpi.LOW)
Beispiel #15
0
from shiftpi import HIGH, LOW, digitalWrite, delay

while True:
    digitalWrite(1, HIGH)
    delay(1000)
    digitalWrite(1, LOW)
    delay(1000)
Beispiel #16
0
def openA2():
    shiftpi.digitalWrite(2, shiftpi.HIGH)
Beispiel #17
0
def openB3():
    shiftpi.digitalWrite(6, shiftpi.HIGH)
Beispiel #18
0
def openA1():
    shiftpi.digitalWrite(1, shiftpi.HIGH)
Beispiel #19
0
def closeB2():
    shiftpi.digitalWrite(5, shiftpi.LOW)
Beispiel #20
0
def openB2():
    shiftpi.digitalWrite(5, shiftpi.HIGH)
Beispiel #21
0
def openB1():
    shiftpi.digitalWrite(4, shiftpi.HIGH)
Beispiel #22
0
def closeB1():
    shiftpi.digitalWrite(4, shiftpi.LOW)
Beispiel #23
0
def closeA2():
    shiftpi.digitalWrite(2, shiftpi.LOW)
 def turnAllOn(self):
     # turns all shift register pins to HIGH
     shiftpi.digitalWrite(shiftpi.ALL, shiftpi.HIGH)
Beispiel #25
0
	# Return the number as a tuple if on it's own
	if length == 1:
		return (0, number)
	
	# Loop over all integers in the number
	for i in xrange(0, length):
		integers += (int(strnum[i]),)

	return integers


try:
	while True:
		# Clear LEDs
		shiftpi.digitalWrite(shiftpi.ALL, shiftpi.LOW)

		# Obtain the current date and time
		now = datetime.datetime.now()

		# Split the time value
		(sec1, sec2) = splitNumber(now.second)
		(min1, min2) = splitNumber(now.minute)
		(hrs1, hrs2) = splitNumber(now.hour)

		# Convert decimal to binary maps
		bin_hrs1 = decimalToBinaryMap(hrs1, 2)
		bin_hrs2 = decimalToBinaryMap(hrs2, 4)
		bin_min1 = decimalToBinaryMap(min1, 3)
		bin_min2 = decimalToBinaryMap(min2, 4)
		bin_sec1 = decimalToBinaryMap(sec1, 3)
 def turnAllOff(self):
     # turns all shift register pins to LOW
     shiftpi.digitalWrite(shiftpi.ALL, shiftpi.LOW)
Beispiel #27
0
import shiftpi
import RPi.GPIO as GPIO

shiftpi.digitalWrite(1, shiftpi.LOW)

# switch it on
def go():
    shiftpi.digitalWrite(0, shiftpi.HIGH)

def stop():
    shiftpi.digitalWrite(0, shiftpi.LOW)

def openA1():
    shiftpi.digitalWrite(1, shiftpi.HIGH)


def closeA1():
    shiftpi.digitalWrite(1, shiftpi.LOW)


def openA2():
    shiftpi.digitalWrite(2, shiftpi.HIGH)

def closeA2():
    shiftpi.digitalWrite(2, shiftpi.LOW)


def closeB1():
    shiftpi.digitalWrite(4, shiftpi.LOW)

def openB1():
 def clear(self):
     shiftpi.digitalWrite(shiftpi.ALL, shiftpi.LOW)
Beispiel #29
0
def closeA1():
    shiftpi.digitalWrite(1, shiftpi.LOW)
def alternateBlinks():
    # turn all off
    allOnorAllOff(True, 10)

    # turn on and off evens
    shiftpi.digitalWrite(0, shiftpi.HIGH)
    shiftpi.digitalWrite(2, shiftpi.HIGH)
    shiftpi.digitalWrite(4, shiftpi.HIGH)
    shiftpi.digitalWrite(6, shiftpi.HIGH)
    shiftpi.delay(300)
    shiftpi.digitalWrite(0, shiftpi.LOW)
    shiftpi.digitalWrite(2, shiftpi.LOW)
    shiftpi.digitalWrite(4, shiftpi.LOW)
    shiftpi.digitalWrite(6, shiftpi.LOW)

    # turn on and off odds
    shiftpi.digitalWrite(1, shiftpi.HIGH)
    shiftpi.digitalWrite(3, shiftpi.HIGH)
    shiftpi.digitalWrite(5, shiftpi.HIGH)
    shiftpi.digitalWrite(7, shiftpi.HIGH)
    shiftpi.delay(300)
    shiftpi.digitalWrite(1, shiftpi.LOW)
    shiftpi.digitalWrite(3, shiftpi.LOW)
    shiftpi.digitalWrite(5, shiftpi.LOW)
    shiftpi.digitalWrite(7, shiftpi.LOW)
def digitZero(shiftregister=0):
    shiftpi.digitalWrite(0 + shiftregister, shiftpi.HIGH)
    shiftpi.digitalWrite(1 + shiftregister, shiftpi.HIGH)
    shiftpi.digitalWrite(2 + shiftregister, shiftpi.HIGH)
    shiftpi.digitalWrite(4 + shiftregister, shiftpi.HIGH)
    shiftpi.digitalWrite(5 + shiftregister, shiftpi.HIGH)
    shiftpi.digitalWrite(6 + shiftregister, shiftpi.HIGH)
    shiftpi.digitalWrite(7 + shiftregister, shiftpi.HIGH)
Beispiel #32
0
from shiftpi import (HIGH, LOW, ALL, digitalWrite, startupMode, delay,
                     shiftRegisters)

shiftRegisters(1)
startupMode(LOW)
up = 3
down = 4

try:

    while True:
        print('up')
        digitalWrite(up, HIGH)
        delay(500)
        digitalWrite(up, LOW)

        delay(6000)

        print('down')
        digitalWrite(down, HIGH)
        delay(500)
        digitalWrite(down, LOW)

        delay(6000)

except KeyboardInterrupt:
    digitalWrite(ALL, LOW)
Beispiel #33
0
import shiftpi

#shiftpi.pinsSetup({"ser": 16, "rclk": 20, "srclk": 21})
#shiftpi.startupMode({1: shiftpi.HIGH, 4: shiftpi.HIGH, 6: shiftpi.HIGH}, True)
shiftpi.delay(1000)
shiftpi.digitalWrite(shiftpi.ALL, shiftpi.LOW)
shiftpi.delay(1000)
for x in range(0, 9):
	shiftpi.digitalWrite(0, shiftpi.HIGH)
	shiftpi.delay(500)
	# turns shift register's pin 1 to LOW
	shiftpi.digitalWrite(0, shiftpi.LOW)
	shiftpi.delay(500)
	shiftpi.digitalWrite(1, shiftpi.HIGH)
	shiftpi.delay(500)
	# turns shift register's pin 1 to LOW
	shiftpi.digitalWrite(1, shiftpi.LOW)
	shiftpi.delay(500)
	shiftpi.digitalWrite(2, shiftpi.HIGH)
	shiftpi.delay(500)
	# turns shift register's pin 1 to LOW
	shiftpi.digitalWrite(2, shiftpi.LOW)
	shiftpi.delay(500)
	shiftpi.digitalWrite(3, shiftpi.HIGH)
	shiftpi.delay(500)
	# turns shift register's pin 1 to LOW
	shiftpi.digitalWrite(3, shiftpi.LOW)
	shiftpi.delay(500)
	shiftpi.digitalWrite(4, shiftpi.HIGH)
	shiftpi.delay(500)
Beispiel #34
0
def openA3():
    shiftpi.digitalWrite(3, shiftpi.HIGH)
Beispiel #35
0
def closeA3():
    shiftpi.digitalWrite(3, shiftpi.LOW)
Beispiel #36
0
from shiftpi import HIGH, LOW, ALL, digitalWrite, delay, startupMode

startupMode(LOW,True)

digitalWrite(0, HIGH)
delay(1000)

digitalWrite(0, LOW)

delay(1000)

digitalWrite(ALL, HIGH)
delay(1000)
digitalWrite(ALL, LOW)


while True:
    for x in range(0, 8):
        digitalWrite(x, HIGH)
        delay(100)
        digitalWrite(x, LOW)
Beispiel #37
0
def closeB3():
    shiftpi.digitalWrite(6, shiftpi.LOW)