Unless you've been stuck upgrading all your computers to Windows 10 before the deadline of July 29th, you may have heard that the 2000's sensation Pokemon has been reborn in a new augmented reality game Pokemon Go.
Poke Balls are the red and white spheres that a person uses to catch Pokemon.
Adafruit's NeoPixel light rings can be set to half red and half white to simulate a Poke Ball.
The code below has been set for the 10 pixels on Circuit Playground. The code can be used on any Adafruit NeoPixel ring with quick changes to the constants at the start.
Have fun!
// CPpokeball Paints your Adafruit NeoPixel ring in Poke Ball colors
//
// Set for Circuit Playground but works for all Adafruit NeoPixel Rings with
// correct pixel pin number and pixel count
//
// Mike Barela July 23, 2016 MIT License
#include <Adafruit_NeoPixel.h>
const int pixelPin = 17; // NeoPixel pin number for Circuit Playground
const int pixelCount = 10; // Number of Neopixels (10 for Circuit Playground)
const int pixelBrightness = 30; // 0 to 255
Adafruit_NeoPixel strip = Adafruit_NeoPixel(pixelCount, pixelPin, NEO_GRB + NEO_KHZ800);
uint32_t red = strip.Color(255, 0, 0);
uint32_t white = strip.Color(255, 255, 255);
uint32_t black = strip.Color(0, 0, 0);
void setup()
{
// this resets all the neopixels to an off state
strip.begin();
strip.show();
strip.setBrightness(pixelBrightness);
}
void loop()
{
setPixelsPokeBall(); // set Pokeball colors
delay(5000); // delay 5 deconds
for( int8_t j=1; j<=5; j++) { // blink Pokeball colors 5 times
setPixelsOff();
delay(700);
setPixelsPokeBall();
delay(700);
}
delay(2000); // wait a bit and start again
}
void setPixelsOff(void) {
for(int8_t i=0; i<=9; i++) {
strip.setPixelColor(i, black);
}
strip.show();
}
void setPixelsPokeBall(void) {
for(int8_t i=0; i<(pixelCount/2); i++) {
strip.setPixelColor(i, red);
}
for(int8_t i=(pixelCount/2); i<pixelCount; i++) {
strip.setPixelColor(i, white);
}
strip.show();
}
No comments:
Post a Comment