This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
university:tools:python-tutorial:tutorial2-read-buttons [16 Sep 2015 15:20] – created Doug Mercer | university: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: | ||
+ | < | ||
+ | # 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, | + | Pio0 = devx.ctrl_transfer(0xc0, |
+ | </ | ||
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 |
{{ : | {{ : |