Пример #1
0
    def __init__(self):
        wp.wiringPiSetup()

        #left 23017, for audio
        wp.mcp23017Setup( PB1,0x20)
        for pin in OUTPUT_PINS_1:
            wp.pinMode(pin,OUTPUT)
        for pin in INPUT_PINS_1:
            wp.pinMode(pin, INPUT)

        #right 23017 for 230v switching
        wp.mcp23017Setup( PB2,0x21)
        for pin in OUTPUT_PINS_2:
            wp.pinMode(pin,OUTPUT)
        for pin in INPUT_PINS_2:
            wp.pullUpDnControl(pin,PUD_UP)
            wp.pinMode(pin, INPUT)


        #display
        wp.digitalWrite(70,0)  # write mode
        self.display1 = wp.lcdInit(2,16,8, 71,69,72,73,74,75,76,77,78,79) #connected to first expander
        wp.lcdClear(self.display1)


        #pwm driver
        self.pwm = PWM()
        self.pwm.setPWMFreq(200)
Пример #2
0
def init_control_plane():
    logger.info("Initializing control plane")
    chip1_i2c_addr = 0x20  # Controlled by A0, A1, A2 pins GND or +5V
#    chip2_i2c_addr = 0x22  # Controlled by A0, A1, A2 pins GND or +5V
#    chip3_i2c_addr = 0x23  # Controlled by A0, A1, A2 pins GND or +5V
#    chip4_i2c_addr = 0x24  # Controlled by A0, A1, A2 pins GND or +5V

    wiringpi.wiringPiSetup()  # initialise wiringpi

    wiringpi.mcp23017Setup(pin_base, chip1_i2c_addr)  # pins 65-80
#    wiringpi.mcp23017Setup(pin_base + 16, chip2_i2c_addr)  # pins 81-96
#    wiringpi.mcp23017Setup(pin_base + 32, chip3_i2c_addr)  # pins 97-112
#    wiringpi.mcp23017Setup(pin_base + 48, chip4_i2c_addr)  # pins 113-128

    for pin in range(pin_base, pin_max):
        set_pin(pin, OFF)
        wiringpi.pinMode(pin, PIN_MODE_ACTIVE)  # set to output mode

    sleep(1)

    for pin in range(pin_base, pin_max):
        mode = wiringpi.getAlt(pin)
        if mode != PIN_MODE_ACTIVE:
            logger.error("Initialized pin {0} to mode {1} but found it in mode {2}".format(pin, PIN_MODE_ACTIVE, mode))

    # and then apply our CHANGES
    apply_model(False)
    logger.info("Control plane initialized successfully")
Пример #3
0
def initialize():
    # Initialize wiringpi
    wiringpi.wiringPiSetup()
    wiringpi.mcp23017Setup(PIN_BASE, I2C_ADDR)
    for button in BUTTONS:
        wiringpi.pinMode(PIN_BASE + button, OUTPUT)
        wiringpi.digitalWrite(PIN_BASE + button, ON)
def gpiosetup():
  global lcd
  wiringpi2.wiringPiSetup()
  wiringpi2.mcp23017Setup(AF_BASE,0x20)
  wiringpi2.pinMode(AF_RIGHT,0)
  wiringpi2.pinMode(AF_LEFT,0)
  wiringpi2.pinMode(AF_SELECT,0)
  wiringpi2.pinMode(AF_RW,1)
  wiringpi2.digitalWrite(AF_RW,0)
  #lcdInit(int rows, int cols, int bits, int rs, int strb, int d0, int d1, int d2, int d3, int d4, int d5, int d6, int d7)
  lcd=wiringpi2.lcdInit(2,16,4,AF_RS,AF_E,AF_DB4,AF_DB5,AF_DB6,AF_DB7,0,0,0,0)
Пример #5
0
def runswitch(deviceaddr, pinswitch, chn, readaddr):
  pin_base = pinstart       # lowest available starting number is 65
  i2c_addr = deviceaddr     # 0x20    A0, A1, A2 pins all wired to GND

  wiringpi.wiringPiSetup()                    # initialise wiringpi
  wiringpi.mcp23017Setup(pin_base,i2c_addr)   # set up the pins and i2c address

  wiringpi.pinMode(pinswitch, 1)         # sets GPA0 to output
  sleep(0.5)
  print(readvoltage(readaddr, chn))
  wiringpi.digitalWrite(pinswitch, 0)    # sets GPA0 to 0 (0V, off)



  wiringpi.pinMode(pinswitch, 0)      # sets GPIO GPA1 back to input Mode
