===== Disco Addons ===== This page will help you get started with the disco add ons with Marty using the python library. Before we get started, make sure you have [[https://userguides.robotical.io/martyv2/userguides/python|python installed]] and [[https://userguides.robotical.io/martyv2/userguides/sensorsandaddons/discomarty|have set up your disco add ons]]. ===== Get Connected ===== First you must always import Martypy and establish connection to your Marty. Follow the code below to connect your Marty. import martypy # USB connection # change "COM1" on this next line to specify the USB port you want to use # comment this line out to use WiFi my_marty = martypy.Marty("USB") # WiFi connection # uncomment this and change the IP address to your Marty's to use WiFi # my_marty = martypy.Marty("wifi", "192.168.0.5") You should now be able to play with your disco add ons using the three functions below. ===== Disco Pattern ===== The function **//disco_named_pattern//** allows you to set your disco add ons to a built-in pattern of lights. You will need to pass in your choice of pattern and specify the add on you would like to turn on, which is outlined below. **disco_pattern**(add_on, pattern): * **add_on**: This allows you to specify the specific add on on your marty that you would like to light up. [[#passing_in_your_add_ons|Click Here]] to learn how to pass in your add ons.\\ \\ * **pattern**: choose the pattern you would your add on to turn to. There are three options: **show-off** or **pinwheel** or **off** Try this function using the code below to set all of your disco add ons to pattern **show-off**. my_marty.disco_named_pattern(my_marty.Disco.ALL, "show-off") ===== Choose Your Own Colors! ===== The function **//disco_color//** allows you to turn on and set your disco add ons to the color of your choice. **disco_color**(color, add_on, region, api): * **color**: choose the color you would like your disco add ons to be. You can pass in either a hex code, RGB tuple, or a string calling one of the built in colors: white, red, blue, yellow, green, teal, pink, purple, and orange.\\ \\ //You can use [[https://g.co/kgs/Na34hP|this color picker]] to find the hex code or RGB tuple of the color of your choice.// \\ \\ * **add_on**: This allows you to specify the specific add on on your marty that you would like to light up. [[#passing_in_your_add_ons|Click Here]] to learn how to pass in your add ons.\\ \\ * **region**: This allows you to specify the specific side of Marty’s eye, arm, or leg that you would like to light up. Revisit [[https://userguides.robotical.io/martyv2/userguides/sensorsandaddons/discomarty|setting up your disco add ons]] for a refresher on these regions. You have the option to pass in 0, 1, or 2. * **api** *: This option lets you choose how you'd like to talk to Marty. You have two choices: 'led' or 'raw_query'. The 'led' option is supported by newer Marty versions (2022 onwards), while the 'raw_query' works with older Marty versions. Try this function using the code below to set all of your disco add ons to teal. my_marty.disco_color('teal', my_marty.Disco.ALL, api='led') You can also get the same color by passing in a hex code or RGB tuple. See the code samples below on how you would pass the color **teal** as a hex code or RGB tuple, respectively. my_marty.disco_color('#02d1bc', my_marty.Disco.ALL, api='led') my_marty.disco_color((2, 209, 188), my_marty.Disco.ALL, api='led') ===== Turning Off Your Disco Addons ===== The function **//disco_off//** allows you to turn off the disco add on of your choice. You can specify which specific add on you want to turn off, or turn off multiple at a time. **disco_off**(add_on, api): * **add_on**: This allows you to specify the specific add on on your marty that you would like to turn off. [[#passing_in_your_add_ons|Click Here]] to learn how to pass in your add ons. * **api** *: This option lets you choose how you'd like to talk to Marty. You have two choices: 'led' or 'raw_query'. The 'led' option is supported by newer Marty versions (2022 onwards), while the 'raw_query' works with older Marty versions. Try this function using the code below to turn off all of your disco add ons. my_marty.disco_off(api = 'led') \\ ===== Party Marty! ===== Now we can use our disco functions to make Marty party! Follow the code below to light up Marty's disco add ons and make Marty dance. from martypy import Marty my_marty = Marty("wifi", "192.168.0.42") # Replace 192.168.0.42 by your Marty's IP my_marty.disco_color('blue', my_marty.Disco.FEET, api='led') my_marty.disco_named_pattern(my_marty.Disco.EYES, pattern="show-off") my_marty.disco_named_pattern(my_marty.Disco.ARMS, pattern="pinwheel") my_marty.dance() my_marty.disco_off(api='led') \\ ===== Passing in Your Add Ons ===== When passing in your add ons, you have two options: 1. You can pass in a string of the name of the add on that you would like to call the function on. You can find the names of all your add ons by visiting the Scratch app and going to **Configure --> ADD-ONS**. Don't forget to disconnect the app after in order to connect with your Marty in python! 2. You can also pass in groupings of the add ons so you can call your chosen function on multiple add ons at a time! We have groupings for: * my_marty.Disco.EYES * my_marty.Disco.FEET * my_marty.Disco.ARMS * my_marty.Disco.ALL Pass in one the variables above in the **add_on** parameter of your chosen function when you would like to call a pair or all of the add ons.