-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Description
I thought that when I have this code it should switch from press to release and back.
Instead it does only work on the flanks. So when I press it fires. When I release it does nothing. When I press again it fires the release.
use rust_gpiozero::{Button, Debounce, LED};
use std::time::Duration;
fn main() {
// Led output
let led = LED::new(17);
// Create a button which is attached to Pin 27
let mut button = Button::new(27)
// Add debouncing so that subsequent presses within 100ms don't trigger a press
.debounce(Duration::from_millis(100));
led.off();
println!("Ready for input changed");
button.wait_for_press(None);
println!("Button status is pressed {}", button.is_active());
led.on();
button.wait_for_release(None);
println!("Button status is released {}", button.is_active());
led.off();
}Output is:
< comments between here >
Ready for input changed => Led is off
< Press button >
Button status is pressed false < Why is status false since it is pressed? >
< Release button >
< Nothing happens wait for 2 seconds >
<Press button >
Button status is released false
I try to make the same example as in Python:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
# LED
GPIO.setup(17,GPIO.OUT)
# Input
GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.output(17,GPIO.HIGH)
while True:
input_state = GPIO.input(27)
if input_state == False:
GPIO.output(17,GPIO.LOW)
else:
GPIO.output(17,GPIO.HIGH)
time.sleep(0.1)Note that in Python I use the GPIO.PUD_UP
Metadata
Metadata
Assignees
Labels
No labels