Пример #6
0
    def __init__(self):
        self._num_of_healds = 32
        self._action_pattern = [0] * self._num_of_heald
        self._i2c_addr = [0x20, 0x21]
        self._solenoid_gpio_table = [
            88, 87, 86, 85, 84, 83, 82, 81, 89, 90, 91, 92, 93, 94, 95, 96, 72,
            71, 70, 69, 68, 67, 66, 65, 73, 74, 75, 76, 77, 78, 79, 80
        ]

        self._pin_base_0 = 65
        self._pin_base_1 = 81

        wiringpi2.wiringpPiSetup()
        wiringpi2.mcp23017Setup(self._pin_base_0, self._i2c_addr[0])
        wiringpi2.mcp23017Setup(self._pin_base_1, self._i2c_addr[2])

        for pin in self._solenoid_gpio_table:
            wiringpi2.pinMode(pin, 1)
            wiringpi2.digitalWrite(pin, 0)
Пример #7
0
def setupIO():
    wiringpi.wiringPiSetup()  # initialise wiringpi
    wiringpi.mcp23017Setup(101, 0x20)  # set up the pins and i2c address
    wiringpi.mcp23017Setup(117, 0x21)
    wiringpi.mcp23017Setup(133, 0x22)
    for x in range(101, 149):
        wiringpi.pinMode(x, 1)  # sets GPA0 to output
Пример #8
0
import wiringpi2 as wiringpi, time, random
wiringpi.wiringPiSetup()  # initialise wiringpi
wiringpi.mcp23017Setup(101, 0x20)  # set up the pins and i2c address
wiringpi.mcp23017Setup(117, 0x21)
wiringpi.mcp23017Setup(133, 0x22)
print('I2C Testing Section')
print('.')
for x in range(101, 149):
    wiringpi.pinMode(x, 1)  # sets GPA0 to output

#Start 1 on at a time
print('Start 1 on/off at a time')
L = 1  # number of loops
S = (.2)  # delay between loops

for run_a in range(0, L):
    for x in range(101, 149):
        print x
        wiringpi.digitalWrite(x, 0)
        time.sleep(S * 2)

#Start 1 on at a time
print('Start 1 on/off at a time')
L = 1  # number of loops
S = (.2)  # delay between loops
for run_a in range(0, L):
    for x in range(101, 149):
        print x
        wiringpi.digitalWrite(x, 1)
        time.sleep(S)
Пример #9
0
import sys


# updated to account for darlington arrays
ON = 1
OFF = 0

pin_base = 65       # lowest available starting number is 65
chip1_i2c_addr = 0x20     # A0, A1, A2 pins all wired to GND 
#chip2_i2c_addr = 0x22     # A0, A1, A2 pins all wired to GND
#chip3_i2c_addr = 0x23     # A0, A1, A2 pins all wired to GND 
#chip4_i2c_addr = 0x24     # A0, A1, A2 pins all wired to GND

wiringpi.wiringPiSetup()                    # initialise wiringpi

wiringpi.mcp23017Setup(pin_base,   chip1_i2c_addr)   # pins 65-80
#wiringpi.mcp23017Setup(pin_base+16,chip2_i2c_addr)   # pins 81-96
#wiringpi.mcp23017Setup(pin_base+32,chip3_i2c_addr)   # pins 97-112
#wiringpi.mcp23017Setup(pin_base+48,chip4_i2c_addr)   # pins 113-128

pin_max = 80

def shutdown():
	for pin in range(pin_base,pin_max):
		off(pin)

def on(pin):
        wiringpi.digitalWrite(pin, ON) # sets port GPA1 to 0V, which turns the relay ON.
        print "pin {} on".format(pin)
  
def off(pin):
Пример #10
0
                       socket.IPPROTO_UDP)  # Create the socket
sender.setsockopt(
    socket.SOL_SOCKET, socket.SO_BROADCAST,
    1)  # Enable broadcasting (sending to many IPs based on wild-cards)
sender.bind(
    ('0.0.0.0', 0)
)  # Set the IP and port number to use locally, IP 0.0.0.0 means all connections and port 0 means assign a number for us (do not care)

GPIO.setmode(GPIO.BOARD)  #Use the pinnumbers easier for different RPI
GPIO.setwarnings(False)

#define MCP23017 and Wiringpi parameters
pin_base = 65  # lowest available starting number is 65
i2c_addr = 0x20  # A0, A1, A2 pins all wired to GND
wiringpi.wiringPiSetup()  # initialise wiringpi
wiringpi.mcp23017Setup(pin_base, i2c_addr)  # set up the pins and i2c address

