Advertisement
nicola_bertelli

pulsante 12v

Nov 24th, 2019
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. import paho.mqtt.publish as publish
  2. import time
  3. import RPi.GPIO as GPIO
  4.  
  5.  
  6. # QUI SOTTO INSERIRE L'INDIRIZZO IP DEL VOSTRO SERVER MQTT
  7. #
  8. host_mqtt="192.168.xxx.xxx"
  9.  
  10. GPIO.setmode(GPIO.BCM)
  11. GPIO.setwarnings(False)
  12.  
  13. pulsante = 21 # PULSANTE
  14. tempo_pressione = 1.3
  15.  
  16. GPIO.setup(pulsante, GPIO.IN, pull_up_down=GPIO.PUD_UP)  
  17.  
  18. print("pulsante avviato")
  19.  
  20.  
  21. while True:
  22.     if (GPIO.input(pulsante)==0):
  23.         publish.single("pulsante_12v", ("on"), hostname= host_mqtt)
  24.         print("premuto")
  25.  
  26.         while (GPIO.input(pulsante)==0):
  27.             time.sleep (0.3)
  28.  
  29.         publish.single("pulsante_12v", ("off"), hostname= host_mqtt)
  30.         print("lasciato")
  31.  
  32.  
  33.     time.sleep(0.2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement