Hardware Reference
In-Depth Information
#include <Adafruit_NeoPixel.h>
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream
// NEO_KHZ400 400 KHz bitstream (e.g., FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g., High Density
// LED strip)
Adafruit_NeoPixel
strip
=
Adafruit_NeoPixel
(
1
,
6
,
NEO_GRB
+
NEO_KHZ800
);
const
int
buttonPin
=
1
;
// the fin snap is connected to FLORA
// TX; the other half of the snap is
// connected to GND
int
buttonState
=
0
;
// variable for reading
// the snap status
void
setup
()
{
strip
.
begin
();
strip
.
show
();
// Initialize all pixels to 'off'
// initialize the pushbutton pin as an input:
pinMode
(
buttonPin
,
INPUT
);
digitalWrite
(
buttonPin
,
HIGH
);
}
void
loop
()
{
// read the state of the pushbutton value:
buttonState
=
digitalRead
(
buttonPin
);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if
(
buttonState
==
LOW
)
{
// turn LED on:
strip
.
setPixelColor
(
0
,
strip
.
Color
(
200
,
211
,
254
));
// color when snap is connected
strip
.
show
();
}
else
{
// change LED color
strip
.
setPixelColor
(
0
,
strip
.
Color
(
250
,
0
,
0
));
// color when snap is disconnected
strip
.
show
();
}