Turn LEDs on and off with buttons

login logout

Blink and pulse LEDs with buttons

login logout
arrow_forward     arrow_forward

play_circle stop_circle
def excited(): # Your first mood
   purple_led.on() # Turn on
   blue_led.off() # Turn off
                        
def worried(): # Your second mood
   purple_led.off() # Turn off
   blue_led.on() # Turn on

excited_button.when_pressed = excited
worried.when_pressed = worried

lightbulb .when_pressed

.when_pressed will call the function when the button is pressed.

bug_report Don't use brackets ()

When you call the function e.g. excited, don't use brackets at the end.


arrow_forward     arrow_forward    

play_circle stop_circle
def available(): # First mood
   red_led.off() # Turn red LED off
   green_led.blink() 
   
def busy(): # First mood
   green_led.off() # Turn green LED off
   red_led.pulse()

available_button.when_pressed = available
busy_button.when_pressed = busy

lightbulb .when_pressed

.when_pressed will call the function when the button is pressed.

bug_report Don't use brackets ()

When you call the function e.g. excited, don't use brackets at the end.