Wiki

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
university:tools:python-tutorial:tutorial2-read-buttons [16 Sep 2015 15:20] – created Doug Merceruniversity:tools:python-tutorial:tutorial2-read-buttons [12 Sep 2019 20:26] – [Procedure:] Doug Mercer
Line 18: Line 18:
    
 To get an input state: To get an input state:
 +<code> 
 +# assign digital pins 
 +PIO_0 = 28 
 +PIO_1 = 29 
 +PIO_2 = 47 
 +PIO_3 = 3 
 # get state of PIO0\\ # get state of PIO0\\
-Pio0 = devx.ctrl_transfer(DevID, 0xc0, 0x91, 0, 0, 0, 1, 100) +Pio0 = devx.ctrl_transfer(0xc0, 0x91, PIO_0, 0, 0, 1, 100) 
 +</code>
 The value after 0x91 is the number of the I\O pin. The rest of the values are the always the same and should not be changed. The value after 0x91 is the number of the I\O pin. The rest of the values are the always the same and should not be changed.
  
Line 44: Line 49:
 ====Procedure:==== ====Procedure:====
  
-Open the read_buttons.py Python program in your favorite editor. The IDLE that comes with Python is handy because you can run the program directly from there. Scroll down to the Digital_in() function. You will see a series of if statements that read the state of an input pin, high or low depending on which of the buttons is pressed. The program then changes the background color of label for each input pin based on what was read. The Digital_in() function is called continuously whenever the Run button is selected.+Open the read_buttons.py Python program (from {{ :university:tools:python-tutorial:read_buttons.zip |read_buttons.zip}}) in your favorite editor. The IDLE that comes with Python is handy because you can run the program directly from there. Scroll down to the Digital_in() function. You will see a series of if statements that read the state of an input pin, high or low depending on which of the buttons is pressed. The program then changes the background color of label for each input pin based on what was read. The Digital_in() function is called continuously whenever the Run button is selected.
  
 {{ :university:tools:python-tutorial:python_tutorial2_f2.png?200 |}} {{ :university:tools:python-tutorial:python_tutorial2_f2.png?200 |}}
university/tools/python-tutorial/tutorial2-read-buttons.txt · Last modified: 20 Jun 2022 20:39 by Doug Mercer