Created
April 8, 2021 23:27
-
-
Save bennamallory/582fcf48d42ac373bffa45e68f509675 to your computer and use it in GitHub Desktop.
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
/* Author: Mallory Benna | |
* Date: April 8, 2021 | |
* Purpose: To test input for changing NeoPixel display by function control | |
*/ | |
#include <Adafruit_NeoPixel.h> //import NeoPixel library | |
#define LED_PIN 8 //Pin connected to NeoPixel on Arduino | |
#define LED_COUNT 256 // Number of NeoPixels attached to Arduiino | |
// Define NeoPixel Object | |
// LED_COUNT = Number of pixels in NeoPixel strip | |
// LED_PIN = Arduino pin number | |
// Pixel type flags: | |
// NEO_GRB = Pixels wired fro GRB bitstream | |
// NEO_KHZ800 = 800 KHz bitstream (most NeoPixel products with WS2812 LEDs) | |
Adafruit_NeoPixel neoPix(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); | |
//Structure to hold mapped values from Excel | |
struct MappedVals{ | |
int location; | |
int R; | |
int G; | |
int B; | |
}; | |
void setup() { | |
neoPix.begin(); //Initialize the neoPixel | |
neoPix.show(); //Turn all pixels 'off' | |
Serial.begin(9600); | |
} | |
void loop() { | |
// while new data is available on the serial port | |
while (Serial.available() > 0) { | |
int receivedData = Serial.parseInt(); // parse an incoming ASCII integer and store it in a variable | |
// When reaching the line break | |
if (Serial.read() == '\n') { | |
// Check whether the data is in the correct range that we need | |
if (receivedData >= 0 && receivedData <= 3) { | |
//set function | |
if(receivedData == 1){ | |
X(0; | |
} | |
} | |
} | |
} | |
} | |
//Function to map Excel Image to NeoPixel Index from: https://www.youtube.com/watch?v=A_S3LAUQHwU | |
MappedVals mapLEDXY(int y, int x, int RED, int GREEN, int BLUE) { | |
int RGBlocation = 0; | |
if (y % 2 == 0) { //even column | |
RGBlocation = x + y * 16; | |
} else { //odd column | |
RGBlocation = 15 - x + y * 16; | |
} | |
MappedVals valuesMap; //instantiate new struct | |
//set struct values | |
valuesMap.location = RGBlocation; | |
valuesMap.R = RED; | |
valuesMap.G = GREEN; | |
valuesMap.B = BLUE; | |
return valuesMap; | |
} | |
void X() { | |
neoPix.clear(); | |
MappedVals mappedValuesArr[] = { mapLEDXY(0, 0, 0, 0, 10), mapLEDXY(0, 15, 0, 0, 10), mapLEDXY(1, 1, 0, 0, 10), | |
mapLEDXY(1, 14, 0, 0, 10), mapLEDXY(2, 2, 0, 0, 10), mapLEDXY(2, 13, 0, 0, 10), | |
mapLEDXY(3, 3, 0, 0, 10), mapLEDXY(3, 12, 0, 0, 10), mapLEDXY(4, 4, 0, 0, 10), | |
mapLEDXY(4, 11, 0, 0, 10), mapLEDXY(5, 5, 0, 0, 10), mapLEDXY(5, 10, 0, 0, 10), | |
mapLEDXY(6, 6, 0, 0, 10), mapLEDXY(6, 9, 0, 0, 10), mapLEDXY(7, 7, 0, 0, 10), | |
mapLEDXY(7, 8, 0, 0, 10), mapLEDXY(8, 7, 0, 0, 10), mapLEDXY(8, 8, 0, 0, 10), | |
mapLEDXY(9, 6, 0, 0, 10), mapLEDXY(9, 9, 0, 0, 10), mapLEDXY(10, 5, 0, 0, 10), | |
mapLEDXY(10, 10, 0, 0, 10), mapLEDXY(11, 4, 0, 0, 10), mapLEDXY(11, 11, 0, 0, 10), | |
mapLEDXY(12, 3, 0, 0, 10), mapLEDXY(12, 12, 0, 0, 10), mapLEDXY(13, 2, 0, 0, 10), | |
mapLEDXY(13, 13, 0, 0, 10), mapLEDXY(14, 1, 0, 0, 10), mapLEDXY(14, 14, 0, 0, 10), | |
mapLEDXY(15, 0, 0, 0, 10), mapLEDXY(15, 15, 0, 0, 10) }; | |
for(int i=0; i < 32; i++){ | |
neoPix.setPixelColor(mappedValuesArr[i].location,mappedValuesArr[i].R,mappedValuesArr[i].G,mappedValuesArr[i].B); | |
neoPix.show(); | |
} | |
delay(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment