A switch is one of the most basic, but very important components in a circuit. When the switch is open, the circuit is broken, and no current will flow through it. When the switch is closed, the circuit is closed or made, and therefore, current will flow through it.
Switches can broadly be classified into two types:
- Mechanical Switches
- Electrical Switches
Mechanical switches can further be classified into two types:
- Maintained Switches: These switches stay in one state i.e. either ON or OFF, unless the state is changed by someone. E.g. slide switches. evive has two inbuilt 3-way slide switches. Slide switch 1 is connected to Arduino pins 40 and 41, both active high. This means that when the switch is slid up, pin 40 is high. When it slides down, pin 41 is high while both are low when the switch is in the middle. Slide switch 2 is connected to pins 42 and 43, and works in a similar manner as slide switch 1.
- Momentary switches: These switches stay in a state i.e. either ON or OFF, as long as they are activated. They come back to their original state once you release them. E.g. tactile switches. evive has two tactile switches connected to Arduino pins 38 and 39, both active high. This means that the pins are at +5V when you press the switch, and at 0V (Ground) otherwise.
How to Read evive’s Switches in PictoBlox
You can read evive’s switches in PictoBlox with the help of two blocks in the evive palette:
- tactile switch () pressed?
- slide switch () is in state () ?
Activity: Making a Torch Using Pin 13 LED
- Connect evive to your computer and open PictoBlox; if already open and working on a project, save that project. Then, click on New.
- Go to the toolbar and click on the Board menu. Then select evive as your board.
- Next, click on the Connect menu and from the fly-out menu, select the Port to which evive is connected e.g. COMXX or ttyXX.Once you select the port, the icon beside the Connect tab will become connected.
- Go to the Events palette and drag and drop the when flag clicked block.
- Next, go to the Control palette and drag and attach the forever block below the when flag clicked block.
- Then, go to the Variables palette and create a variable named Brightness and drag and drop the set () to () block inside the forever block; Brightness is set as default.
- Next, go to the evive palette and drag and drop the potentiometer () reading inside the space in the set () to () block; potentiometer 1 is set as default potentiometer.
- From the Control palette, drag and drop the if-else block below the set () to () block. Inside the diamond-shaped space, drag and drop the tactile switch () pressed? block; tactile switch 1 is set as the default switch.
- Drag and drop the set pwm pin () output as () block below the if arm of the if-else block. Set the pin as 13 and drag and drop the ()/() (division operator) block from the Operators palette in the white space.
- Inside the first space of the ()/() block, drag and drop the Brightness variable block; in the second space, drag write 4.
- Below the else arm of the if-else block, drag and drop the set digital pin () output as () block; set the pin as 13 and the output as LOW.
- Finally, outside the if-else block, drag and drop a wait () secs block from the Control palette; write 0.1 in the space.
Below is the complete script:
Click on the green flag to run the script and rotate the potentiometer to change the brightness of the LED.
Click on the red octagon, next to the green flag to stop the script.
It this tutorial, you learned how to control evive’s switches in both Stage mode and Upload mode.
Hope you had fun! 🙂