<jupyter_start><jupyter_text>PyMODI Beginner's TutorialWelcome to PyMODI!!You can do many things.  Install PyMODIAs long as you have python installed on your computer, a simple command using pip will work.    $ python -m pip install pymodi --userIf you have cloned the git repository, you can also install by    $ python setup.py install --user<jupyter_code># Installing pymodi from current Jupyter Kernel
import sys

!{sys.executable} -m pip install pymodi<jupyter_output><empty_output><jupyter_text>After installing pymodi, check if the it is installed correctly by printing out the current version of installed pymodi.Generally, importing modi package will automatically print out the version of your pymodi.<jupyter_code>import modi<jupyter_output><empty_output><jupyter_text>Great! If modi package is successfully imported, you can use pymodi to control modules.  Python 101To use PyMODI package, it is always good to remind some of the basics of python.  Hello WorldPrinting out hello world is the basic of learning every language. In Python, you can make the program to print out something by just writingprint([whatever you want])    Let's print out "Hello World" using python.<jupyter_code>print("Hello World")<jupyter_output><empty_output><jupyter_text>VariablesIn Python, the values you make can be stored in containers named variables. Variables are basically names of the containers that save your values. First, let's make a variable named num which contains the value 5.<jupyter_code>num = 5<jupyter_output><empty_output><jupyter_text>As long as you have declared a variable like this, whenever you call num, it will represent the value 5. For example, if you do num + 2, it will be 7, because you stored the value 5 in the container num.<jupyter_code>print(num + 2)<jupyter_output><empty_output><jupyter_text>What if you have quotation mark around your variables?<jupyter_code>print("num")<jupyter_output><empty_output><jupyter_text>Quotation marks mean that the value is a real text, not the variable. Any text that is not wrapped by quatation marks will be considered to have certain meaning.  ConditionalSometimes, you might want to execute some action only when some condition is met. In Python, we can do such job using "if"-statements.Python syntax for the conditionals is as follows.```pythonif :    ```These are some of the conditions you can use in python.* Logical Values: True, False* == : Equal to - We use double = to distinguish from variable declaration.* \> : Greater than* \>= : Greater or equal* < : Less than* <= : Less or equal* not : negationFor example, the following code will only execute the code when the value is bugger than 10.<jupyter_code>num = 5
if num > 10:
    print(num)
num = 15
if num > 10:
    print(num)<jupyter_output><empty_output><jupyter_text>You can also chain multiple conditionals. if statement can be linked with "elif" statements which are executed when above conditions fail. If all the if and elif conditions fail, else statment is executed.<jupyter_code>num = 15
if num > 15:
    print("Bigger than 15!!")
elif num > 10:
    print("Bigger than 10!!")
else:
    print("Less than 10!!")<jupyter_output><empty_output><jupyter_text>LoopsThe power of computer is that it can do tedious jobs easily and quickly. For example, what if you want to add all the integers from 1 to 100? If you do it by hand, it will be boring and painful, but computers are extremely good at repetetive jobs. One way of repeating something is using a for loop.  "For" loopFor loop is used when you want to do a fixed number of iterations. The syntax of the for loop is as follows.<jupyter_code>for i in range(10):
    print(i)<jupyter_output><empty_output><jupyter_text>As you can see, it will iterate through values for i in range from 0 to 9, making it overall 10 iterations. If you want to do n number of iterations, you can simply do```pythonfor i in range(n):    ``` Using the above method, you can easily add up all the numbers from 0 to 100<jupyter_code>sum = 0 # Make a variable named "sum" and it starts from value 0
for i in range(101): # This will iterate from 0 to 100
    sum = sum + i # Add i to the current running sum

print(sum) # Print the value of total sum<jupyter_output><empty_output><jupyter_text>"While" loopAnother way of iteration is using a while loop. The syntax for the while loop is as follows.```pythonwhile :    ```This loop will execute the code while the condition is True. Once the condition is False, it will break out of the loop.<jupyter_code>num = 0
while num < 10: # While num is smaller than 10
    print(num) # print the number
    num = num + 1 # and increase num by 1<jupyter_output><empty_output><jupyter_text>You can also manually break out of the loop by the "break" statement<jupyter_code>num = 0
