[quote=“gadgetoid, post:10, topic:7858”]
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
import datetime
sys.path.append ('/home/pi/.local/lib/python2.7/site-packages')
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
from astral import Astral
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(5,GPIO.OUT)
a = Astral()
a.solar_depression = 'civil'
city = a['London']
class Lights(MenuOption):
def __init__(self):
self._mode = 0
self._message = ''
self._timeout = 0
self._status = False
self._auto = True
self._sun_rise = None
self._sun_set = None
MenuOption.__init__(self)
def get_status(self):
return self._status
def is_auto(self):
return self._auto
def set_times(self, sun_rise, sun_set):
self._sun_rise = sun_rise
self._sun_set = sun_set
def redraw(self, menu):
if self._mode == 0:
menu.write_row(0, "Lights {}".format(str(datetime.datetime.now().time())[:8]))
menu.write_row(1, "{} {}".format("[LIGHTS]" if self._status else " LIGHTS ", "[AUTO]" if self._auto else " AUTO "))
menu.write_row(2, "R:{} S:{}".format(str(self._sun_rise)[:-3], str(self._sun_set)[:-3]))
elif self._mode == 1:
if self._timeout <= time.time():
self._mode = 0
menu.clear_row(0)
menu.write_row(1, self._message)
menu.clear_row(2)
def display_message(self, message, timeout=1):
self._message = message
self._timeout = time.time() + timeout
self._mode = 1
def lights_on(self):
GPIO.output(13,0)
GPIO.output(5,1)
GPIO.output(13,1)
self._status = True
self.display_message("Lights: On", 1)
def lights_off(self):
GPIO.output(5,1)
GPIO.output(13,0)
time.sleep(1)
GPIO.output(13,1)
time.sleep(1)
GPIO.output(13,0)
self._status = False
self.display_message("Lights: Off", 1)
def auto_on(self):
self._auto = True
self.display_message("Auto: On", 1)
def auto_off(self):
self._auto = False
self.display_message("Auto: Off", 1)
def right(self):
self.auto_on()
def left(self):
self.auto_off()
return True
def up(self):
self._auto = False
self.lights_on()
def down(self):
self._auto = False
self.lights_off()
lights = Lights()
menu = Menu(
structure={
'Power Options': {
'Reboot':GraphSysReboot(),
'Shutdown':GraphSysShutdown(),
},
'Aquarium': {
'Lighting': {
'Control': lights,
}
},
'Clock': Clock(backlight),
'Status': {
'IP': IPAddress(),
'CPU': GraphCPU(backlight),
'Temp': GraphTemp()
},
'Settings': {
'Display': {
'Contrast': Contrast(lcd),
'Backlight': Backlight(backlight)
}
}
},
lcd=lcd,
idle_handler=lights,
idle_time=2,
input_handler=Text())
nav.bind_defaults(menu)
while True:
menu.redraw()
now = datetime.datetime.now()
sun = city.sun(date=now.date(), local=True)
sun_rise = sun['sunrise'].time()
sun_set = sun['sunset'].time()
lights.set_times(sun_rise, sun_set)
if lights.is_auto() == True:
if now.time() >= sun_rise and lights.get_status() == False:
lights.lights_on()
if now.time() >= sun_set and lights.get_status() == True:
lights.lights_off()
time.sleep(1.0 / 20)
[/quote] i change the menu structure so its in order, however the last 3 Backlight LEDs on the right hand side are at a different brightness to the first 3, any ideas why this happens as i only changed the structure
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
import datetime
sys.path.append ('/home/pi/.local/lib/python2.7/site-packages')
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
from astral import Astral
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(5,GPIO.OUT)
a = Astral()
a.solar_depression = 'civil'
city = a['London']
class Lights(MenuOption):
def __init__(self):
self._mode = 0
self._message = ''
self._timeout = 0
self._status = False
self._auto = True
self._sun_rise = None
self._sun_set = None
MenuOption.__init__(self)
def get_status(self):
return self._status
def is_auto(self):
return self._auto
def set_times(self, sun_rise, sun_set):
self._sun_rise = sun_rise
self._sun_set = sun_set
def redraw(self, menu):
if self._mode == 0:
menu.write_row(0, "Lights {}".format(str(datetime.datetime.now().time())[:8]))
menu.write_row(1, "{} {}".format("[LIGHTS]" if self._status else " LIGHTS ", "[AUTO]" if self._auto else " AUTO "))
menu.write_row(2, "R:{} S:{}".format(str(self._sun_rise)[:-3], str(self._sun_set)[:-3]))
elif self._mode == 1:
if self._timeout <= time.time():
self._mode = 0
menu.clear_row(0)
menu.write_row(1, self._message)
menu.clear_row(2)
def display_message(self, message, timeout=1):
self._message = message
self._timeout = time.time() + timeout
self._mode = 1
def lights_on(self):
GPIO.output(13,0)
GPIO.output(5,1)
GPIO.output(13,1)
self._status = True
self.display_message("Lights: On", 1)
def lights_off(self):
GPIO.output(5,1)
GPIO.output(13,0)
time.sleep(1)
GPIO.output(13,1)
time.sleep(1)
GPIO.output(13,0)
self._status = False
self.display_message("Lights: Off", 1)
def auto_on(self):
self._auto = True
self.display_message("Auto: On", 1)
def auto_off(self):
self._auto = False
self.display_message("Auto: Off", 1)
def right(self):
self.auto_on()
def left(self):
self.auto_off()
return True
def up(self):
self._auto = False
self.lights_on()
def down(self):
self._auto = False
self.lights_off()
lights = Lights()
menu = Menu(
None,
lcd,
5)
menu.add_item('Lighting/Aquarium/Control', lights)
menu.add_item('Clock', Clock())
menu.add_item('Status/IP', IPAddress())
menu.add_item('Status/CPU', GraphCPU())
menu.add_item('Status/Temp', GraphTemp())
menu.add_item('Display/Settings/Contrast', Contrast(lcd)),
menu.add_item('Display/Settings/Backlight', Backlight(backlight))
"""
You can use anything to control dot3k.menu,
but you'll probably want to use dot3k.joystick
"""
REPEAT_DELAY = 0.5
nav.bind_defaults(menu)
while True:
menu.redraw()
now = datetime.datetime.now()
sun = city.sun(date=now.date(), local=True)
sun_rise = sun['sunrise'].time()
sun_set = sun['sunset'].time()
lights.set_times(sun_rise, sun_set)
if lights.is_auto() == True:
if now.time() >= sun_rise and lights.get_status() == False:
lights.lights_on()
if now.time() >= sun_set and lights.get_status() == True:
lights.lights_off()
time.sleep(1.0 / 20)