<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Lesson 21.1. UNITS. LIGHT]]></title><description><![CDATA[<h3>The purpose of this lesson</h3>
<p dir="auto">Hi! Today we will get acquainted with the light units and learn to determine the presence of light (figure 1).</p>
<p dir="auto"><img src="https://pp.userapi.com/c849432/v849432737/fe8a0/8HA-hN9dRIg.jpg" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Figure 1</p>
<p dir="auto">This lesson will teach you how to obtain and process digital data about the presence of a light source.</p>
<h3>Short help</h3>
<ul>
<li>Purpose: used to determine the presence of a light source</li>
<li>Scope: agriculture, science and home life</li>
<li>Connection interface: I /O (b port slot connector)<br />
Supply voltage: 5 V</li>
<li>Compatibility: M5 fire</li>
<li>Form factor: LEGO compatible</li>
</ul>
<h3>Brief overview</h3>
<p dir="auto">Light is one of a large family of additional modules (blocks) designed primarily for M5 fire. This module Comes in a plastic box. The kit includes an excellent cable (15 cm) with installed groove plugs (figure 2). On the front side of the sensor there is a sticker with the name of the module and the designation of contacts. Interestingly, the sensor can operate in two modes: analog and digital.</p>
<p dir="auto"><img src="https://pp.userapi.com/c849432/v849432737/fe8ae/L78lMBoz2QQ.jpg" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Figure 2</p>
<p dir="auto">In order to set the trigger threshold for the digital output, there is a trimmer resistor motor on the back of the sensor (figure 3), which can be rotated with a screwdriver.</p>
<p dir="auto"><img src="https://pp.userapi.com/c849432/v849432737/fe8df/kI4WlrymHaI.jpg" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Figure 3</p>
<p dir="auto">Overall dimensions of the sensor are ridiculous, and the problems with installation is not (figure 4) :)</p>
<p dir="auto"><img src="https://pp.userapi.com/c849432/v849432737/fe8cc/7_XiNY54Kdc.jpg" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Figure 4</p>
<p dir="auto">The sensor Is connected directly to the above M5 port using the supplied cable. The light should fall into the hole with the sensor (figure 5).</p>
<p dir="auto"><img src="https://pp.userapi.com/c851436/v851436654/8ae30/FdqOu2mCgBc.jpg" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Figure 5</p>
<h2>Let's start!</h2>
<h3>Blockly (<a href="http://flow.m5stack.com" target="_blank" rel="noopener noreferrer nofollow ugc">UI Flow</a>)</h3>
<p dir="auto">First of all, we need to make sure that the UI thread is connected to the M5. If You see the words "Disconneted", then repeatedly press the arrows (1) as long as the label (2) not to be changed to "connected". Great! Blocks Can now be added by clicking on the plus (3) (figure 6).</p>
<p dir="auto"><img src="https://pp.userapi.com/c851436/v851436654/8ae3e/7MtsbTa0d30.jpg" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Figure 6</p>
<p dir="auto">OK, now check the box next to the light (1), then click OK (2) (figure 6.1).</p>
<p dir="auto"><img src="https://pp.userapi.com/c851436/v851436654/8ae48/KR_89y0yBlE.jpg" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Figure 6.1</p>
<p dir="auto">In order to get the digital data from the module you need to add the appropriate puzzle Blockly. Units press (1), then light (2), then transfer the digital value (3) to the puzzle workspace (figure 6.2).</p>
<p dir="auto"><img src="https://pp.userapi.com/c851436/v851436654/8ae5c/Aa4mQ6RBCrk.jpg" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Figure 6.2</p>
<p dir="auto">When the light falls on the sensor, it returns the logical unit on the digital output, in this case - we do not need the backlight and we turn it off, otherwise, on the contrary, we light the backlight. In order to control the heat of the glow, use the a key (colder) and the C key (warmer) (figure 7).</p>
<p dir="auto"><img src="https://pp.userapi.com/c851436/v851436654/8ae7e/JhR8okK1yBc.jpg" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Figure 7</p>
<p dir="auto">The lesson is finished! :)</p>
<h3>MicroPython (<a href="http://flow.m5stack.com" target="_blank" rel="noopener noreferrer nofollow ugc">UI Flow</a>)</h3>
<pre><code>from m5stack import *
from m5ui import *
import units