while True: # This runs forever
    num = num + 1 # Increase num by 1
    if num > 10: # If num is bigger than 10,
        break # Break out of the loop
print(num) # Print out the final value of num<jupyter_output><empty_output><jupyter_text>Let's do the addition with while loop this time! Complete the following code to correctly add all the numbers from 0 to 100.<jupyter_code>sum = 0

while <condition>:
    <do something>

print(sum)<jupyter_output><empty_output><jupyter_text>Your First PyMODI Script!!Now you can do python!! Using the skills you have learned above, you can control MODI modules using python.PyMODI Package offers basic functinality of each modules, which can be found on this document.https://pymodi.readthedocs.io/en/master/modi.module.htmlsubpackagesFollow the below tutorial to make your first pymodi project!  Making a MODI Object Before you start, connect one led module and one button moduleWhen MODI modules are connected to your computer, you can control the modules by creating a MODI object.Let's make a MODI object named "bundle."<jupyter_code>import modi

bundle = modi.MODI()<jupyter_output><empty_output><jupyter_text>The MODI modules connected to the Network module will appear automatically. Once you make a MODI object, you can access the modules as follows.<jupyter_code>modules = bundle.modules
print(modules)<jupyter_output><empty_output><jupyter_text>You can also access individual modules!<jupyter_code>print(bundle.leds)
print(bundle.buttons)<jupyter_output><empty_output><jupyter_text>You can access individual modules by specifying the index of the module.<jupyter_code>led = bundle.leds[0] # The first led module in bundle.leds
button = bundle.buttons[0] # The first button module in bundle.buttons
print(led)
print(button)<jupyter_output><empty_output><jupyter_text>Great!! Now you have your led module and button module.You can make your button to show green light by changing led.green.The document explains how you can use led module.https://pymodi.readthedocs.io/en/master/modi.module.output_module.htmlmodule-modi.module.output_module.led<jupyter_code>led.green = 255 # Change the RGB value of green to 255<jupyter_output><empty_output><jupyter_text>You can also set the custom color.<jupyter_code>led.rgb = 148, 0, 211 # Set the RGB value to violet color rgb(148, 0, 211)<jupyter_output><empty_output><jupyter_text>Just changing the color is tedious. Let's make it blink 5 times!!<jupyter_code>import time

led.turn_off() # First, turn the led off

for i in range(5): # 5 Times
    led.blue = 255 # Set the color to blue
    time.sleep(1) # Wait 1 second
    led.turn_off() # Turn it off again
    time.sleep(1) # Wait 1 second<jupyter_output><empty_output><jupyter_text>Let's make thing a bit more interesting. Using the button module, we can make a system in which led lights up whenever button is pressed.<jupyter_code>import time

while True: # This runs forever
    if button.pressed: # If your button is pressed,
        led.turn_on() # Turn on the led
    elif button.double_clicked: # or if button is double clicked,
        break # Break out of the loop
    else: # Otherwise,
        led.turn_off() # Turn off the led
    time.sleep(0.1) # Wait 0.1 seconds<jupyter_output><empty_output><jupyter_text>You can do even cooler things. Let's make a system in which the led shows green light when button is toggled and shows red light when button is not toggled.<jupyter_code># Complete the following code

import time

while True:
    if <condition>:
        <do something>
    else:
        <do something>
    
    if button.double_clicked:
        break
    time.sleep(0.1)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07136094674556213, 'fraction_numerical': 0.013136094674556212, 'mean_word_length': 4.745071380013596, 'pattern_counts': {'":': 0, '<': 97, '<?xml version=': 0, '>': 101, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 1, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '22', 'dir': 'jupyter-structured-clean-dedup', 'id': '316502', 'license': 'MIT', 'n_tokens_mistral': 2567, 'n_tokens_neox': 2412, 'n_words': 1091, 'path': 'tutorial/[ENG]pymodi_tutorial.ipynb', 'repo_name': 'jha929/pyMODI', 'size': '8450'}