Jump to content

More in depth of what I'm doing...I have a project term going on for my Electronics & Comptuer Engineering studies, and we are controlling some "smart" lights with Bluetooth signals (RSSI)...if you are in "Bedroom1" turn on lights in "Bedroom1", turn off all the lights in "Bedroom0 and Bedroom2." Basically an automated system by simplying having Bluetooth enabled on your smartphone / tablet / etc.

 

I'm in charge of storing/recalling the user-selected settings (colour, brightness, Hue, saturation, etc) for the lights. Right now, the light settings are only written and stored in a external file ONCE...as it is outside of the "While True" loop. I want it so that if the user wants to change the stored settings, they don't need to stop the program and run it again. Basically, they can chnge the settings anytime they so desire.

 

So the code so far:

- Declare necessary modules and such

- Code to read the settings for the lightbulbs and write them to an external file that can be read at a later time

- While true loop (run continously)

  • Determine where the user is located (i.e. "Bedroom0")
  • Turn on the appropriate lights (i.e. turn on lgiths in "Bedroom0")
  • Turn off the approriate lights (i.e. turn off lights in "Bedroom1" and "Kitchen")
  • Some error handling so program won't crash and burn

 

I am having some issues trying to implement some kind of keyboard input (key press) acknowledgement in Python.

 

What I want to do is basically:

- Declare necessary modules and such

- Code to read the settings of the lightbulbs and write them to an external file that can be read at a later time ("Bedroom0" colour: "Green", brightness level: "150", Hue level: "3000", Saturation: "200")

- While True:

  • Determine where the user is located (i.e. "Bedroom0")
  • Turn on the appropriate lights and use the settings stored in the external file (i.e. turn on lights in "Bedroom0")
  • Turn off the approriate lights (i.e. turn off lights in "Bedroom1" and "Kitchen")
  • Some error handling so program won't crash and burn
  • whenever the...ENTER key is pressed...skip this part if ENTER is is not pressed
    • Read the new settings for the lightbulbs and over-write the current settings that is stored in the external file

 

I first tried raw_input, but it WAITS for the user to input something before the program can proceed any further. I want something that doesn't wait; just whenver the user inputs the correspodning key, do this.

 

I've looked into msvcrt...but that only works if you are working with Python in Windows.

 

Tkinter was something "plausible" but I'm not so sure about it.

 

 

 

This program is running in Terminal (Linux's version of Command Prompt) as it will be on a "headless" Raspberry Pi computer.

 

I can provide a copy of my code if necessary...but 90% of the code is from a Python module / package to control the "smart" lights (Philips Hue LED lighting system).

 

In case any of you are wondering, the Philips Hue system allows you to control LED lightbulbs via WiFi. It can be done from an App on a Apple or Android device, through a website, or programming code. Each lightbulb is controlled via HTTP (they have their own URL) and the settings for each bulb have their own specific URL. Philips provides an open source API and manual...they WANT you to tinker with it...and make your own app or website if you so desire.

Communication from mobile device (App, etc) --> Hue "Bridge" via WiFi.

Communication from Hue "Bridge" --> bulbs via Zigbee light Protocol.

 

Any help from the good ol' LTT community would be fantastic!

Cheers!

AMD Ryzen 9000 Rig

  • AMD R7 9800X3D + Alphacool CORE 1 w/ Performance Mount Kit + Thermal Grizzly AM5 Contact Frame
  • Gigabyte X870E Aorus Pro Ice
  • 32GB (16GB X2) G.Skill Trident Z5 Neo RGB DDR5-6400
  • Sapphire NITRO+ 6800 XT Special Edition + EKwb Full Cover Block
  • Custom Loop w/ 2x 360mm Radiators
  • WD SN850X + WD SN750 + Samsung 980
  • EVGA P2 850W + Red/White CableMod Cables
  • Lian-Li O11 Dynamic EVO XL

AMD Ryzen 5000 Rig

  • AMD R7-5800X
  • Gigabyte B550 Aorus Pro AC
  • 32GB (16GB X 2) Crucial Ballistix RGB DDR4-3600
  • Gigabyte Vision RTX 3060 Ti OC
  • EKwb D-RGB 360mm AIO
  • Intel 660p NVMe 1TB + Crucial MX500 1TB + WD Black 1TB HDD
  • EVGA P2 850W + White CableMod cables
  • Lian-Li LanCool II Mesh - White

Intel i7-8086K / Z390 Rig (Decommissioned Q2' 2025)

Intel i7-6800K / X99 Rig (Officially Decommissioned, Dead CPU returned to Intel)
Intel i5-4690K / Z97 Rig (Decommissioned)

AMD FX-8350 / 990FX Rig (Decommissioned)

AMD Phenom II X6 1090T / 890FX Rig (Decommissioned)

 

<> Electrical Engineer , B.Eng <>

<> Electronics & Computer Engineering Technologist (Diploma + Advanced Diploma) <>

<> Electronics Engineering Technician for the Canadian Department of National Defence <>

Link to comment
https://linustechtips.com/topic/77789-python-key-press-event-for-linux-ubuntu/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×