Here we're making a simple Night Light that turns on when it gets dark, and off when it's light.
On the 2400mAh battery used it should last around 4 months assuming the LED is on for 4 hours a day.
You might also want to check out the Puck.js Night Light which glows a colour to show you the temperature.
Simply:
D15
but any pin will do.var light = 0, on = false;
setInterval(function() {
light = analogRead(LED2);
if (light < 0.16) on = true;
if (light > 0.18) on = false;
D15.write(on);
}, 2000);
// Only use this code if you want to make the light
// invisible on Bluetooth until the button is pressed
NRF.sleep();
setWatch(function() {
NRF.wake();
}, BTN1);
Just upload the code above to flash the MDBT42Q. Once uploaded it'll disconnect from Bluetooth and will be a usable night light.
However, you'll probably want to tweak the numbers for when the
LED turns on and off. Simply do this by removing the last bit of code,
then while connected type light
into the Web IDE's console to find
out what the light value is at different brightness levels.
As noted in the video, the usage of hysteresis can help to stop the light from flickering on and off, however there are some other additions that can really help.
light = analogRead(LED2);
with D15.reset(); light = analogRead(LED2); D15.write(on);
. Suggested by Akos Lukacs
in the video comments, this turns the LED off very briefly in order to take a light reading, then turns it back on. There's a
barely perceptible flicker.The case was designed with OpenSCAD - it is simply a hollow cylinder:
difference() {
translate([0,0,-1.5]) cylinder(r=36/2,h=60);
cylinder(r=33/2,h=60);
}
This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.