Skip to content

Instantly share code, notes, and snippets.

@SharpCoder
Created February 2, 2020 21:19
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 SharpCoder/e7000aed0fc098f9548cf7ddec2d3b66 to your computer and use it in GitHub Desktop.
Save SharpCoder/e7000aed0fc098f9548cf7ddec2d3b66 to your computer and use it in GitHub Desktop.
Hexagon Sigil Arduino Code
#include <Adafruit_NeoPixel.h>
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN 7
// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 2
// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_RGB + NEO_KHZ800);
bool down = false;
unsigned int w_min= 1;
unsigned int w_max = 254;
unsigned int w_speed = 24;
unsigned int j = w_min;
struct rgb {
unsigned char r = 0, g = 0, b = 0;
} rgb_t;
int i = 0;
double bv = 0.0;
rgb wheel(unsigned int);
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
strip.setBrightness(128);
j = (w_max - w_min) / 2;
rgb origin = wheel(w_min);
for (i = 0; i < LED_COUNT; i++) {
strip.setPixelColor(i, origin.r, origin.g, origin.b);
}
strip.show(); // Initialize all pixels to 'off'
strip.begin();
pinMode(A0, INPUT);
double value = 0.0;
for (i; i < 4; i++) {
delay(50);
value += (double)analogRead(A0);
}
value = (value / 4);
bv = 100 * (value / 1024.0);
if (bv <= 25) {
w_min = 1;
w_max = 22;
w_speed = 50;
}
}
rgb wheel(unsigned int j){
unsigned int wp = 255 - j;
rgb resp;
if (wp < 85) {
resp.r = 255 - (wp * 3);
resp.g = 0;
resp.b = wp * 3;
} else if (wp < 170) {
wp -= 85;
resp.r = 0;
resp.g = wp * 3;
resp.b = 255 - wp * 3;
} else {
wp -= 170;
resp.r = wp * 3;
resp.g = 255 - wp * 3;
resp.b = 0;
}
return resp;
}
void loop() {
if (j < w_min) {
down = false;
j = w_min;
}
else if (j > w_max) {
j = w_max;
down = true;
}
if (down) --j;
else ++j;
rgb colors = wheel(j);
for (i = 0; i < LED_COUNT; i++) {
strip.setPixelColor(i, colors.r, colors.g, colors.b);
}
strip.setBrightness(128 + 32);
strip.show(); // Update
delay(w_speed);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment