Advertisement
KRITSADA

Raspberry pi Light-Relay VEC No4

Dec 24th, 2015
4,494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- encoding: utf-8 -*-
  3. import time
  4. import smbus
  5. bus = smbus.SMBus(1)
  6. import RPi.GPIO as GPIO
  7. import time
  8. GPIO.setwarnings(False)
  9. GPIO.setmode(GPIO.BCM)
  10. addr = 0x23 # i2c adress
  11. my_pin=[16,26,20,21]
  12. for pin in my_pin:
  13.     GPIO.setup(pin,GPIO.OUT)
  14. st1=0
  15. st2=0
  16. st3=0
  17. st4=0
  18. st5=0
  19. count=0
  20. timer=0
  21. while True:
  22.     time.sleep(0.2)
  23.     data = bus.read_i2c_block_data(addr,0x11)
  24.     lum=(data[1] + (data[0]<<8) / 1.2)
  25.     #print ("Luminosity " ,lum,"lx")
  26.     while (lum<100):
  27.         timer=0
  28.         count+=1
  29.         data = bus.read_i2c_block_data(addr,0x11)
  30.         lum=(data[1] + (data[0]<<8) / 1.2)
  31.         time.sleep(0.2)
  32.         while (lum<100):
  33.             data = bus.read_i2c_block_data(addr,0x11)
  34.             lum=(data[1] + (data[0]<<8) / 1.2)
  35.             time.sleep(0.2)
  36.     print(count)
  37.     timer+=1
  38.     #print ("Timer=",timer)
  39.     if (timer>10):
  40.         if(count==1):
  41.             st1=~st1
  42.             GPIO.output(my_pin[0],st1)
  43.         elif(count==2):
  44.             st2=~st2
  45.             GPIO.output(my_pin[1],st2)
  46.         elif(count==3):
  47.             st3=~st3
  48.             GPIO.output(my_pin[2],st3)
  49.         elif(count==4):
  50.             st4=~st4
  51.             GPIO.output(my_pin[3],st4)
  52.         elif(count==5):
  53.             st5=~st5
  54.             st1=st2=st3=st4=st5
  55.             GPIO.output(my_pin[0],st5)
  56.             GPIO.output(my_pin[1],st5)
  57.             GPIO.output(my_pin[2],st5)
  58.             GPIO.output(my_pin[3],st5)
  59.         count=0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement