Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <LedControl.h>
- #include "data.h"
- #include <Wire.h>
- #include <LiquidCrystal.h>
- /*
- # the data looks like this
- int data[][2] = {
- {6,10},
- {0,14},
- {9,10},
- ...
- }
- */
- LedControl lc = LedControl(7, 9, 8);
- const int rs = 12, en = 11, d4 = 2, d5 = 3, d6 = 4, d7 = 5;
- LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
- int lx = 0;
- int ly = 0;
- bool ledData[6][47] = {{false}};
- void foldX(int line){
- for (size_t i = 0; i < sizeof data/sizeof data[0] ; i++)
- {
- if(data[i][0] > line)
- data[i][0] = line - (data[i][0] - line);
- }
- }
- void foldY(int line){
- for (size_t i = 0; i < sizeof data/sizeof data[0] ; i++)
- {
- if(data[i][1] > line)
- data[i][1] = line - (data[i][1] - line);
- }
- }
- int countDots(){
- size_t columns = sizeof data/sizeof data[0];
- long unique[columns];
- size_t index = 0;
- for (size_t i = 0; i < columns ; i++)
- {
- lx = max(lx,data[i][0]);
- ly = max(ly,data[i][1]);
- long hash = data[i][1]*columns + data[i][0];
- bool isUnique = true;
- for (size_t j = 0; j < index; j++)
- {
- if(hash == unique[j]){
- isUnique = false;
- break;
- }
- }
- if(isUnique){
- unique[index]=hash;
- index++;
- }
- }
- return index;
- }
- static int comp(const void* p1, const void* p2) {
- int* arr1 = (int*)p1;
- int* arr2 = (int*)p2;
- int diff1 = arr1[1] - arr2[1];
- if (diff1) return diff1;
- return arr1[0] - arr2[0];
- }
- void setleds(int offset){
- for (size_t y = 0; y < 6; y++)
- {
- for (size_t x= 0; x < 8; x++)
- {
- int xPos = (x+offset)%47;
- lc.setLed(0,y+1,x,ledData[y][xPos]);
- }
- }
- }
- void setup() {
- Serial.begin(9600);
- while(!Serial);
- lc.shutdown(0,false);
- lc.setIntensity(0,8);
- lc.clearDisplay(0);
- lcd.begin(16, 2);
- lcd.setCursor(0, 0);
- lcd.print(" HELLO REDDIT! ");
- lcd.setCursor(0, 1);
- lcd.print( " DAY 13 PART 2 " );
- /*
- foldY(7);
- foldX(5);
- */
- foldX(655);
- foldY(447);
- foldX(327);
- foldY(223);
- foldX(163);
- foldY(111);
- foldX(81);
- foldY(55);
- foldX(40);
- foldY(27);
- foldY(13);
- foldY(6);
- qsort(data, sizeof(data) / sizeof(data[0]), sizeof(data[0]), comp);
- int count = countDots();
- int index = 0;
- size_t columns = sizeof data/sizeof data[0];
- for (int y = 0; y <= ly; y++)
- {
- for (int x = 0; x <= lx; x++)
- {
- if(data[index][0] == x && data[index][1] == y){
- Serial.print("#");
- ledData[y][x+8] = true;
- while(data[index][0] == x && data[index][1] == y)
- index++;
- }
- else{
- Serial.print(" ");
- }
- }
- Serial.println();
- }
- for (size_t y = 0; y < 8; y++)
- {
- for (size_t x= 0; x < 8; x++)
- {
- lc.setLed(0,8-y,x,true);
- }
- delay(100);
- }
- delay(500);
- for (size_t y = 0; y < 8; y++)
- {
- for (size_t x= 0; x < 8; x++)
- {
- lc.setLed(0,8-y,x,false);
- }
- delay(100);
- }
- lc.clearDisplay(0);
- }
- int offset = 0;
- void loop() {
- setleds(offset++);
- delay(150);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement