add sample to turn LED on and off via button
This commit is contained in:
		
							parent
							
								
									41a4f7307a
								
							
						
					
					
						commit
						3f2a0db9a3
					
				@ -1,11 +1,10 @@
 | 
			
		||||
from gpiozero import Button
 | 
			
		||||
from gpiozero import LED
 | 
			
		||||
from signal import pause
 | 
			
		||||
 | 
			
		||||
def say_hello():
 | 
			
		||||
    print("Hello!")
 | 
			
		||||
 | 
			
		||||
led_green = LED(18)
 | 
			
		||||
button = Button(23)
 | 
			
		||||
 | 
			
		||||
button.when_pressed = say_hello
 | 
			
		||||
    led_green.toggle()
 | 
			
		||||
 | 
			
		||||
pause()
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										11
									
								
								2_BUTTON/button_turnOnLED.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								2_BUTTON/button_turnOnLED.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
from gpiozero import Button
 | 
			
		||||
from signal import pause
 | 
			
		||||
 | 
			
		||||
def say_hello():
 | 
			
		||||
    print("Hello!")
 | 
			
		||||
 | 
			
		||||
button = Button(23)
 | 
			
		||||
 | 
			
		||||
button.when_pressed = say_hello
 | 
			
		||||
 | 
			
		||||
pause()
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user