Skip to content

Instantly share code, notes, and snippets.

@DarkDust
Created May 1, 2017 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarkDust/9120994bbf5058ba833d4468e8ea5b95 to your computer and use it in GitHub Desktop.
Save DarkDust/9120994bbf5058ba833d4468e8ea5b95 to your computer and use it in GitHub Desktop.
AVR/GCC bug?
// 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>
#endif
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
#define PIN PB3
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 24
// When we setup 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 = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int phase = 0;
int direction = 1;
void setup() {
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
pixels.begin();
pixels.setBrightness(8);
pixels.show();
}
void hexdump(uint32_t value) {
for (int i = 0; i < 12; ++i) {
pixels.setPixelColor(i+12, 0, 0, ((value >> i) & 1) * 255);
}
}
// I'd like to use a global variable but the program does not work when I
// *write* to to. If I only read it everything is fine.
// uint8_t kitt[12];
void loop()
{
// Instead, I need to use a stack variable.
uint8_t kitt[12];
for (int k = 0; k < 24; k++) {
for (int i = 0; i < 12; i++) {
kitt[i] /= 2;
}
kitt[phase] = 255;
if (phase == 0) {
direction = 1;
} else if (phase == 11) {
direction = -1;
}
phase += direction;
for (int i = 0; i < 12; i++) {
pixels.setPixelColor(i, 0, kitt[i], 0);
pixels.setPixelColor(23-i, kitt[i], 0, 0);
}
pixels.show();
delay(150);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment