Welcome, Guest

Author Topic: GPIO Programming for Push button and ON/OFF (spdt) switch  (Read 272 times)


  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
GPIO Programming for Push button and ON/OFF (spdt) switch
« on: November 26, 2018, 08:36:43 AM »
Hi iam using following code to access gpios of A64 board.
Code works fine when i use ON/OFF switch, prints 1 consistently in OFF position and prints 0 consistently in ON postion.

Problem is when i use Push button for the same code, it works fine when button is pushed, but when button is in open position, it is printing 1 and 0 randomly. Does any else also faced such problem

#!/usr/bin/env python
"""Basic blinking led example.

import os
import sys

if not os.getegid() == 0:
    sys.exit('Script must be run as root')

from time import sleep
from pyA64.gpio import gpio
from pyA64.gpio import port

button = port.PE15

gpio.setcfg(button, gpio.INPUT)

state = gpio.input(button)
print state