mardi 25 mai 2021

Add two while loop with cwiid module - Raspberry Pi

appreciate if someone able to assist me on my script. I'm planning to write a script which able to switch between loop. Currently, I have TWO(2) while loop. Thus, I add 'if' statement to create a condition which I hope the programmed able to differentiate which loop to run. BUT when I run the programmed, I just able to connect the wiimote but unable run the conditions and the while loop. Appreciate if someone could point out or assist me to make my script right. Kind new with programming language. Still experimenting myself.

import cwiid

print("Press and hold 1+2 buttons on your Wiimote simultaneously")
wii = cwiid.Wiimote()
print("Connection established")

wii.rpt_mode = cwiid.RPT_BTN

while True:

    buttons = wii.state["buttons"]

    if (buttons & cwiid.BTN_MINUS):
        wii.rpt_mode = cwiid.RPT_BTN
        condition_1 = buttons & cwiid.BTN_MINUS
        
        while condition_1 == buttons & cwiid.BTN_MINUS:
            if (buttons & cwiid.BTN_LEFT):
                print("LEFT")

            if (buttons & cwiid.BTN_RIGHT):
                print("RIGHT")

            if (buttons & cwiid.BTN_UP):
                print("UP")

            if (buttons & cwiid.BTN_DOWN):
                print("DOWN")

            if (buttons & cwiid.BTN_B):
                print("B")

    if (buttons & cwiid.BTN_PLUS):
        wii.rpt_mode = cwiid.RPT_BTN | cwiid.RPT_ACCC
        condition_2 = buttons & cwiid.BTN_PLUS

        while condition_2 == buttons & cwiid.BTN_PLUS:
            print(wii.state['acc'])
            time.sleep(0.01)

Aucun commentaire:

Enregistrer un commentaire