<jupyter_start><jupyter_text>Buttons, switches, and LEDs----  Aim/s* Test the board components. References* [PYNQ docs](https://pynq.readthedocs.io/en/latest/index.html) Last revised* 27Jan21    * Initial revision----  Base overlayLoad the overlay first<jupyter_code>from pynq.overlays.base import BaseOverlay

base = BaseOverlay('base.bit')<jupyter_output><empty_output><jupyter_text>Buttons and LEDs Now the following demo shows how to use push buttons, LEDs, and RGB LEDs on the board.You can do the following to control the LEDs or RGB LEDs:    Button 0 pressed:        RGB LEDs change color.    Button 1 pressed:        LEDs shift from right to left.    Button 2 pressed:        LEDs shift from left to right.    Button 3 pressed:        Turns off all the LEDS and ends this demo.Please note that when a push button is pressed, the corresponding value read from AXI GPIO is 1.<jupyter_code>from time import sleep

Delay1 = 0.3
Delay2 = 0.1
color = 0
rgbled_position = [0, 1]

for led in base.leds:
    led.on()
while (base.buttons[3].read()==0):
    if (base.buttons[0].read()):
        color = (color+1) % 8
        for led in rgbled_position:
            base.rgbleds[led].write(color)
            base.rgbleds[led].write(color)
        sleep(Delay1)

    elif (base.buttons[1].read()):
        for led in base.leds:
            led.off()
        sleep(Delay2)
        for led in base.leds:
            led.toggle()
            sleep(Delay2)

    elif (base.buttons[2].read()):
        for led in reversed(base.leds):
            led.off()
        sleep(Delay2)
        for led in reversed(base.leds):
            led.toggle()
            sleep(Delay2)                  

print('End of this demo ...')
for led in base.leds:
    led.off()
for led in rgbled_position:
    base.rgbleds[led].off()<jupyter_output>End of this demo ...<jupyter_text>Switches We can also read switch values. On the board,if a switch is up, the reading value will be 1;otherwise the reading value for that switch will be 0.The next cell will read out 4 switch values;the left-most LED has index 0 and the right-most LEDhas index 3.<jupyter_code>for i in range(4):
    print("Switch {0} reading value: {1}".format(
        i, base.switches[i].read()))<jupyter_output>Switch 0 reading value: 1
Switch 1 reading value: 1
Switch 2 reading value: 1
Switch 3 reading value: 1
{'fraction_non_alphanumeric': 0.09953211399404509, 'fraction_numerical': 0.019566142067205444, 'mean_word_length': 2.824390243902439, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '550578', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 772, 'n_tokens_neox': 723, 'n_words': 264, 'path': 'board/RFSoC2x2/base/notebooks/board/buttons_leds_switches.ipynb', 'repo_name': 'Zacarhay/RFSoC2x2-PYNQ', 'size': '2351'}