#include <Adafruit_NeoPixel.h>
#include <KosmoBits_Pixel.h>
#include <KosmoBits_Pins.h>
const int sensorPin = KOSMOBITS_SENSOR_PIN;
KosmoBits_Pixel pixel;
void setup() {
pinMode(sensorPin, INPUT);
pixel.setColor(255, 255, 255, 0);
}
void loop() {
int brightness = analogRead(sensorPin);
if (brightness > 255) {
brightness = 255;
}
pixel.setColor(255, 255, 255, brightness);
delay(10);
}
You can probably understand the program without any
help. In brief: In
setup()
you set the sensor pin mode and
switch off the NeoPixel. In the main loop, you use the light
sensor to measure the brightness and store the reading in
the
brightness
variable. Since the brightness value
must not be greater than 255 with
pixel.setColor()
,
limit the
brightness
value to 255 with the help of the
if
instruction.
Now you just need to place the sensor in the fridge and
close the door. And what’s the answer? Does the light go
out?
</>
THE PROGRAM
▲
Jumper wire in fridge
54
PROJECT 18
CodeGamer manual inside english.indd 54
7/19/16 12:33 PM