The Inputs Module of Dabble App has 3 input types:
- Slide Switch
- Tactical Switch
Each type has 2 inputs.
The potentiometer is the first input type from left. It works similar to a real potentiometer, by providing a variable output value between 0 to 1023. You can change the value by rotating it. The value is sent to the hardware device when the potentiometer is moved.
The Slide Switch is the second input type from left. It has 3 states – Left, Right, and Off. By default when the module is opened the slide switch is in Off state. You can change the state of the slide switch by clicking on the desired state.
At all time only one state will be active and the other two states will be inactive. The state of the slide switch is sent to Arduino, only when there is a change in the active position.
The tactile switch is the third and the last module in the Input module. It senses whether the user has pressed on the switch or not. It a momentary-type switch.
Arduino IDE Functions
To include the Inputs module in the Arduino program, you have to include the following header:
After defining the above mention headers, you have to include the dabble library:
Enabling Bluetooth Communication
To enable Bluetooth communication, you have to initialize serial communication using the following code:
For evive and Arduino Mega, Uno and Nano
Here Baud_Rate is the baud rate set for the Bluetooth module. With evive, you normally get 115200 baud rate modules.
In place of Bluetooth_Name enter name that you want to keep for Bluetooth of ESP32. Default name given in the library is “MyEsp32”.
Refreshing the data
To refresh the data that the device has got from the mobile app, you have to use the following line of code:
The following functions are available for the input module:
- Inputs.getPot1Value(): This function returns the potentiometer value 1 reading from the app. The returned value ranges from 0 to 1023.
- Inputs.getPot2Value(): This function returns the potentiometer value 2 reading from the app. The returned value ranges from 0 to 1023.
- Inputs.getSlideSwitch1Value(): This function returns the slide switch 1 state. These are the following possibilities for the returned value:
- 1 when the slide switch is in the left position.
- 2 when the slide switch is in the right position.
- 0 when the slide switch is in the center position.
- Inputs.getSlideSwitch2Value(): This function returns the slide switch 2 state.
- Inputs.getTactileSwitch1Value(): This function tells whether the tactile switch 1 is pressed or not. These are the following possibilities for the returned value:
- 1 when the switch is pressed.
- 0 when the switch is not pressed.
- Inputs.getTactileSwitch2Value(): This function tells whether the tactile switch 2 is pressed or not.
PictoBlox (Scratch) Blocks
You can access the controls of Inputs in the following ways:
Slide Switch: To access a slide switch, you have to use a boolean block “is slide switch () ()?”
You can choose 1 or 2, Left or Right from the drop-down.
Tactile Switch: A boolean block “is tactile switch () pressed?” will enable you to access the tactile switch.
This example code prints the current state of all the potentiometers, slide switches and tactile switches on Serial Monitor using the functions explained above. Board wise code is given below. You can also access the code by navigating to “File>>Examples>>Dabble>>” and selecting “Inputs” example as per your board.
Arduino Mega, Uno, and Nano
Controlling PWM pins using potentiometers.
Example Slide Switch
Setting digital pins using slide switches.
Example Tactile Switch
Setting digital pins using Tactile switches.
Depending upon your board type you can use different head blocks and along with it you also have to use “set bluetooth baudrate” as well, whereas rest of the script remains same. Currently, PictoBlox supports evive and Arduino Uno, Nano, and Mega boards. Support for ESP32 board will be added soon.