// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// Released under the GPLv3 license to match the rest of the
// Adafruit NeoPixel library
// This sketch shows use of the "new" operator with Adafruit_NeoPixel.
// It's helpful if you don't know NeoPixel settings at compile time or
// just want to store this settings in EEPROM or a file on an SD card.
#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?
int pin = 23; // On Trinket or Gemma, suggest changing this to 1
// How many NeoPixels are attached to the Arduino?
int numPixels = 11; // Popular NeoPixel ring size
// NeoPixel color format & data rate. See the strandtest example for
// information on possible values.
int pixelFormat = NEO_GRB + NEO_KHZ800;
// Rather than declaring the whole NeoPixel object here, we just create
// a pointer for one, which we'll then allocate later...
Adafruit_NeoPixel *pixels;
#define DELAYVAL 200 // Time (in milliseconds) to pause between pixels
int sensorPin = A6;
int sensorValue = 0;
const int BUTTON1 = 35;
const int BUTTON2 = 32;
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.
// Right about here is where we could read 'pin', 'numPixels' and/or
// 'pixelFormat' from EEPROM or a file on SD or whatever. This is a simple
// example and doesn't do that -- those variables are just set to fixed
// values at the top of this code -- but this is where it would happen.
// Then create a new NeoPixel object dynamically with these values:
pixels = new Adafruit_NeoPixel(numPixels, pin, pixelFormat);
// Going forward from here, code works almost identically to any other
// NeoPixel example, but instead of the dot operator on function calls
// (e.g. pixels.begin()), we instead use pointer indirection (->) like so:
pixels->begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
// You'll see more of this in the loop() function below.
pinMode(BUTTON1, INPUT_PULLUP);
pinMode(BUTTON2, INPUT_PULLUP);
}
void loop() {
int sensorValue = analogRead(sensorPin);
int POWER_ON = digitalRead(BUTTON1);
int CHARGER_ON = digitalRead(BUTTON2);
if (POWER_ON == HIGH) {
// turn LED on:
pixels->setPixelColor(1, pixels->Color(0, 255, 0));
pixels->setPixelColor(2, pixels->Color(0, 155, 0));
pixels->setPixelColor(3, pixels->Color(0, 100, 0));
pixels->setPixelColor(4, pixels->Color(0, 80, 0));
pixels->setPixelColor(5, pixels->Color(0, 50, 0));
} else {
pixels->setPixelColor(1, pixels->Color(0, 0, 0));
pixels->setPixelColor(2, pixels->Color(0, 0, 0));
pixels->setPixelColor(3, pixels->Color(0, 0, 0));
pixels->setPixelColor(4, pixels->Color(0, 0, 0));
pixels->setPixelColor(5, pixels->Color(0, 0, 0));
}
pixels->show(); // Send the updated pixel colors to the hardware.
if (CHARGER_ON == HIGH) {
// turn LED on:
pixels->setPixelColor(6, pixels->Color(255, 0, 0));
pixels->setPixelColor(7, pixels->Color(155, 0 ,0));
pixels->setPixelColor(8, pixels->Color(100, 0, 0));
pixels->setPixelColor(9, pixels->Color(80, 0, 0));
pixels->setPixelColor(10, pixels->Color(50, 0, 0));
} else {
pixels->setPixelColor(6, pixels->Color(0, 0, 0));
pixels->setPixelColor(7, pixels->Color(0, 0 ,0));
pixels->setPixelColor(8, pixels->Color(0, 0, 0));
pixels->setPixelColor(9, pixels->Color(0, 0, 0));
pixels->setPixelColor(10, pixels->Color(0, 0, 0));
}
pixels->show(); // Send the updated pixel colors to the hardware.
if (POWER_ON == HIGH || CHARGER_ON == HIGH) {
} else {
pixels->clear(); // Set all pixel colors to 'off'
}
}