Digital Input/Output Pins
Under the Magic Lid of evive, there are 28 Digital 5V Input and Output (I/O) pins.
Controlling digital pins in Arduino IDE
Using the digital pin as Input
evive digital I/O pins are default assigned as inputs and hence they don’t need to be explicitly declared as input initially in the program. But it is advisable that one should declare each and every pin as input or output for consistency.
Digital Input pins can be configured as pinMode(pin, INPUT), where the pin is the digital pin number you want to initialise. Often it is useful to steer an input pin to a known state if no input is present. This can be done by adding a pullup resistor (to +5V), or a pulldown resistor (resistor to ground) on the input. A 10K resistor is a good value for a pullup or pulldown resistor.
If the pin is configured as INPUT_PULLUP during initialisation, it inverts the behaviour of the INPUT mode, where HIGH means the sensor is OFF and LOW means the sensor is ON. It is because there are 20K pullup resistors built into the Atmega chip that can be accessed from software.
Using the digital pin as Output
Pins can be configured as OUTPUT with pinMode(pin, OUTPUT), where the pin is the digital pin number you want to initialise as output. These pins are also in a low-impedance state. This means that they can provide a substantial amount of current to other circuits. Atmega pins can source (provide positive current) or sink (provide negative current) up to 40 mA (milliamps) of current to other devices/circuits. This is enough current to brightly light up an LED (don't forget the series resistor), or run many sensors, for example, but not enough current to run most relays, solenoids, or motors.
Short circuits on digital pins, or attempting to run high current devices from them, can damage or destroy the output transistors in the pin, or damage the entire Atmega chip. Often this will result in a "dead" pin in the microcontroller but the remaining chip will still function adequately. For this reason, it is a good idea to connect OUTPUT pins to other devices with 470Ω or 1kΩ resistors, unless maximum current draw from the pins is required for a particular application.
Using digitalWrite() function in Arduino IDE, you can write a digital pin, to a HIGH or LOW value.
If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the corresponding value: 5V for HIGH, 0V for LOW.
If the pin is configured as an INPUT, digitalWrite() will enable (HIGH) or disable (LOW) the internal pull-up on the input pin. It is recommended to set the pinMode() to INPUT_PULLUP to enable the internal pull-up resistor.
The analog input pins can also be used as digital pins, referred to as A0, A1, etc.
Using digitalRead() function in Arduino IDE, you can read the value from a specific digital pin as HIGH or LOW.
Controlling digital pins in Scratch
Set digital pin output block is used for digital output on a digital pin. It sets the digital state of specified digital pin either “High” or “Low”. If the output is High, the pin will be at 5V and if the output is Low the pin will be at 0V.
Controlling Pin 13 LED using Space key. If the output is High, LED glows, and if the output is Low, LED turns off.
Read digital pin () block available in Arduino Extension is used for digital read in Scratch. It reads the state of the digital pin on evive (“High” or “Low”). If the state of the pin is “High”, it returns True, else False.
Available pins for digital read in evive:
- 26 digital pins available for user (2-27)
- Two tactile switches (Tactile_Swithc_1 & Tactile_Switch_2)
- Two slide switches (Slide_Switch_1_Dir_1, Slide_Switch_1_Dir_2, Slide_Switch_2_Dir_1 and Slide_Switch_2_Dir_2).
You can choose these pins from the drop down menu.
This block can be used in Arduino Mode as well as in Scratch Mode.
Displaying the state of the tactile switch in Scratch Mode.
Introduction You must have played Air Hockey! Pay few $$dollars$$ to the gaming zone and just start scoring goals to beat your friends. Isn’t it