Advertisement
Stybyk

zalohaPythonu

May 27th, 2015
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. __author__ = 'StybyK'
  2. import MySQLdb
  3. import smbus
  4. import sys
  5. import getopt
  6. import time
  7. import datetime
  8.  
  9. bus = smbus.SMBus(1)
  10.  
  11. db = MySQLdb.connect(host="localhost", user="root", passwd="Luc1nka", db="Automaty")
  12.  
  13.  
  14. def main():
  15.     while True:
  16.         maska = int('11111111', 2)
  17.         PolePinu = [1, 1, 1, 1, 1, 1, 1, 1]
  18.  
  19.         cursor = db.cursor()
  20.         cursor.execute("SELECT STATUS FROM `i2cA`")
  21.         db.commit()
  22.         result = cursor.fetchall()
  23.  
  24.         for k in range(0, 8):
  25.             PolePinu[(7 - k)] = int(result[k][0])
  26.  
  27.  
  28.  
  29.         for i in range(len(PolePinu)):
  30.             tmp = (len(PolePinu) - 1) - i
  31.             if PolePinu[i] == 1:
  32.                 pinposition = 1 << tmp
  33.                 pinmask = ~~pinposition
  34.                 maska = maska - pinmask
  35.  
  36.             if PolePinu[i] == 0:
  37.                 pinposition = 0 << tmp
  38.                 pinmask = ~~pinposition
  39.                 maska += pinmask
  40.  
  41.  
  42.  
  43.         try:
  44.             bus.write_byte_data(0x20,0x00, maska)
  45.         except Exception:
  46.             pass
  47.         time.sleep(0.6)
  48.  
  49.  
  50.  
  51.  
  52. if __name__ == "__main__":
  53.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement