Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
Commit c788dd71 authored by Mark Yoder's avatar Mark Yoder Committed by Robert Nelson
Browse files

Starting to remove JavaScript and add C

parent f63f7aa3
Branches
No related merge requests found
...@@ -126,7 +126,7 @@ By default, it takes you to your home directory. Notice that the prompt has chan ...@@ -126,7 +126,7 @@ By default, it takes you to your home directory. Notice that the prompt has chan
.. code-block:: .. code-block::
root@beaglebone:~/boneSensors# ./pushbutton.js debian@beaglebone:beaglebone-cookbook/code/02sensors$ ./pushbutton.py
data= 0 data= 0
data= 0 data= 0
data= 1 data= 1
...@@ -178,13 +178,13 @@ reads GPIO port *P9_42*, which is attached to the pushbutton. ...@@ -178,13 +178,13 @@ reads GPIO port *P9_42*, which is attached to the pushbutton.
:download:`pushbutton.py <../code/02sensors/pushbutton.py>` :download:`pushbutton.py <../code/02sensors/pushbutton.py>`
.. _js_pushbutton_code: .. _c_pushbutton_code:
.. literalinclude:: ../code/02sensors/pushbutton.js .. literalinclude:: ../code/02sensors/pushbutton.c
:caption: Monitoring a pushbutton (pushbutton.js) :caption: Monitoring a pushbutton (pushbutton.c)
:linenos: :linenos:
:download:`pushbutton.js <../code/02sensors/pushbutton.js>` :download:`pushbutton.c <../code/02sensors/pushbutton.c>`
Put this code in a file called *pushbutton.py* following the steps in :ref:`sensors_getting_started`. Put this code in a file called *pushbutton.py* following the steps in :ref:`sensors_getting_started`.
In the VSC *bash* tab, run it by using the following commands: In the VSC *bash* tab, run it by using the following commands:
...@@ -202,6 +202,18 @@ The command runs it. Try pushing the button. The code reads the pin and prints i ...@@ -202,6 +202,18 @@ The command runs it. Try pushing the button. The code reads the pin and prints i
You will have to press ^C (Ctrl-C) to stop the code. You will have to press ^C (Ctrl-C) to stop the code.
If you want to run the C version do:
.. code-block:: bash
bone$ gcc -o pushbutton pushbutton.c -lgpiod
bone$ ./pushbutton
data = 0
data = 0
data = 1
data = 1
^C
If you want to use the magnetic reed switch wired as shown in If you want to use the magnetic reed switch wired as shown in
:ref:`js_pushbutton_fig`, change *P9_42* to *P9_26* which is gpio *14*. :ref:`js_pushbutton_fig`, change *P9_42* to *P9_26* which is gpio *14*.
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment