Python Forum

Full Version: LED control menu
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
i made this before seeing your last post, which works apar from if i tap back a few times also it hangs on lights Off unlike Lights On which waits 2secs then goes back to On or OFF
#!/usr/bin/env python
 
import sys
import time
 
import dothat.backlight as backlight
import dothat.lcd as lcd
import dothat.touch as nav
from dot3k.menu import Menu, MenuOption
from time import sleep 
 
# Add the root examples dir so Python can find the plugins
sys.path.append('/home/pi/Pimoroni/displayotron/examples')
 
from plugins.clock import Clock
from plugins.graph import IPAddress, GraphTemp, GraphCPU, GraphNetSpeed, GraphSysReboot, GraphSysShutdown
from plugins.text import Text
from plugins.utils import Backlight, Contrast
 
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(5,GPIO.OUT)
 
print("""
This advanced example uses the menu framework.
It gives you a basic menu setup with plugins. You should be able to view system info and adjust settings!
 
Press CTRL+C to exit.
""")
 
class LightOn(MenuOption):
    """Control; Lights"""
    def __init__(self):
        self.last = self.millis()
        MenuOption.__init__(self)

    def redraw(self, menu):
        
        GPIO.output(13,0)
        GPIO.output(5,0)
        GPIO.output(13,1)
        menu.write_row(1,"Lights On")
        time.sleep(2)
        return
        
class LightOff(MenuOption):
    """Control; Lights"""
    def __init__(self):
        self.last = self.millis()
        MenuOption.__init__(self)

    def redraw(self, menu):
        GPIO.output(5,0)
        GPIO.output(13,0)
        GPIO.output(5,1)
        menu.write_row(1,"Lights Off")
        time.sleep(2)
        return         



     
"""
Using a set of nested lists you can describe
the menu you want to display on dot3k.
 
Instances of classes derived from MenuOption can
be used as menu items to show information or change settings.
 
See GraphTemp, GraphCPU, Contrast and Backlight for examples.
"""

LY = LightOn()
LN = LightOff()
 
menu = Menu(
    structure={
            'Power Options': {
                'Reboot':GraphSysReboot(),
                'Shutdown':GraphSysShutdown(),
                },
            'Aquarium': {
                'Lighting': {
                    'Control': {
                        'On': LY,
                        'Off':LN,
                        }
                    }
                },
        'Clock': Clock(backlight),
        'Status': {
            'IP': IPAddress(),
            'CPU': GraphCPU(backlight),
            'Temp': GraphTemp()
        },
        'Settings': {
            'Display': {
                'Contrast': Contrast(lcd),
                'Backlight': Backlight(backlight)
            }
        }
    },
    lcd=lcd,
    idle_handler=(LightOn,LightOff),
    idle_timeout=30,
    input_handler=Text())
 
"""
You can use anything to control dot3k.menu,
but you'll probably want to use dot3k.touch
"""
nav.bind_defaults(menu)
 
while 1:
    menu.redraw()
    time.sleep(0.05)
Traceback (most recent call last):
  File "/home/pi/Scripts/newtemp.py", line 116, in <module>
    menu.redraw()
  File "/usr/local/lib/python3.5/dist-packages/dot3k/menu.py", line 477, in redraw
    if self.current_value().text_entry:
AttributeError: 'dict' object has no attribute 'text_entry'

any ideas on how to add a delay so you cant press a button too many times to cause a crash?
Okay so is sorted my previous issue, now to go abit deeper,
has anyone used openweather or anything simplier to get an update on the weather x times a day and control a gpio,
i think if i can figure out the first bit the later shouldnt be too difficult
#!/usr/bin/env python
 
import sys
import time
 
import dothat.backlight as backlight
import dothat.lcd as lcd
import dothat.touch as nav
from dot3k.menu import Menu, MenuOption
from time import sleep 
 
# Add the root examples dir so Python can find the plugins
sys.path.append('/home/pi/Pimoroni/displayotron/examples')
 
from plugins.clock import Clock
from plugins.graph import IPAddress, GraphTemp, GraphCPU, GraphNetSpeed, GraphSysReboot, GraphSysShutdown
from plugins.text import Text
from plugins.utils import Backlight, Contrast
 
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(5,GPIO.OUT)


 
print("""
Script Running:
Press CTRL+C to exit.
""")
 
class DayLight(MenuOption):
    """Control; Lights"""
    def __init__(self):
        self.last = self.millis()
        MenuOption.__init__(self)

    def redraw(self, menu):
        menu.clear_row(0)
        menu.clear_row(1)
        menu.clear_row(2)
        GPIO.output(13,0)
        GPIO.output(5,0)
        GPIO.output(13,1)
        menu.write_row(1,"Daylights On")
        now = self.millis()
        if now - self.last < 1000 * 5:
            return False
        return

class MoonLight(MenuOption):
    """Control; Lights"""
    def __init__(self):
        self.last = self.millis()
        MenuOption.__init__(self)

    def redraw(self, menu):
        menu.clear_row(0)
        menu.clear_row(1)
        menu.clear_row(2)
        GPIO.output(13,0)
        GPIO.output(5,0)
        GPIO.output(5,1)
        menu.write_row(1,"Daylights On")
        now = self.millis()
        if now - self.last < 1000 * 5:
            return False
        return
        
class LightOff(MenuOption):
    """Control; Lights"""
    def __init__(self):
        self.last = self.millis()
        MenuOption.__init__(self)

    def redraw(self, menu):
        menu.clear_row(0)
        menu.clear_row(1)
        menu.clear_row(2)
        GPIO.output(5,0)
        GPIO.output(13,0)
        menu.write_row(1,"Lights Off")
        now = self.millis()
        if now - self.last < 1000 * 5:
            return False
        return       

LN = LightOff()
DL = DayLight()
ML = MoonLight()
 
menu = Menu(
    structure={
            'Power Options': {
                'Reboot':GraphSysReboot(),
                'Shutdown':GraphSysShutdown(),
                },
            'Aquarium': {
                'Lighting': {
                    'Control': {
                        'Lights': {
                            'Manual': {
                                'DayLight':DL,
                                'MoonLight':ML,
                                'Off':LN,
                                },
                            'Automatic':{
                                'Sunrise':SR,
                                'Sunset':SS,
                                }
                            }
                        }
                    }
                },
        'Clock': Clock(backlight),
        'Status': {
            'IP': IPAddress(),
            'CPU': GraphCPU(backlight),
            'Temp': GraphTemp()
        },
        'Settings': {
            'Display': {
                'Contrast': Contrast(lcd),
                'Backlight': Backlight(backlight)
            }
        }
    },
    lcd=lcd,
    idle_handler=(LightOff,DayLight,MoonLight),
    idle_timeout=30,
    input_handler=Text())
 
nav.bind_defaults(menu)
 
while 1:
    menu.redraw()
    time.sleep(0.05)
I was playing with openweather a while before. You can get I think 50 free requests per day. I was interested only in temperature.
Pages: 1 2 3