Auteur : Jerome | Langage : Python
Posté le 11 avril 2018
Télécharger | Éditer | Reposter

code pilotage sevomoteur

#!/usr/bin/python import paho.mqtt.client as mqtt import paho.mqtt.publish as publish import time import RPi.GPIO as GPIO def on_connect(client, userdata, flags, rc): print("Connected with result code "+str(rc)) # Subscribing in on_connect() means that if we lose the connection and # reconnect then subscriptions will be renewed. client.subscribe("printcam/servo") def on_publish(client, userdata, mid): print("Message sent") def on_subscribe(client, userdata, mid, granted_qos): print("Subscribe with mid "+str(mid)+" received.") def on_message(client, userdata, msg): print("Message received on topic "+msg.topic+" with QoS "+str(msg.qos)) if (msg.topic=="printcam/servo") and (msg.payload=='stop'): GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(12, GPIO.OUT) duree = 1 pwm=GPIO.PWM(12,100) pwm.start(5) angleChoisi = 10 pwm.ChangeDutyCycle(angleChoisi) time.sleep(0.1) angleChoisi = 12 pwm.ChangeDutyCycle(angleChoisi) time.sleep(duree) GPIO.cleanup() pwm.stop(5) if (msg.topic=="printcam/servo") and (msg.payload=='start'): GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(12, GPIO.OUT) duree = 1 pwm=GPIO.PWM(12,100) pwm.start(5) angleChoisi = 13.6 pwm.ChangeDutyCycle(angleChoisi) time.sleep(0.1) angleChoisi = 12 pwm.ChangeDutyCycle(angleChoisi) time.sleep(duree) GPIO.cleanup() pwm.stop(5) time.sleep(2) # Déclaration d'une variable d'éta globale SNAP_Image=0 mqttclient = mqtt.Client() mqttclient.connect("test.mosquitto.org", 1883,60) # Assign event callbacks mqttclient.on_connect = on_connect mqttclient.on_publish = on_publish mqttclient.on_subscribe = on_subscribe mqttclient.on_message = on_message # Connect #mqttclient.username_pw_set("surveillanceimprimante3d@gmail.com, "impriman") # Start subscription mqttclient.subscribe("printcam/servo") mqttclient.loop_forever()
x
Éditer le texte

Merci d'entrer le mot de passe que vous avez indiqué à la création du texte.

x
Télécharger le texte

Merci de choisir le format du fichier à télécharger.