➕Misty to Arduino
In this project, you’ll use MIsty’s bump sensor to trigger Arduino to change its LEDs.
Last updated
In this project, you’ll use MIsty’s bump sensor to trigger Arduino to change its LEDs.
Last updated
Misty’s Arduino backpack
2 LEDs
2 resistance 330 Ω
Some wires of different lengths.
In this code, you can see the same structure as the previous one: A void setup and a void loop. In the void setup, you open the serial, set the maximum milliseconds to wait for serial data (the default is 1000 ms) and define the pins that you’ll use in the code.
In the void loop, the first thing you should do is to check if there is something written in the serial. The second step is to read the string that exists in the serial by defining it. To read strings completely you can use the character “\n” at the end, which represents the new line character/enter. Once you get the string the last part is to define all the conditions you can have.
For example :
If the string you get from Misty is “red” turn on the red LED and write in the Arduino’s serial “red on”. The Serial.println at the end of each if condition is not necessary for the code but it’s helpful for the programmer who can see what’s happening in the code from the serial monitor in the Arduino IDE.
To write in the serial you don’t need an event, but Misty has it as an element in her Python API. This code is a normal Bump sensor event that associates to each bump sensor a string to write in the serial.
For example:
If the bump front right sensor is contacted turn Misty’s chest LED red and write “red\n” in the serial. Arduino will receive the string from the serial, read it until the “\n” character and select the function from its list.