Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __author__ = 'StybyK'
- import MySQLdb
- import smbus
- import sys
- import getopt
- import time
- import datetime
- bus = smbus.SMBus(1)
- db = MySQLdb.connect(host="localhost", user="root", passwd="Luc1nka", db="Automaty")
- def main():
- while True:
- maska = int('11111111', 2)
- PolePinu = [1, 1, 1, 1, 1, 1, 1, 1]
- cursor = db.cursor()
- cursor.execute("SELECT STATUS FROM `i2cA`")
- db.commit()
- result = cursor.fetchall()
- for k in range(0, 8):
- PolePinu[(7 - k)] = int(result[k][0])
- for i in range(len(PolePinu)):
- tmp = (len(PolePinu) - 1) - i
- if PolePinu[i] == 1:
- pinposition = 1 << tmp
- pinmask = ~~pinposition
- maska = maska - pinmask
- if PolePinu[i] == 0:
- pinposition = 0 << tmp
- pinmask = ~~pinposition
- maska += pinmask
- try:
- bus.write_byte_data(0x20,0x00, maska)
- except Exception:
- pass
- time.sleep(0.6)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement