from gpiozero import LED from random import randint from signal import pause def rand(): while True: yield randint(0, 1) led = LED(17) led.source = rand() pause()