#define GPIO ports
Button_Left_up = 26  #gpio input
Button_Left_down = 7  #gpio input
Button_Right_down = 11  #gpio input
Button_Right_up = 13  #gpio input
MCP_LED_White = 65  #MCP WiringPI port GPIOA0
MCP_LED_Green = 66  #MCP WiringPI port GPIOA1
MCP_LED_Red = 67  #MCP WiringPI port GPIOA2
MCP_Switch = 72  #MCP WiringPI port GPIOA7

#Setup the GPIO ports
GPIO.setup(Button_Left_up, GPIO.IN)
GPIO.setup(Button_Left_down, GPIO.IN)
GPIO.setup(Button_Right_up, GPIO.IN)
Пример #11
0

#Python Raspberry Pi Logging
#Jeroen van Oorschot 2014
#Server side script write logs to database


import subprocess
import PyDatabase
import wiringpi2 as wp
import GFunc
import serial

GF = GFunc.GFunc()
wp.wiringPiSetup()
wp.mcp23017Setup(64,0x20)#initialize expander, needed for output pin 66 for smart meter
wp.pinMode(66,1)
wp.digitalWrite(66,0)


##//////////////////////////////##
##|||||Output helper func|||||||##
##\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\##

def setOutput(pin, value):
    print ("set " + pin + " to " + value)
    #set gpio


##//////////////////////////////##
##||||||LOG FUNCTIONS|||||||||||##
Пример #12
0
# Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander )
import wiringpi2

pin_base = 65
i2c_addr = 0x20
pins = [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80]

wiringpi2.wiringPiSetup()
wiringpi2.mcp23017Setup(pin_base, i2c_addr)

for pin in pins:
    wiringpi2.pinMode(pin, 1)
    wiringpi2.digitalWrite(pin, 1)
#	wiringpi2.delay(1000)
#	wiringpi2.digitalWrite(pin,0)
Пример #13
0
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
import wiringpi2 as wiringpi

# Define constants
INPUT, OUTPUT = LOW, HIGH = OFF, ON = [0, 1]
BUTTONS = [0,1,2,3,4]
PIN_BASE = 64
I2C_ADDR = 0x20
PUD_UP=2

# Initialize wiringpi to use mcp23017 GPIO expansion chip
wiringpi.wiringPiSetup()
wiringpi.mcp23017Setup(PIN_BASE,I2C_ADDR)

for button in BUTTONS:
  wiringpi.pinMode(PIN_BASE + button,INPUT)
  wiringpi.pullUpDnControl(PIN_BASE + button,PUD_UP)

# Main loop to capture button
try:
  while 1:
    for index,button in enumerate(BUTTONS):
      button_state = wiringpi.digitalRead(PIN_BASE + button)
      if button_state == OFF:
        print "button (%d) %d = %d" % (PIN_BASE + button, index, button_state)
      wiringpi.delay(20)
except KeyboardInterrupt:
  pass
Пример #14
0
import wiringpi2 as wiringpi
import time

pin_base = 65  # lowest available starting number is 65
i2c_addr = 0x20  # A0, A1, A2 pins all wired to GND

wiringpi.wiringPiSetup()  # initialise wiringpi
wiringpi.mcp23017Setup(pin_base, i2c_addr)  # set up the pins and i2c address

wiringpi.pinMode(68, 1)  # sets GPA0 to output
wiringpi.pinMode(66, 1)
wiringpi.pinMode(67, 1)
wiringpi.digitalWrite(68, 0)  # sets GPA0 to 0 (0V, off)
wiringpi.digitalWrite(66, 0)
wiringpi.digitalWrite(67, 0)

# Note: MCP23017 has no internal pull-down, so I used pull-up and inverted
# the button reading logic with a "not"
while True:
    wiringpi.digitalWrite(68, 1)  # sets port GPA0 to 1 (3V3, on)
    wiringpi.digitalWrite(66, 1)
    time.sleep(3)
    wiringpi.digitalWrite(68, 0)
    wiringpi.digitalWrite(66, 0)
    time.sleep(3)
Пример #15
0
from celery import Celery


# updated to account for Darlington arrays
ON = 1
OFF = 0

