title: python - how to make a function to check if button pressed once or twice?
body: <p>I am trying to make a task for school with Python. But the problem is that I don't understand how the following function works: So we are trying to make a smarthome with lights and relays(now we use LED). If we push the button once, lights go on, if we push twice within 1.5sec: all lights go on and so on...
  Also we have to make a function when lights are already on...</p>
  
  <p>So my question is "How do I tell or let python know that I pushed the button once or twice or more or hold it so it does a function?"</p>
  
  <p>This is my code (we work with on the air uploading to Raspberry Pi</p>
  
  <pre><code>#!/usr/bin/env
  
  __author__ = "Zino Henderickx"
  __version__ = "1.0"
  
  # LIBRARIES
  from gpiozero import LED
  from gpiozero import Button
  from gpiozero.pins.pigpio import PiGPIOFactory
  import time
  
  IP = PiGPIOFactory('192.168.0.207')
  
  # LED's
  LED1 = LED(17, pin_factory=IP)
  LED2 = LED(27, pin_factory=IP)
  LED3 = LED(22, pin_factory=IP)
  LED4 = LED(10, pin_factory=IP)
  
  
  # BUTTONS
  BUTTON1 = Button(5, pin_factory=IP)
  BUTTON2 = Button(6, pin_factory=IP)
  BUTTON3 = Button(13, pin_factory=IP)
  BUTTON4 = Button(19, pin_factory=IP)
  
  
  # LISTS
  
  led [10, 17, 22, 27]
  button [5, 6, 13, 19]
  
  def button_1():
      if BUTTON1.value == 1:
          LED1.on()
          time.sleep(0.50)
      if BUTTON1.value == 0:
          LED1.on()
          time.sleep(0.50)
  
  
  def button_2():
      if BUTTON2.value == 1:
          LED2.on()
          time.sleep(0.50)
      if BUTTON2.value == 0:
          LED2.on()
          time.sleep(0.50)
  
  
  def button_3():
      if BUTTON3.value == 1:
          LED3.on()
          time.sleep(0.50)
      if BUTTON3.value == 0:
          LED3.on()
          time.sleep(0.50)
  
  
  def button_4():
      if BUTTON4.value == 1:
          LED4.on()
          time.sleep(0.50)
      if BUTTON4.value == 0:
          LED4.on()
          time.sleep(0.50)
  
  def check_button():
      while True:
          for i in range(BUTTON1):
              toggle_button(i)
  
  
  def main():
      set_up_led()
      set_up_button()
      check_button()
  
  # MAIN START PROGRAM
  
  
  if __name__ == "__main__":
      main()
  </code></pre>