Last active
February 25, 2021 17:48
-
-
Save mpflaga/b17a55e665d056f8062b62e107eed031 to your computer and use it in GitHub Desktop.
Simple sketch to increment and decrement a single NeoPixel on a string as to determine positions of interest for defining segments.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Adafruit_NeoPixel.h> | |
#ifdef __AVR__ | |
#include <avr/power.h> | |
#endif | |
#define PIN 6 | |
#define NUMPIXELS 500 | |
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); | |
int pos = 0; | |
void setup() { | |
Serial.begin(9600); | |
Serial.println(F("Started - Simple NeoPixel increamenter")); | |
Serial.println(F("(1 based Index)")); | |
Serial.println(F("'-' to decreament")); | |
Serial.println(F("'+' to increament")); | |
pixels.begin(); | |
pixels.clear(); | |
pixels.setPixelColor(pos, pixels.Color(128, 128, 128)); | |
pixels.show(); | |
} | |
void loop() { | |
if(Serial.available()) { | |
while (Serial.available()) { | |
byte inByte = Serial.read(); // get command from serial input | |
if(inByte == '-') { | |
if(pos > 0 ) { | |
pos--; | |
} | |
Serial.print(F("decreamenting pos = ")); | |
Serial.println(pos + 1); | |
} else if(inByte == '+') { | |
if(pos < NUMPIXELS ) { | |
pos++; | |
} | |
Serial.print(F("increamenting pos = ")); | |
Serial.println(pos + 1); | |
} | |
} | |
pixels.clear(); | |
pixels.setPixelColor(pos, pixels.Color(128, 128, 128)); | |
pixels.show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment