From c788dd71a3ff5c850c81f3cce4e6fc66879a33f2 Mon Sep 17 00:00:00 2001 From: "Mark A. Yoder" <Mark.A.Yoder@Rose-Hulman.edu> Date: Wed, 14 Jun 2023 14:07:50 -0400 Subject: [PATCH] Starting to remove JavaScript and add C --- .../beaglebone-cookbook/02sensors/sensors.rst | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/books/beaglebone-cookbook/02sensors/sensors.rst b/books/beaglebone-cookbook/02sensors/sensors.rst index 877ec229..7e50b75a 100644 --- a/books/beaglebone-cookbook/02sensors/sensors.rst +++ b/books/beaglebone-cookbook/02sensors/sensors.rst @@ -126,7 +126,7 @@ By default, it takes you to your home directory. Notice that the prompt has chan .. code-block:: - root@beaglebone:~/boneSensors# ./pushbutton.js + debian@beaglebone:beaglebone-cookbook/code/02sensors$ ./pushbutton.py data= 0 data= 0 data= 1 @@ -178,13 +178,13 @@ reads GPIO port *P9_42*, which is attached to the pushbutton. :download:`pushbutton.py <../code/02sensors/pushbutton.py>` -.. _js_pushbutton_code: +.. _c_pushbutton_code: -.. literalinclude:: ../code/02sensors/pushbutton.js - :caption: Monitoring a pushbutton (pushbutton.js) +.. literalinclude:: ../code/02sensors/pushbutton.c + :caption: Monitoring a pushbutton (pushbutton.c) :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`. 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 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 :ref:`js_pushbutton_fig`, change *P9_42* to *P9_26* which is gpio *14*. -- GitLab