clear_bg(0x000000)
light0 = units.Light(units.PORTB)



btnA = M5Button(name="ButtonA", text="ButtonA", visibility=False)
btnB = M5Button(name="ButtonB", text="ButtonB", visibility=False)
btnC = M5Button(name="ButtonC", text="ButtonC", visibility=False)

import random

red = None
blue = None
green = None


def buttonA_pressed():
  global red, blue, green, rgb, light0
  red = red - 25
  blue = blue + 25
  pass
def buttonC_pressed():
  global red, blue, green, rgb, light0
  red = red + 25
  blue = blue - 25
  pass
buttonA.wasPressed(callback=buttonA_pressed)
buttonC.wasPressed(callback=buttonC_pressed)
red = 100
green = 100
blue = 100
while True:
  if red &gt;= 255:
    red = 255
  if red &lt; 0:
    red = 0
  if green &gt;= 255:
    green = 255
  if green &lt; 0:
    green = 0
  if blue &gt;= 255:
    blue = 255
  if blue &lt; 0:
    blue = 0
  if light0.d_read():
    rgb.set_all(int('0x%02x%02x%02x' % (round(min(100, max(0, red)) * 2.55), round(min(100, max(0, green)) * 2.55), round(min(100, max(0, blue)) * 2.55))))
  else:
    rgb.set_all(0x000000)
  lcd.pixel(random.randint(0, 320), random.randint(0, 240), 0xccffff)
  wait(0.05)
  wait(0.001)
</code></pre>
<h3>C &amp; C++ (<a href="https://www.arduino.cc/en/Main/Software" target="_blank" rel="noopener noreferrer nofollow ugc">Arduino IDE</a>)</h3>
<p dir="auto">Example not yet written ^_^</p>
<h3>Downloads</h3>
<h3>Demo</h3>
<ol>
<li><a href="https://youtu.be/AvBx1AhFtt8" target="_blank" rel="noopener noreferrer nofollow ugc">YouTube</a></li>
</ol>
]]></description><link>https://community.m5stack.com/topic/502/lesson-21-1-units-light</link><generator>RSS for Node</generator><lastBuildDate>Sun, 08 Mar 2026 10:43:06 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/502.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 11 Jan 2019 08:06:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Lesson 21.1. UNITS. LIGHT on Fri, 01 Feb 2019 11:50:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/423">@lastcaress</a> You can to increase a delay interval.</p>
]]></description><link>https://community.m5stack.com/post/2805</link><guid isPermaLink="true">https://community.m5stack.com/post/2805</guid><dc:creator><![CDATA[Dimi]]></dc:creator><pubDate>Fri, 01 Feb 2019 11:50:42 GMT</pubDate></item><item><title><![CDATA[Reply to Lesson 21.1. UNITS. LIGHT on Tue, 29 Jan 2019 20:33:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/79">@dimi</a> I've tried this and it works, but it makes so much noise. Each time it makes a reading (several times every second I guess) it makes an annoying "click" :\</p>
]]></description><link>https://community.m5stack.com/post/2776</link><guid isPermaLink="true">https://community.m5stack.com/post/2776</guid><dc:creator><![CDATA[LastCaress]]></dc:creator><pubDate>Tue, 29 Jan 2019 20:33:19 GMT</pubDate></item><item><title><![CDATA[Reply to Lesson 21.1. UNITS. LIGHT on Fri, 11 Jan 2019 09:35:40 GMT]]></title><description><![CDATA[<p dir="auto">Thank you</p>
]]></description><link>https://community.m5stack.com/post/2449</link><guid isPermaLink="true">https://community.m5stack.com/post/2449</guid><dc:creator><![CDATA[ajb2k3]]></dc:creator><pubDate>Fri, 11 Jan 2019 09:35:40 GMT</pubDate></item></channel></rss>