# QR code detector

We suggest to use a printed QR code, about 15x15 cm. The QR code that we used for this project is the Misty Lessons one.

This project will only work in the Misty Desktop Environment because we will modify the events file.

Open the folder containing the Python-SDK that you use for the [desktop environment](https://github.com/MistyCommunity/Python-SDK).\
The folder should look like this one.

<figure><img src="/files/GrGYa0rpHOz6b2qC1iKC" alt="" width="563"><figcaption></figcaption></figure>

Open the folder MistyPy, open the file [Events.py](http://events.py/) in Visual Studio code and modify the Events class to add the QRdetection Event.<br>

<figure><img src="/files/kkNHzjgDDyg64DGxomx3" alt="" width="563"><figcaption></figcaption></figure>

Now you're ready to use Misty's scanning QR capabilities in Python.

#### Python Code

```python
from mistyPy.Robot import Robot
from mistyPy.Events import Events

misty = Robot("YOUR_ROBOT_IP_ADDRESS") #your Robot IP Address

misty.change_led(0, 255, 0)
misty.move_head(0, 0, 0)

misty.start_qr_tag_detector()

def code(data):
    print(data) #this shows all the data related to the event
    print(data['message']['decodedInfo'])

misty.register_event(event_name='qrtag_event', event_type=Events.QrTagDetection, callback_function=code, keep_alive=True, debounce = 500)

misty.keep_alive()
```

In the first part of the code, we set the robot by initializing the libraries, calling it and setting it in a standard position.\
Once these actions are done we start the event like any other event in the Misty world by calling the action .*start\_qr\_tag\_detector().*

We create a function that will handle the data read by scanning the QR code. We can then register the event and then keep it alive.

You can insert if statements to handle different QR codes and assign to each a different Misty action.

For example, if we want Misty to turn her RGB LED purple when she recognizes the QR code of the Misty lessons or have the  RGB LED red when she doesn't, our function can look like this one:&#x20;

```python
def code(data):
    print(data['message']['decodedInfo'])
    if data['message']['decodedInfo'] == 'unknown person': #intruder
        misty.change_led(100, 70, 160)
    else :
        misty.change_led(255, 0, 0)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lessons.mistyrobotics.com/python-projects/qr-code-detector.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