pin_base = 65       # lowest available starting number is 65
chip1_i2c_addr = 0x21     # A0, A1, A2 pins all wired to GND 
chip2_i2c_addr = 0x22     # A0, A1, A2 pins all wired to GND
chip3_i2c_addr = 0x23     # A0, A1, A2 pins all wired to GND 
chip4_i2c_addr = 0x24     # A0, A1, A2 pins all wired to GND

wiringpi.wiringPiSetup()                    # initialise wiringpi

wiringpi.mcp23017Setup(pin_base,   chip1_i2c_addr)   # pins 65-80
wiringpi.mcp23017Setup(pin_base+16,chip2_i2c_addr)   # pins 81-96
wiringpi.mcp23017Setup(pin_base+32,chip3_i2c_addr)   # pins 97-112
wiringpi.mcp23017Setup(pin_base+48,chip4_i2c_addr)   # pins 113-128

pin_max = 128

def shutdown():
	for pin in range(pin_base,pin_max):
		off(pin)

def on(pin):
        wiringpi.digitalWrite(pin, ON) # sets port GPA1 to 0V, which turns the relay ON.
        print "pin {} on".format(pin)
  
def off(pin):
Пример #16
0
 def GPIOsetup(self, pinbase=0, ADDR=IO_ADDR):
     wiringpi2.wiringPiSetupPhys()
     if (pinbase != 0):
         wiringpi2.mcp23017Setup(pinbase, ADDR)
     for gpio in self.pins:
         wiringpi2.pinMode(gpio, OUT)
def enable_device():
    """enable the specified device """
    try:
        devices = cm.hardware.devices

        for key in devices.keys():
            device = key
            device_slaves = devices[key]

            # mcp23017
            if device.lower() == "mcp23017":
                for slave in device_slaves:
                    params = slave
                    wiringpi.mcp23017Setup(int(params['pinBase']),
                                           int(params['i2cAddress'],
                                               16))

            # mcp23s17
            elif device.lower() == "mcp23s17":
                for slave in device_slaves:
                    params = slave
                    wiringpi.mcp23s17Setup(int(params['pinBase']),
                                           int(params['spiPort'],
                                               16),
                                           int(params['devId']))

            # TODO: Devices below need testing, these should work but
            # could not verify due to lack of hardware

            # mcp23016
            elif device.lower() == "mcp23016":
                for slave in device_slaves:
                    params = slave
                    wiringpi.mcp23016Setup(int(params['pinBase']),
                                           int(params['i2cAddress'],
                                               16))

            # mcp23s08 - Needs Testing
            elif device.lower() == "mcp23008":
                for slave in device_slaves:
                    params = slave
                    wiringpi.mcp23008Setup(int(params['pinBase']),
                                           int(params['i2cAddress'],
                                               16))

            # mcp23s08 - Needs Testing
            elif device.lower() == "mcp23s08":
                for slave in device_slaves:
                    params = slave
                    wiringpi.mcp23s08Setup(int(params['pinBase']),
                                           int(params['spiPort'],
                                               16),
                                           int(params['devId']))

            # sr595 - Needs Testing
            elif device.lower() == "sr595":
                for slave in device_slaves:
                    params = slave
                    wiringpi.sr595Setup(int(params['pinBase']),
                                        int(params['numPins']),
                                        int(params['dataPin']),
                                        int(params['clockPin']),
                                        int(params['latchPin']))

            # pcf8574
            elif device.lower() == "pcf8574":
                for slave in device_slaves:
                    params = slave
                    wiringpi.pcf8574Setup(int(params['pinBase']),
                                          int(params['i2cAddress'],
                                              16))

            else:
                logging.error("Device defined is not supported, please check "
                              "your devices settings: " + str(device))
    except Exception as error:
        logging.debug("Error setting up devices, please check your devices "
                      "settings.")
        logging.debug(error)
