Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93879

Re: Keypress Input

From John McKenzie <davros@bellaliant.net>
Subject Re: Keypress Input
Newsgroups comp.lang.python
References <rBHbx.75089$MO7.40532@fx10.iad>
Message-ID <9aypx.126956$r46.110087@fx28.iad> (permalink)
Date 2015-07-15 19:05 +0000

Show all headers | View raw


 Hello, all.

 Thanks to everyone who responded to my post.

 I decided to make sure I had something that worked with what I have now 
and used Curses to finish it. However, it turns out that the extra work 
and problems with using GPIO pins and wiring up controllers that way is a 
small amount of headaches and work compared to what I thought it would be 
and the software part is actually easier than doing it this way. So in 
the end I will hooking the Raspberry Pi up directly to the buttons and 
use the Raspberry Pi's GPIO library to do it all.

 For posterity and in case other beginners want to look at it, here is 
what I have with curses that works now. Tried to add a function to cause 
it to only work for a certain amount of time and that did not work. Will 
worry about that when I do the new programme based off of directly 
connected buttons and have those working.

 Thanks everyone.

 Here is the keyboard controls the colours script. (Raspberry Pi B+, 
Blinkstick Pro and LED Adapter, analouge RGB LED light strip.)

import curses
import atexit
import time
from datetime import datetime
from blinkstick import blinkstick

starttime = time.time()

screen = curses.initscr()
curses.noecho()
curses.curs_set(0)
screen.keypad(1)
screen.nodelay(1)

led = blinkstick.find_first()

timered = 0
timeyellow = 0
timeblue = 0

timestamp = str(datetime.now())

colour = 0

screen.addstr("Eflag 1")

while True:
    event = screen.getch()
    if event == ord("q"):
        flog = open('flag1log.text', 'a')
        flog.write(timestamp + '\n' + 'Red Team: ' + str(timered) + '\n' 
+ 'Yellow Team: ' + str(timeyellow) + '\n' + 'Blue Team: ' + str(timeblue) 
+ '\n')
        flog.close()
        curses.endwin()
        break
    elif event == ord("r"):
        colour = 1
        screen.addstr("Red Activated")

    elif event == ord("y"):
        colour = 2
        screen.addstr("Yellow Activated")

    elif event == ord("b"):
        colour = 3
        screen.addstr("Blue Activated")


    if colour == 1:
        led.pulse(red=255, green=0, blue=0, repeats=1, duration=3000, 
steps=50)
        timered += 1
        print timered

    if colour == 2:
        led.pulse(red=255, green=255, blue=0, repeats=1, duration=3000, 
steps=50)
        timeyellow += 1

    if colour == 3:
        led.pulse(red=0, green=0, blue=255, repeats=1, duration=2000, 
steps=50)
        timeblue += 1


    if time.time() == (time.time() + 30):
        flog = open('flag1log.text', 'a')
        flog.write(timestamp + '\n' + 'Red Team: ' + str(timered) + '\n' 
+ 'Yellow Team: ' + str(timeyellow) + '\n' + 'Blue Team: ' + str(timeblue) 
+ '\n')
        flog.close()
        curses.endwin()
        break

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Keypress Input John McKenzie <davros@bellaliant.net> - 2015-06-03 18:22 +0000
  Re: Keypress Input Laura Creighton <lac@openend.se> - 2015-06-03 20:59 +0200
  Re: Keypress Input Gary Herron <gherron@digipen.edu> - 2015-06-03 12:15 -0700
  Re: Keypress Input Gary Herron <gherron@digipen.edu> - 2015-06-03 11:47 -0700
  Re: Keypress Input Laura Creighton <lac@openend.se> - 2015-06-04 12:50 +0200
  Re: Keypress Input John McKenzie <davros@bellaliant.net> - 2015-06-06 18:28 +0000
    Re: Keypress Input Laura Creighton <lac@openend.se> - 2015-06-06 22:52 +0200
    Re: Keypress Input Chris Angelico <rosuav@gmail.com> - 2015-06-07 07:20 +1000
    Re: Keypress Input Michael Torrie <torriem@gmail.com> - 2015-06-06 22:31 -0600
  Re: Keypress Input John McKenzie <davros@bellaliant.net> - 2015-06-15 05:15 +0000
    Re: Keypress Input John McKenzie <davros@bellaliant.net> - 2015-06-16 15:09 +0000
    Re: Keypress Input Christian Gollwitzer <auriocus@gmx.de> - 2015-06-19 07:20 +0200
      Re: Keypress Input John McKenzie <davros@bellaliant.net> - 2015-06-20 14:59 +0000
      Re: Keypress Input Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-15 18:03 -0700
        Re: Keypress Input Michael Torrie <torriem@gmail.com> - 2015-07-15 22:30 -0600
          Re: Keypress Input Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-16 10:22 -0700
            Re: Keypress Input Michael Torrie <torriem@gmail.com> - 2015-07-16 15:27 -0600
        Re: Keypress Input Terry Reedy <tjreedy@udel.edu> - 2015-07-16 02:08 -0400
          Re: Keypress Input Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-16 11:30 -0700
        Re: Keypress Input Terry Reedy <tjreedy@udel.edu> - 2015-07-16 03:10 -0400
        Re: Keypress Input Michael Torrie <torriem@gmail.com> - 2015-07-16 15:29 -0600
  Re: Keypress Input John McKenzie <davros@bellaliant.net> - 2015-06-15 05:23 +0000
    Re: Keypress Input Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-06-15 12:22 +0100
      Re: Keypress Input Grant Edwards <invalid@invalid.invalid> - 2015-06-15 15:22 +0000
    Re: Keypress Input Michael Torrie <torriem@gmail.com> - 2015-06-16 11:15 -0600
      Re: Keypress Input John McKenzie <davros@bellaliant.net> - 2015-06-16 20:06 +0000
        Re: Keypress Input Grant Edwards <invalid@invalid.invalid> - 2015-06-16 20:49 +0000
          Re: Keypress Input Michael Torrie <torriem@gmail.com> - 2015-06-16 19:22 -0600
          Re: Keypress Input Michael Torrie <torriem@gmail.com> - 2015-06-18 16:42 -0600
      Re: Keypress Input John McKenzie <davros@bellaliant.net> - 2015-06-20 15:02 +0000
        Re: Keypress Input Michael Torrie <torriem@gmail.com> - 2015-06-20 10:30 -0600
  Re: Keypress Input Paul Rubin <no.email@nospam.invalid> - 2015-06-16 14:22 -0700
  Re: Keypress Input John McKenzie <davros@bellaliant.net> - 2015-07-15 19:05 +0000
    Re: Keypress Input Michael Torrie <torriem@gmail.com> - 2015-07-15 13:17 -0600
      Re: Keypress Input John McKenzie <davros@bellaliant.net> - 2015-08-16 19:45 +0000

csiph-web