0

I have a simple python script :

#!/usr/bin/python

import RPi.GPIO as GPIO
import time
from time import *

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

GPIO.setup(26,GPIO.IN)
GPIO.setup(4, GPIO.OUT)

while True:
    sleep (1)
    input = GPIO.input(26)
    if input:
            GPIO.output(4,True)
    else:
            GPIO.output(4,False)

Should I avoid switching on a GPIO Pin every second or should I only switch it once the button changes its return value? I switch a LED on and off.

5

You can switch a GPIO on and off as frequently as you want. It will not be harmed.

If the GPIO is used to switch an external circuit on and off you would have to consider what you are switching. E.g. if the GPIO is used to switch a mechanical relay you might want to limit the frequency. The relay will likely have a limited lifetime measured in tens of thousands of activations.

2
  • it's just a LED – Motte001 Jul 2 '16 at 22:43
  • 3
    A LED will be fine. – joan Jul 3 '16 at 5:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.