Please select To the mobile version | Continue to access the desktop computer version

OrangePi

 Login            
 Register            
Search
Hot search: orangepi
View: 828|Reply: 1

How to use push buttons with Orange ?

[Copy link]

3

Threads

3

Posts

27

Credits

Novice

Rank: 1

Credits
27
Post time 2019-9-2 21:50:50 | Show all posts |Read mode
Hi there,

In my project, I need 3 push buttons attached to OrangePi.
Theses buttons are tied to changing the behavior of the software.

When someone press (and release) one of theses buttons, the original configuration is restaured (whatever that means).
When another button is pressed a pre-configured mode is setup.
And when a third button is pressed another configuration is activated. You got the ideia.

I am using the 3.3V GPIO pins to plug a push button.
A infinite loop on a python program detects when a specific button is pressed.
  1. while True:
  2.     if (gpio.input(23) == 1 ):
  3.         print ("button was pressed. Do something usefull")
  4.     time.sleep (1)
  5. gpio.cleanup ()
Copy the Code
It is working.
But the question is about the right way of doing things. Is the infinite loop the best approach ? Is it not a time consuming operation ?
I was looking for a event based, kernel fired approach...Is it possible ?
Related to that, how to implement a hardware reset button that works even when the OS is borked ? Kind of a  watchdog reset ? Much like the reset button we have on our computers...? Is it possible ?

best regards

23

Threads

52

Posts

697

Credits

Senior member

Rank: 4

Credits
697
Post time 2019-11-1 00:16:09 | Show all posts
It is best to activate the internal pull-up, set the debounce and switch to GND.
You have to log in before you can reply Login | Register

Points Rules

Archiver|Mobile edition|Darkroom|OrangePi En ( 粤ICP备14086627号-2

2019-12-12 19:33 GMT+8 , Processed in 0.025127 second(s), 22 queries .

Powered by Discuz! X3.2

© 2014-2015 orangepibbs en.

Quick Reply To Top Return to the list