dropdown menu

Back To Home

Thursday, November 21, 2019

Button control for gpio raspberry pi using python

Python code:

from gpiozero import Button
#you need to have this module installed
from time import sleep
from tkinter.messagebox import *

button = Button(4)
#button 4 mean pin7
while True:
    if button.is_pressed:
        print("Pressed")
        #so if grounded, mean press
    else:
        print("Released")
        #so if connect to 3.3V mean release
    sleep(1)
    
    showinfo(title="Greetings", message="Pressed")

Board connection for "OFF":

PIN7 connected to PIN1(3.3V)


Board connection for "ON":

PIN7 connected to PIN9(GND)                           











No comments:

Post a Comment