Digital Outputs

A digital output is the most elementary feature in a microcontroller. A pin that is a digital output is set either high or low. The high value is the microcontroller's operating voltage Vcc and the low value is .

Basic Operation

In the basic operation of a digital output pin the output is either high or low.

Load the package.
In[1]:=
Click for copyable input
Turn on the LED at pin .
In[2]:=
Click for copyable input
Out[2]=
Any value greater than is considered as a high value.
In[3]:=
Click for copyable input
Out[3]=
Turn off the LED.
In[4]:=
Click for copyable input
Out[4]=
Toggle the LED on or off every second.
In[5]:=
Click for copyable input
Out[5]=

The specification "pin"->"Digital" is equivalent to "pin"-><|"Type"->"Digital"|>.

Pulse Generation

In the basic operation, the output remained high or low for the entire duration of the sampling period. However, by specifying the output type to be a "Pulse", pulses of varying widths can be generated.

The complete specification is "pin"-><|"Type"->"Pulse",spec1->val1,|>. The following specs can be given:

SamplingPeriodthe sampling period τp
"Timer"the timer to use

Pulse specifications.

By default τp is assumed to be the same as τ which is the sampling period of sys. An explicit timer can also be specified. Otherwise it will be automatically chosen.

The output signal has the following form:

4.gif

If τp is greater than τ then it effectively is τ. If Δ is greater than τp then it effectively is τp.

A pulse of width second occurs once every seconds.
In[6]:=
Click for copyable input
Out[6]=
The one-second pulse occurs twice every five seconds.
In[7]:=
Click for copyable input
Out[7]=
Use the timer to generate the pulses.
In[8]:=
Click for copyable input
Out[8]=
All the following cause the LED on pin to toggle every second.
In[9]:=
Click for copyable input
Out[9]=
In[10]:=
Click for copyable input
Out[10]=
In[11]:=
Click for copyable input
Out[11]=