Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import time
  2. import RPi.GPIO as GPIO
  3. GPIO.setmode(GPIO.BCM)
  4.  
  5. GPIO.setup(26, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
  6.  
  7. i = 0
  8.  
  9. start = time.time()
  10.  
  11. while time.time() - start < 60: # sample for 1 minute
  12.         GPIO.wait_for_edge(26, GPIO.FALLING)
  13.         i += 1
  14.  
  15. # 10000 impulses per hour @ 1kW
  16. # =  10 impulses per hour @ 1W
  17. # i = watts * 10 / hours
  18. # 1 minute = 1/60 hours
  19. # i = watts * 10 / (1/60)
  20.  
  21. watts = i * 60.0 / 10.0
  22.  
  23. print watts, "Watts"
  24.  
  25. GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement