I would appreciate if someone is able to assist me on my script. I'm planning to write a script which is able to switch between loop. Currently, I have TWO(2) while loop. Thus, I add an 'if' statement to create a condition which I hope the program is able to differentiate which loop to run. BUT when I run the program, I'm just able to connect the Wiimote but unable run the conditions and the while loop. I would appreciate if someone could point out or assist me to make my script right. I'm kinda 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)
After digging and do some research. Manage to reach the goal. Below are the code I write and manage to run.