The following information is for the EMANT380
Ex 6: Measure Light intensity with GUI
Lux.py
Modified from example code provided by Nokia. Please read the section on Real-Time Graphics Support and Key Event Handling from the manual Programming with Python for Series 60 Platform for more information.
- Measures light intensity and displays as value and bar.
- End the program by pressing right menu key
Code Explained
import Emant
m = Emant.Emant300()
m.Open("00:06:66:00:a1:D8")
hwid = unicode(m.HwId())
Instantiate connect to DAQ module. Display the HwId.
while running:
img.clear(WHITE)
volt, binval = m.ReadAnalog(Emant.Emant300.AIN0,Emant.Emant300.COM)
lux = int(1333 * volt)
if luxold != lux:
handle_redraw(())
luxold = lux
luxstring = unicode(str(lux))
if lux > 230:
lux = 230
canvas.rectangle((10,90,lux,130),fill=(0,255,0))
canvas.text((10,50),hwid, 0x008000, 'title')
canvas.text((10,80),luxstring, 0x008000, 'title')
e32.ao_yield()
m.Close()
Loop to measure voltage, convert to lux and display the value and bar. Upon exit, close the DAQ connection.
def quit():
global running
running=0
.
.
appuifw.app.exit_key_handler=quit
Code to signal loop exit when the right menu key is pressed.
