pin

In this post, we will discover the options offered by the PIN functions tab on bitbloq. Let´s get started!

captura_funciones_pin

Pin declaration blocks

The first blocks that we will see are the Analogue pin and the Digital pin:

funcPin_pines

As shown, these blocks allow us to select numbers between 0 and 13 for the digital pins, and A0 and A5 for the analogue ones. By now, you will definitely know why, right? Because on the controller board, we have that number of pins:

pines_analogicos_digitales

The Analogue pin block helps you to declare which pins you have connected to analogue components… which is logical!

funcPin_analog

Likewise, the Digital pin block is used to indicate which pins are connected to digital components….

funcPin_digital

However, you can change the latter block and simply use a whole number, as shown in the image. The effect will be the same, but remember not to use it with analogue pins which require the letter at the beginning.

funcPin_digital_diff

Reading and writing on pins

The LED ON THE BOARD status… if for switching “D13” on/off, the tiny built-in LED which is connected internally to digital pin 13. You could use this small block instead of the usual LED block:

funcPin_Led13

As the name would suggest, the Read analogue PIN#… block reads the status of the analogue component connected to this pin. You could use this small block instead of a usual block for a component which has already been defined (for example, such as the potentiometer). In Arduino code this would correspond to analogRead()

funcPin_analog_read

The Read digital PIN#… block reads the status of the digital component that is connected. In Arduino code this would correspond to digitalRead()

funcPin_digital_read

As with the reading blocks, there are two blocks for writing: The Write on digital PIN… the analogue value… block generates a cyclical output signal (PWM) on this pin, which will act on certain components, such as the Servo motors or the Buzzer. So we can see an example of how it would be equivalent to using this block or the Servo block to write the angle 90:

funcPin_analog_write

In Arduino code this would correspond to analogWrite().

The Write on PIN digital… status… block writes a HIGH/LOW status, which is the same as 1/0) on the pin indicated. In Arduino code this would correspond to  digitalWrite()

funcPin_digital_write

Only one small block is left which is used to directly define the HIGH or LOW digital status, which we use for example to compare a variable::

funcPin_HL

Why use the PIN function blocks?

As we have already seen, there is much equivalence between the usual bitbloq blocks for components (Octopus bloqs, Zum bloqs…) and the ones we have just been looking at. So why use them?

The usual blocks have icons for the component they program to make them easier to identify, but there are times when we need to streamline a program so that it doesn´t show an LED image every time it is activated, or when we want to connect different modules or components.

So if we know how to measure voltage by reading an analogue pin… Ahem… I don´t know how to say this but… Did you think you could make a pepper sensor?

pimientoooooA vegetable sensor could be more useful that you might think… Or at least it looks like fun!