-
Notifications
You must be signed in to change notification settings - Fork 0
Add files via upload #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,255 @@ | ||
| #include <EEPROM.h> | ||
| #include <Adafruit_NeoPixel.h> | ||
|
|
||
| /// @brief Loads the last saved colors and delays into the current arrays. | ||
| void loadLast() | ||
| { | ||
| uint16_t buf = 0; | ||
| for (uint8_t k = 0; k < FRAME_COUNT; k++) | ||
| { | ||
| for (uint8_t l = 0; l < LED_COUNT; l++) | ||
| { | ||
| buf = colorsLast[k][l]; | ||
| colorsLast[k][l] = colors[k][l]; | ||
| colors[k][l] = buf; | ||
| } | ||
| buf = delayLast[k]; | ||
| delayLast[k] = cycleDelay[k]; | ||
| cycleDelay[k] = buf; | ||
| } | ||
| } | ||
|
|
||
| void printNumPadded(uint16_t in) { | ||
| if(in == 255) { | ||
| Serial.print("---"); //Special case in matrix printing | ||
| } else if (in < 10) { | ||
| Serial.print(" "); | ||
| Serial.print(in); | ||
| Serial.print(" "); | ||
| } else if (in < 100) { | ||
| Serial.print(" "); | ||
| Serial.print(in); | ||
| } else { | ||
| Serial.print(in); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| /// @brief Saves the current colors and delays into the "last" arrays for potential later retrieval. Call this before making changes to the current arrays if you want to be able to easily revert back to the previous state. | ||
| void saveLast() | ||
| { | ||
| for (uint8_t k = 0; k < FRAME_COUNT; k++) | ||
| { | ||
| for (uint8_t l = 0; l < LED_COUNT; l++) | ||
| { | ||
| colorsLast[k][l] = colors[k][l]; | ||
| } | ||
| delayLast[k] = cycleDelay[k]; | ||
| } | ||
| } | ||
|
|
||
| /// @brief Clears all colors and delays from the current arrays and the strip. | ||
| void clear() | ||
| { | ||
| for (uint8_t k = 0; k < FRAME_COUNT; k++) | ||
| { | ||
| for (uint8_t l = 0; l < LED_COUNT; l++) | ||
| { | ||
| colors[k][l] = 0; | ||
| } | ||
| cycleDelay[k] = 0; | ||
| strip.clear(); | ||
| strip.show(); | ||
| } | ||
| } | ||
|
|
||
| /// @brief Clears the colors for a specific frame. | ||
| void clear(uint8_t k) | ||
| { | ||
| for (uint8_t l = 0; l < LED_COUNT; l++) | ||
| { | ||
| colors[k][l] = 0; | ||
| } | ||
| strip.clear(); | ||
| strip.show(); | ||
| } | ||
|
|
||
| ///@brief Generates a color. | ||
| uint32_t c(uint8_t r, uint8_t g, uint8_t b) | ||
| { | ||
| return strip.Color(r, g, b); | ||
| } | ||
|
|
||
| ///@brief Generates black color. | ||
| uint32_t c() | ||
| { | ||
| return strip.Color(0, 0, 0); | ||
| } | ||
|
|
||
| uint32_t c(uint32_t in, bool silent = true) | ||
| { | ||
|
|
||
| uint8_t r = floor(in / 100); | ||
| uint8_t g = floor((in - (100 * r)) / 10); | ||
| uint8_t b = floor(in - (100 * r) - (10 * g)); | ||
|
|
||
| r = constrain(r, 0, 9); | ||
| g = constrain(g, 0, 9); | ||
| b = constrain(b, 0, 9); | ||
|
|
||
| uint8_t newr = 3 * r * r; | ||
| uint8_t newg = 3 * g * g; | ||
| uint8_t newb = 3 * b * b; | ||
|
|
||
| if (r == 1) | ||
| { | ||
| newr = 6; | ||
| } | ||
|
|
||
| if (g == 1) | ||
| { | ||
| newg = 6; | ||
| } | ||
|
|
||
| if (b == 1) | ||
| { | ||
| newb = 6; | ||
| } | ||
|
|
||
| if (!silent) | ||
| { | ||
| Serial.print("> Color code `"); | ||
| Serial.print(in); | ||
| Serial.print("`: rgb("); | ||
| Serial.print(newr); | ||
| Serial.print(", "); | ||
| Serial.print(newg); | ||
| Serial.print(", "); | ||
| Serial.print(newb); | ||
| Serial.print(")"); | ||
| Serial.println(); | ||
| } | ||
|
|
||
| return strip.Color(newr, newg, newb); | ||
| } | ||
|
|
||
| /// @brief Saves the current colors and delays to EEPROM. | ||
| void saveEEPROM() | ||
| { | ||
| EEPROM.write(0, 1); // Set a flag to indicate that data is saved | ||
| EEPROM.put(1, colors); | ||
| EEPROM.put(sizeof(colors) + 1, cycleDelay); | ||
| } | ||
|
|
||
| /// @brief Loads the colors and delays from EEPROM into the current arrays. | ||
| /// @return true if data was successfully loaded, false if no valid data was found. | ||
| bool loadEEPROM() | ||
| { | ||
| if (EEPROM.read(0) != 1) | ||
| { | ||
| return false; | ||
| } | ||
| EEPROM.get(1, colors); | ||
| EEPROM.get(sizeof(colors) + 1, cycleDelay); | ||
| return true; | ||
| } | ||
|
|
||
| /// @brief Clears all data from EEPROM. | ||
| void clearEEPROM() | ||
| { | ||
| for (int i = 0; i < EEPROM.length(); i++) | ||
| { | ||
| EEPROM.write(i, 0); | ||
| } | ||
| } | ||
|
|
||
| void toggleBuiltin(){ | ||
| if (LEDBuiltinOn) { | ||
| digitalWrite(LED_BUILTIN, LOW); | ||
| } else { | ||
| digitalWrite(LED_BUILTIN, HIGH); | ||
| } | ||
| LEDBuiltinOn = !LEDBuiltinOn; | ||
| } | ||
|
|
||
| /// @brief Transforms an x and y value into an LED index based on the MATRIX array. | ||
| uint8_t xyToIndex(int x, int y) | ||
| { | ||
| if (x < 0 || x >= MATRIX_WIDTH || y < 0 || y >= MATRIX_HEIGHT) | ||
| { | ||
| Serial.println("> Warning: xyToIndex: 'cell (" + String(x) + "," + String(y) + ") is out of bounds'"); | ||
| return 255; | ||
| } | ||
|
|
||
| uint8_t index = pgm_read_byte(&(MATRIX[y][x])); | ||
| if (index == 255) | ||
| { | ||
| Serial.println("> Warning: xyToIndex: 'cell (" + String(x) + "," + String(y) + ") is empty'"); | ||
| return 255; | ||
| } | ||
| return index; | ||
| } | ||
|
|
||
| uint8_t indToX(uint8_t ind){ | ||
| for(uint8_t y = 0; y < MATRIX_HEIGHT; y++){ | ||
| for(uint8_t x = 0; x < MATRIX_WIDTH; x++){ | ||
| if(pgm_read_byte(&(MATRIX[y][x])) == ind){ | ||
| return x; | ||
| } | ||
| } | ||
| } | ||
| return 255; | ||
| } | ||
|
|
||
| uint8_t indToY(uint8_t ind){ | ||
| for(uint8_t y = 0; y < MATRIX_HEIGHT; y++){ | ||
| for(uint8_t x = 0; x < MATRIX_WIDTH; x++){ | ||
| if(pgm_read_byte(&(MATRIX[y][x])) == ind){ | ||
| return y; | ||
| } | ||
| } | ||
| } | ||
| return 255; | ||
| } | ||
|
|
||
| String extractCmd(String in){ | ||
| while (in.indexOf('\n') != -1) { | ||
| in = in.substring(0, in.indexOf('\n')); | ||
| } | ||
| uint8_t idxStr = in.indexOf(' '); | ||
| if(idxStr == -1){ | ||
| return in; | ||
| } else { | ||
| return in.substring(0, idxStr); | ||
| } | ||
| } | ||
|
|
||
| uint8_t parseIntCharsToBurn(String s) { | ||
| uint8_t parseIntIdx = 0; | ||
| bool shouldFinish = false; | ||
| while (!shouldFinish) { | ||
| if (isDigit(s.charAt(parseIntIdx))) { | ||
| parseIntIdx++; | ||
| } else { | ||
| shouldFinish = true; | ||
| } | ||
| } | ||
| return parseIntIdx; | ||
| } | ||
|
|
||
| int parseInt(String s) { | ||
| uint8_t parseIntIdx = 0; | ||
| int out = 0; | ||
| bool shouldFinish = false; | ||
| while (!shouldFinish) { | ||
| if (isDigit(s.charAt(parseIntIdx))) { | ||
| out *= 10; | ||
| out += s.substring(parseIntIdx, parseIntIdx + 1).toInt(); | ||
| parseIntIdx++; | ||
| } else { | ||
| shouldFinish = true; | ||
| } | ||
| } | ||
| return out; | ||
| } | ||
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| #include <Adafruit_NeoPixel.h> | ||
| #include <EEPROM.h> | ||
| #include "Matrix.h" | ||
|
|
||
| #define PARITY_EVEN 2 | ||
| #define PARITY_ODD 1 | ||
| #define PARITY_ALL 0 | ||
|
28pins marked this conversation as resolved.
|
||
|
|
||
| bool LEDBuiltinOn = false; | ||
|
|
||
| uint16_t cycleDelay[FRAME_COUNT]; | ||
| uint16_t delayLast[FRAME_COUNT]; | ||
| uint16_t colors[FRAME_COUNT][LED_COUNT]; | ||
| uint16_t colorsLast[FRAME_COUNT][LED_COUNT]; | ||
|
|
||
| Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_RGB + NEO_KHZ800); | ||
|
|
||
| void setup() | ||
| { | ||
| toggleBuiltin(); | ||
| pinMode(13, OUTPUT); | ||
| strip.begin(); | ||
|
28pins marked this conversation as resolved.
|
||
| strip.show(); | ||
| Serial.begin(9600); | ||
| Serial.println(F("> ####################> SERIAL LIGHT SHOW <####################")); | ||
| toggleBuiltin(); | ||
| Serial.println(F("> Version 0.0.0 [beta]")); | ||
| Serial.println(F("> **Warning:** Set line ending to `New Line` for proper parsing.")); | ||
| Serial.println(F("> Type `help` for help")); | ||
| Serial.println("> Currently configured with " + String(LED_COUNT) + " LEDs and " + String(FRAME_COUNT) + " frames. Feature flags: cacheCmds: NO; textDisp: NO; WiFi: NO"); | ||
| toggleBuiltin(); | ||
| if (loadEEPROM()) | ||
| { | ||
| Serial.println(F("> Saved data found in EEPROM and loaded successfully.")); | ||
| } | ||
| else | ||
| { | ||
| Serial.println(F("> No saved data found in EEPROM.")); | ||
| } | ||
| Serial.println(F("> Ready for command \n")); | ||
| toggleBuiltin(); | ||
| } | ||
|
|
||
| uint16_t bm = 0; | ||
|
|
||
| void loop() | ||
| { | ||
| serialHandle(); | ||
| for (uint8_t i = 0; i < FRAME_COUNT; i++) | ||
| { | ||
| if(cycleDelay[i] == 254) { //Text flag | ||
| for (uint8_t j = 1; j < LED_COUNT; j++) { | ||
| if (colors[i][j] == 0) { | ||
| break; | ||
| } else { | ||
| //textLoop(i, j); | ||
| serialHandle(); | ||
| } | ||
| } | ||
| } else { | ||
| if(cycleDelay[i] != 0){ | ||
| colorLoop(i); | ||
| toggleBuiltin(); | ||
| } | ||
| bm = cycleDelay[i]; | ||
| if (bm > 0){ | ||
| while(bm > 3000){ | ||
| toggleBuiltin(); | ||
| delay(50); | ||
| toggleBuiltin(); | ||
| delay(50); | ||
| toggleBuiltin(); | ||
| delay(50); | ||
| toggleBuiltin(); | ||
| delay(50); | ||
| toggleBuiltin(); | ||
| delay(50); | ||
| bm -= 500; | ||
| serialHandle(); | ||
| } | ||
| delay(bm); | ||
| bm = 0; | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.