// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// Released under the GPLv3 license to match the rest of the
// Adafruit NeoPixel library
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 6 // On Trinket or Gemma, suggest changing this to 1
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 8 // Popular NeoPixel ring size
// When setting up the NeoPixel library, we tell it how many pixels,
// and which pin to use to send signals. Note that for older NeoPixel
// strips you might need to change the third parameter -- see the
// strandtest example for more information on possible values.
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
void setup() {
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
// Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
}
// Color get_rainbow_color(int index, int total)
// {
// return Color(0, 0, 0);
// }
void one_light()
{
for(int i = 0; i < 3; i++)
{
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
pixels.show();
delay(500);
pixels.setPixelColor(0, pixels.Color(255, 0, 255));
pixels.show();
delay(500);
}
}
void circle_led3()
{
for(int count=0; count<8*5; count++) {
pixels.clear();
pixels.setPixelColor(count % 8, pixels.Color(0, 150, 0));
pixels.setPixelColor((count-1) % 8, pixels.Color(0, 150, 0));
pixels.setPixelColor((count-2) % 8, pixels.Color(0, 150, 0));
pixels.show();
delay(150);
}
}
void circle_fast()
{
int delay_time = 200;
for(int j = 0; j < 5; j++)
{
for(int i=0; i<NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(0, 150, 0));
pixels.show();
delay(delay_time);
}
for(int i=0; i<NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(0, 0, 0));
pixels.show();
delay(delay_time);
delay_time -= 5;
}
}
}
void breathe() {
float sinVal, r;
for(int i = 0; i < 255; i++) {
sinVal = 126 * sin((float)i/100.0) + 128;
r = constrain(sinVal, 2, 255);
pixels.setPixelColor(0, pixels.Color(r, 0, 0));
pixels.show();
delay(10);
}
}
void loop() {
pixels.clear(); // Set all pixel colors to 'off'
// one_light();
// circle_led3();
// circle_fast();
breathe();
}