I'm trying to write a python program that responds to a switch attached to GPIO pin 11, using the push button circuit from Mag Pi issue 2 http://www.themagpi.com/. Using the code in the magazine the button pressing works as expected, however when I try to do the same using python curses, nothing is displayed on screen, it doesn't seem to be reading the GPIO state.
Can anyone see what I'm doing wrong? I am using Python 2.7
Code: Select all
#! /usr/bin/python # -*- coding: utf-8 -*- import RPi.GPIO as GPIO import curses GPIO.setup(11, GPIO.IN) def swichtest(): count = 0 screen = curses.initscr() curses.noecho() curses.curs_set(0) screen.keypad(1) top = 2 left = 0 screen.addstr("Press a Little Button (or press 'q' to quit)") while True: mybutton = GPIO.input(11) if mybutton == False: count += 1 screen.addstr(top, left, "Button Pressed") else: screen.addstr(top, left, " ") event = screen.getch() if event == ord("q"): break curses.endwin() return count if __name__ == "__main__": count = swichtest() print count, "fin."