<jupyter_start><jupyter_text>@Copyright (C): 2010-2019, Shenzhen Yahboom Tech  @Author: Malloy.Yuan  @Date: 2019-07-17 10:10:02  @LastEditors: Malloy.Yuan  @LastEditTime: 2019-09-17 17:54:19    Button event detectionWhen the state of the button changes, the blue LED will follow the state change and print the current button GPIO port status.<jupyter_code>#!/usr/bin/env python

import RPi.GPIO as GPIO
import time

# Pin Definitons:
led_pin = 23  # BOARD pin 23 Green
but_pin = 7  # BOARD pin 7   key2

def main():
    prev_value = None

    # Pin Setup:
    GPIO.setmode(GPIO.BCM)  # BCM
    GPIO.setup(led_pin, GPIO.OUT)  # LED pin set as output
    GPIO.setup(but_pin, GPIO.IN)  # Button pin set as input

    # Initial state for LEDs:
    GPIO.output(led_pin, GPIO.LOW)
    print("Starting demo now!")
    try:
        while True:
            curr_value = GPIO.input(but_pin)
            if curr_value != prev_value:
                GPIO.output(led_pin, not curr_value)
                prev_value = curr_value
                print("Outputting {} to Pin {}".format(curr_value, led_pin))
            time.sleep(0.2)
    finally:
        GPIO.cleanup()  # cleanup all GPIO

if __name__ == '__main__':
    main()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10048231511254019, 'fraction_numerical': 0.03617363344051447, 'mean_word_length': 2.7841945288753798, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '570707', 'license': 'MIT', 'n_tokens_mistral': 455, 'n_tokens_neox': 417, 'n_words': 121, 'path': 'notebooks/3.Using of GPIO/2.Using of buttons/Using of Button2.ipynb', 'repo_name': 'Hoehlenbaer/jetbot', 'size': '1244'}