CPX Switch code

Microsoft's MakeCode platform for easy blocks-style programming

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Yeetmaster4628
 
Posts: 1
Joined: Fri May 05, 2023 11:18 pm

CPX Switch code

Post by Yeetmaster4628 »

I can't solve this coding problem. I am making a metronome and I am making it so that when the switch is on the left hand side, it repeats a certain pattern for 1e+150 times and when the switch is on the right side, it repeats another pattern for 1e+150 times. But whenever I switch the switch left to right and vice versa, the two separate codes overlap. I want to make it so that when the switch is on the left hand side, only the code for the "on switch moved left" is being executed and when the switch is moved to the right hand side, it completely stops the "on switch moved left" codes and just executes the "on switch moved right" codes. Please help ASAP.
Attachments
Screen Shot 2023-05-06 at 12.24.27 PM.png
Screen Shot 2023-05-06 at 12.24.27 PM.png (261.02 KiB) Viewed 954 times

User avatar
johnpark
 
Posts: 985
Joined: Wed Mar 25, 2009 2:15 pm

Re: CPX Switch code

Post by johnpark »

You could create a conditional if statement that essentially stops playback on one pattern when you flip the switch and vice versa. Here's a simplified version of it:
Screenshot 2023-05-19 at 12.50.10 PM.jpg
Screenshot 2023-05-19 at 12.50.10 PM.jpg (95.93 KiB) Viewed 893 times

Locked
Please be positive and constructive with your questions and comments.

Return to “MakeCode”