Thames & Kosmos Code Gamer Experiment Manual page 56

Coding workshop ? game with kosmobits
Table of Contents

Advertisement

PROJECT 18
THE PROGRAM
You can probably understand the program without any
help. In brief: In
setup()
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
limit the
brightness
instruction.
if
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?
54
CodeGamer manual inside english.indd 54
you set the sensor pin mode and
pixel.setColor()
value to 255 with the help of the
#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);
}
▲ Jumper wire in fridge
</>
7/19/16 12:33 PM

Advertisement

Table of Contents
loading

Table of Contents