Пример #18
0
IN7 = pinBase + 14
IN8 = pinBase + 15
#ins = [IN1,IN2,IN3,IN3,IN4,IN5,IN6,IN7,IN8]
ins = [IN1,IN2,IN3]
ROW1 = 0
ROW2 = 1
ROW3 = 2
ROW4 = 3
ROW5 = 4
ROW6 = 5
ROW7 = 6
ROW8 = 7
#rows = [ROW1,ROW2,ROW3,ROW4,ROW5,ROW6,ROW7,ROW8]
rows = [ROW1,ROW2,ROW3]
wiringpi.wiringPiSetup()
wiringpi.mcp23017Setup(pinBase,i2cAddr)
#Setup pin mode for LEDs AS OUTPUTS
wiringpi.pinMode(LED1,OUT)
wiringpi.pinMode(LED2,OUT)
wiringpi.pinMode(LED3,OUT)
wiringpi.pinMode(LED4,OUT)
wiringpi.pinMode(LED5,OUT)
wiringpi.pinMode(LED6,OUT)
wiringpi.pinMode(LED7,OUT)
wiringpi.pinMode(LED8,OUT)
#pull ups
wiringpi.pullUpDnControl(IN1,2)
wiringpi.pullUpDnControl(IN2,2)
wiringpi.pullUpDnControl(IN3,2)
wiringpi.pullUpDnControl(IN4,2)
wiringpi.pullUpDnControl(IN5,2)
def enable_device():
    """enable the specified device """
    try:
        devices = cm.hardware.devices

        for key in devices.keys():
            device = key
            device_slaves = devices[key]

            # mcp23017
            if device.lower() == "mcp23017":
                for slave in device_slaves:
                    params = slave
                    wiringpi.mcp23017Setup(int(params['pinBase']),
                                           int(params['i2cAddress'], 16))

            # mcp23s17
            elif device.lower() == "mcp23s17":
                for slave in device_slaves:
                    params = slave
                    wiringpi.mcp23s17Setup(int(params['pinBase']),
                                           int(params['spiPort'], 16),
                                           int(params['devId']))

            # TODO: Devices below need testing, these should work but
            # could not verify due to lack of hardware

            # mcp23016
            elif device.lower() == "mcp23016":
                for slave in device_slaves:
                    params = slave
                    wiringpi.mcp23016Setup(int(params['pinBase']),
                                           int(params['i2cAddress'], 16))

            # mcp23s08 - Needs Testing
            elif device.lower() == "mcp23008":
                for slave in device_slaves:
                    params = slave
                    wiringpi.mcp23008Setup(int(params['pinBase']),
                                           int(params['i2cAddress'], 16))

            # mcp23s08 - Needs Testing
            elif device.lower() == "mcp23s08":
                for slave in device_slaves:
                    params = slave
                    wiringpi.mcp23s08Setup(int(params['pinBase']),
                                           int(params['spiPort'], 16),
                                           int(params['devId']))

            # sr595 - Needs Testing
            elif device.lower() == "sr595":
                for slave in device_slaves:
                    params = slave
                    wiringpi.sr595Setup(int(params['pinBase']),
                                        int(params['numPins']),
                                        int(params['dataPin']),
                                        int(params['clockPin']),
                                        int(params['latchPin']))

            # pcf8574
            elif device.lower() == "pcf8574":
                for slave in device_slaves:
                    params = slave
                    wiringpi.pcf8574Setup(int(params['pinBase']),
                                          int(params['i2cAddress'], 16))

            else:
                logging.error("Device defined is not supported, please check "
                              "your devices settings: " + str(device))
    except Exception as error:
        logging.debug("Error setting up devices, please check your devices "
                      "settings.")
        logging.debug(error)
Пример #20
0
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
import wiringpi2 as wiringpi

# Define constants
INPUT, OUTPUT = LOW, HIGH = OFF, ON = [0, 1]
BUTTONS = [0, 1, 2, 3, 4]
PIN_BASE = 64
I2C_ADDR = 0x20
PUD_UP = 2

# Initialize wiringpi to use mcp23017 GPIO expansion chip
wiringpi.wiringPiSetup()
wiringpi.mcp23017Setup(PIN_BASE, I2C_ADDR)

for button in BUTTONS:
    wiringpi.pinMode(PIN_BASE + button, INPUT)
    wiringpi.pullUpDnControl(PIN_BASE + button, PUD_UP)

# Main loop to capture button
try:
    while 1:
        for index, button in enumerate(BUTTONS):
            button_state = wiringpi.digitalRead(PIN_BASE + button)
            if button_state == OFF:
                print "button (%d) %d = %d" % (PIN_BASE + button, index,
                                               button_state)
            wiringpi.delay(20)
except KeyboardInterrupt:
Пример #21
0
import wiringpi2
wiringpi2.mcp23017Setup(100, 0x20)
wiringpi2.mcp23017Setup(200, 0x21)
wiringpi2.mcp23017Setup(300, 0x22)
wiringpi2.mcp23017Setup(400, 0x23)
wiringpi2.mcp23017Setup(500, 0x24)

for i in range(100, 115+1):
	#print "setting input %s", str(i)
	wiringpi2.pinMode(i, 0) #0 = input
	wiringpi2.pullUpDnControl(i, 2) #2 = pull up   

