Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Multi-mode goggles put together by MrARM
- // Power cycle changes modes
- #include <Adafruit_NeoPixel.h>
- #include <EEPROM.h>
- #ifdef __AVR_ATtiny85__ // Trinket, Gemma, etc.
- #include <avr/power.h>
- #endif
- #define PIN 0
- byte eepromFlags = 0;
- byte nexteeprom = 0;
- bool initFlag = false; // setup for a mode, Ex. Set brightness
- bool modeIndicatior = true; // Light up with a set number of LEDS to indicate mode
- // Adafruit tutorial wheel vars
- uint8_t offset = 0;
- uint32_t color = 0x00FF00;
- Adafruit_NeoPixel pixels = Adafruit_NeoPixel(32, PIN);
- void setup() {
- // Performance tweak
- #ifdef __AVR_ATtiny85__ // Trinket, Gemma, etc.
- if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
- #endif
- // Initialize things
- randomSeed(analogRead(0));
- pixels.begin();
- //get current EEPROM value, then rotate for the next reboot
- eepromFlags = EEPROM.read(0);
- nexteeprom = eepromFlags + 1;
- if (nexteeprom > 2) {
- // Only 2 modes, reset to mode 0
- nexteeprom = 0;
- }
- EEPROM.write(0, nexteeprom);
- // If mode indication is on, show that.
- if (modeIndicatior) {
- pixels.setBrightness(5);
- for (int i = 0; i < eepromFlags + 1; i++) {
- pixels.setPixelColor(i, 255, 255, 255);
- }
- pixels.show();
- delay(500);
- pixels.clear();
- pixels.show();
- }
- }
- void white() {
- if (!initFlag) {
- pixels.setBrightness(100);
- for (int i = 0; i < 31; i++) {
- pixels.setPixelColor(i, 255, 255, 255);
- }
- pixels.show();
- initFlag = true;
- }
- delay(1000);
- }
- void rainbow(uint8_t wait) {
- uint16_t i, j;
- if (!initFlag) {
- pixels.setBrightness(40);
- initFlag = true;
- }
- for (j = 0; j < 256; j++) {
- for (i = 0; i < pixels.numPixels(); i++) {
- pixels.setPixelColor(i, Wheel((i * 1 + j) & 255));
- }
- pixels.show();
- delay(wait);
- }
- }
- void adawheel() {
- uint8_t i;
- if (!initFlag) {
- pixels.setBrightness(40);
- initFlag = true;
- }
- for (i = 0; i < 16; i++) {
- uint32_t c = 0;
- if (((offset + i) & 7) < 2) c = color; // 4 pixels on...
- pixels.setPixelColor( i, c); // First eye
- pixels.setPixelColor(31 - i, c); // Second eye (flipped)
- }
- pixels.show();
- offset++;
- delay(50);
- }
- // Input a value 0 to 255 to get a color value.
- // The colours are a transition r - g - b - back to r.
- uint32_t Wheel(byte WheelPos) {
- if (WheelPos < 85) {
- return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
- }
- else if (WheelPos < 170) {
- WheelPos -= 85;
- return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
- }
- else {
- WheelPos -= 170;
- return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
- }
- }
- void loop() {
- // put your main code here, to run repeatedly:
- switch (eepromFlags) {
- case 0:
- // Simple flashlight mode created by me
- // "Dude turn off your brights"
- white();
- break;
- case 1:
- // Neopixel rainbow by mattnupen.
- // Best way to put it is fading colors
- rainbow(30);
- break;
- case 2:
- // Spinning color Wheel created by adafruit.
- // Color set in the color variable
- adawheel();
- break;
- default:
- // Spillover/EEPROM overflow code.
- // Slow blinking white
- white();
- delay(200);
- pixels.clear();
- pixels.show();
- initFlag = false;
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement