Im Using Pyfirmata For A While, And I Want To Connect A Joystick Button On It, I Made The Code (AI) And It Didnt Work, It Keeps Changing Like "True, False, False, True, True..." and doesnt do nothing, heres my python code (PS: im using standart_firmata)
from pyfirmata import *
import time
import speech_recognition as sr
import random
from math import *
class IA:
def __init__(self, board, maquina, analogx, analogy) -> None:
self.board = board
self.maquina = maquina
self.analogx = analogx
self.analogy = analogy
self.button = self.board.get_pin("d:8:i")
self.previous_button_state = 0
self.sr = sr.Recognizer()
def record(self):
with self.sr.Microphone() as source:
print("gravando")
self.sr.adjust_for_ambient_noise(source)
audio = self.sr.listen(source)
try:
frase = sr.recognize_google(audio,language='pt-BR')
frase = frase.lower()
pass
except sr.UnkownValueError:
self.maquina.say("Não Entendi")
self.maquina.runAndWait()
self.main()
if (frase == "olá"):
sentences = ["Olá","Opa","Eae","Oi","Haha Eae"]
sentence = random.choice(tuple(sentences))
self.maquina.say(sentence)
self.maquina.runAndWait()
def main(self):
while True:
print(floor(self.button.read()))
time.sleep(1)
def greet(self):
self.board.digital[2].write(135)
self.maquina.say("Olá! Sou Jesse, Bem Vindo Ao Meu Sistema")
self.maquina.runAndWait()
self.board.digital[2].write(90)
self.maquina.say("Posso Fazer Varias Coisas")
self.maquina.runAndWait()
self.board.digital[2].write(135)
self.maquina.say("Apenas Aperte No Botão Do Joystick E Fale Oque Quer! Divirta-se")
self.maquina.runAndWait()
self.board.digital[2].write(90)
self.board.digital[3].write(75)
self.main()
If anyone can help me, i will be grateful, thanks.