for i in range(200, 208+1):
	#print "setting input %s", str(i)
	wiringpi2.pinMode(i, 0) #0 = input
	wiringpi2.pullUpDnControl(i, 2) #2 = pull up   

out = ""
out2 = ""
for i in range(100, 115+1):
	out += str(wiringpi2.digitalRead(i)) + "   "
	out2 += str(i) + " "
	#out += "%s = %s" % ( i, wiringpi2.digitalRead(i) )
print out2
print out
Пример #22
0
LCD_WIDTH = 16  # Maximum characters per line
LCD_CHR = True
LCD_CMD = False
LCD_LINE_1 = 0x80  # LCD RAM address for the 1st line
LCD_LINE_2 = 0xC0  # LCD RAM address for the 2nd line

# Timing constants
E_PULSE = 0.0005
E_DELAY = 0.0005
T_MS = 1.0000000 / 1000000
P_RS = 11  # 7


# Initialise the I2Cs
wiringpi.wiringPiSetup()
wiringpi.mcp23017Setup(pin_base_i2c1, i2c1_LEDS_addr)
wiringpi.mcp23017Setup(pin_base_i2c2, i2c2_LEDS_addr)


# Set default PIN MODES
wiringpi.pinMode(A, OUT)
wiringpi.pinMode(B, OUT)
wiringpi.pinMode(C, OUT)
wiringpi.pinMode(D, OUT)
wiringpi.pinMode(E, OUT)
wiringpi.pinMode(F, OUT)
wiringpi.pinMode(G, OUT)
wiringpi.pinMode(H, OUT)
wiringpi.pinMode(ONE, OUT)
wiringpi.pinMode(TWO, OUT)
wiringpi.pinMode(THR, OUT)
Пример #23
0
i2c_addr = 0x20
# how long a pin should be high/on, in seconds
on_duration = 0.2


# functions
def pin_on(pin):
	print "pin: "+str(pin)+" - on"
	wpi.digitalWrite(pin, 1)

def pin_off(pin):
	print "pin: "+str(pin)+" - off"
	wpi.digitalWrite(pin, 0)

def all_on():
	for pin in xrange(pin_base, pin_last+1):
		pin_on(pin)
def all_off():
	for pin in xrange(pin_base, pin_last+1):
		pin_off(pin)

# setup wiring pi library to work with mcp23017
wpi.wiringPiSetup()
wpi.mcp23017Setup(pin_base, i2c_addr)

try:
  all_off()

finally:
  all_off()
Пример #24
0
import time

import wiringpi2

pin_base = 65   # arbitrary number above 64
i2c_addr = 0x21 # I2C address of the MCP23017

wiringpi2.wiringPiSetup()
wiringpi2.mcp23017Setup(pin_base, i2c_addr)

states = [0, 1]
lights = range(0, 16)

# init
for light in lights:
    wiringpi2.pinMode(pin_base + light, 1)

# run
while True:
    for state in states:
        for light in lights:
            wiringpi2.digitalWrite(pin_base + light, state)
        time.sleep(1)
Пример #25
0
IN7 = pinBase + 14
IN8 = pinBase + 15
#ins = [IN1,IN2,IN3,IN3,IN4,IN5,IN6,IN7,IN8]
ins = [IN1, IN2, IN3]
ROW1 = 0
ROW2 = 1
ROW3 = 2
ROW4 = 3
ROW5 = 4
ROW6 = 5
ROW7 = 6
ROW8 = 7
#rows = [ROW1,ROW2,ROW3,ROW4,ROW5,ROW6,ROW7,ROW8]
rows = [ROW1, ROW2, ROW3]
wiringpi.wiringPiSetup()
wiringpi.mcp23017Setup(pinBase, i2cAddr)
#Setup pin mode for LEDs AS OUTPUTS
wiringpi.pinMode(LED1, OUT)
wiringpi.pinMode(LED2, OUT)
wiringpi.pinMode(LED3, OUT)
wiringpi.pinMode(LED4, OUT)
wiringpi.pinMode(LED5, OUT)
wiringpi.pinMode(LED6, OUT)
wiringpi.pinMode(LED7, OUT)
wiringpi.pinMode(LED8, OUT)
#pull ups
wiringpi.pullUpDnControl(IN1, 2)
wiringpi.pullUpDnControl(IN2, 2)
wiringpi.pullUpDnControl(IN3, 2)
wiringpi.pullUpDnControl(IN4, 2)
wiringpi.pullUpDnControl(IN5, 2)