Merge branch 'main' of git.leizour.fr:GroupeIOT/projet-iot
This commit is contained in:
commit
b47db0f6d9
1 changed files with 27 additions and 9 deletions
|
@ -1,30 +1,48 @@
|
||||||
client = mqtt.client("Player", "mqtt.leizour.fr", 8883, true)
|
client = mqtt.client("Player", "mqtt.leizour.fr", 8883, true)
|
||||||
client:connect("student", "O99Rq8$F12NXzhL5caya")
|
client:connect("student", "O99Rq8$F12NXzhL5caya")
|
||||||
|
|
||||||
-- CLK (clock) : D15
|
-- CLK (clock) : D15
|
||||||
-- DT (data) : D2
|
-- DT (data) : D2
|
||||||
-- SW (Bouton): D4
|
-- SW (Bouton): D4
|
||||||
-- dir = direction de tournage de l'encodeur
|
-- dir = direction de tournage de l'encodeur
|
||||||
-- counter = nombre de cran tourner
|
-- counter = nombre de crans tournés
|
||||||
-- button = bouton poussoir
|
-- button = bouton poussoir
|
||||||
|
|
||||||
|
playing = false
|
||||||
mot = ""
|
mot = ""
|
||||||
last_clicked = 0
|
last_clicked = 0
|
||||||
function action(dir, counter, button)
|
function action(dir, counter, button)
|
||||||
cls()
|
cls()
|
||||||
lettre = string.char((counter % 26)+65)
|
lettre = string.char((counter % 26)+65)
|
||||||
if button==1 then
|
if button==1 then
|
||||||
if os.time() - last_clicked > 1 then
|
if playing then
|
||||||
mot = mot..lettre
|
client:publish("pendu/lettre", lettre, mqtt.QOS0)
|
||||||
last_clicked = os.time()
|
else
|
||||||
else
|
if os.time() - last_clicked > 1 then
|
||||||
client:publish("pendu/mot", mot, mqtt.QOS0)
|
mot = mot..lettre
|
||||||
mot = ""
|
last_clicked = os.time()
|
||||||
|
else
|
||||||
|
client:publish("pendu/mot", mot, mqtt.QOS0)
|
||||||
|
mot = ""
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
console("Choix lettre : "..lettre)
|
console("Choix lettre : "..lettre)
|
||||||
console("Mot : "..mot)
|
if not playing then
|
||||||
|
console("Mot : "..mot)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function handle_message(len, message, topic_len, topic_name)
|
||||||
|
if topic_name == "pendu/gamestate" then
|
||||||
|
if message == "PLAYING" then
|
||||||
|
playing = true
|
||||||
|
elseif message == "WAITING" then
|
||||||
|
playing = false
|
||||||
|
mot = ""
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
client:subscribe("pendu/gamestate", mqtt.QOS0, handle_message)
|
||||||
enc = encoder.attach(pio.GPIO15, pio.GPIO2, pio.GPIO4, action)
|
enc = encoder.attach(pio.GPIO15, pio.GPIO2, pio.GPIO4, action)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue