Guest User

Untitled

a guest
Dec 9th, 2017
694
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.50 KB | None | 0 0
  1. // Glediator Arduino UNO sketch by Jens Andrée
  2. // Some changes and testing by Nils Gregersen, www.hamburgtech.de, [email protected]
  3. // sdcard bug fixed by Pascal also from Hamburg, [email protected]
  4.  
  5.  
  6. #include <FastLED.h>
  7. #include <SPI.h>
  8. #include <SD.h>
  9.  
  10. #define NUM_LEDS 364 // LED number
  11. #define DATA_PIN 2    // your data arduino pin
  12. #define CHIPSET WS2811  // your LED chip type
  13. #define CMD_NEW_DATA 1
  14. //#define BAUD_RATE 500000  //if using Glediator via serial
  15. unsigned char x = 11; // matrix x size
  16. unsigned char y = 11; // matrix y size
  17.  
  18. File fxdata;
  19. CRGB leds[NUM_LEDS];
  20. CRGB tmp[NUM_LEDS];
  21.  
  22. const uint16_t XYTable[] = {
  23.      0,  51,  52, 103, 104, 155, 156, 207, 208, 259, 260, 311, 312, 363, 364, 415,
  24.      1,  50,  53, 102, 105, 154, 157, 206, 209, 258, 261, 310, 313, 362, 365, 414,
  25.      2,  49,  54, 101, 106, 153, 158, 205, 210, 257, 262, 309, 314, 361, 366, 413,
  26.      3,  48,  55, 100, 107, 152, 159, 204, 211, 256, 263, 308, 315, 360, 367, 412,
  27.      4,  47,  56,  99, 108, 151, 160, 203, 212, 255, 264, 307, 316, 359, 368, 411,
  28.      5,  46,  57,  98, 109, 150, 161, 202, 213, 254, 265, 306, 317, 358, 369, 410,
  29.      6,  45,  58,  97, 110, 149, 162, 201, 214, 253, 266, 305, 318, 357, 370, 409,
  30.      7,  44,  59,  96, 111, 148, 163, 200, 215, 252, 267, 304, 319, 356, 371, 408,
  31.      8,  43,  60,  95, 112, 147, 164, 199, 216, 251, 268, 303, 320, 355, 372, 407,
  32.      9,  42,  61,  94, 113, 146, 165, 198, 217, 250, 269, 302, 321, 354, 373, 406,
  33.     10,  41,  62,  93, 114, 145, 166, 197, 218, 249, 270, 301, 322, 353, 374, 405,
  34.     11,  40,  63,  92, 115, 144, 167, 196, 219, 248, 271, 300, 323, 352, 375, 404,
  35.     12,  39,  64,  91, 116, 143, 168, 195, 220, 247, 272, 299, 324, 351, 376, 403,
  36.     13,  38,  65,  90, 117, 142, 169, 194, 221, 246, 273, 298, 325, 350, 377, 402,
  37.     14,  37,  66,  89, 118, 141, 170, 193, 222, 245, 274, 297, 326, 349, 378, 401,
  38.     15,  36,  67,  88, 119, 140, 171, 192, 223, 244, 275, 296, 327, 348, 379, 400,
  39.     16,  35,  68,  87, 120, 139, 172, 191, 224, 243, 276, 295, 328, 347, 380, 399,
  40.     17,  34,  69,  86, 121, 138, 173, 190, 225, 242, 277, 294, 329, 346, 381, 398,
  41.     18,  33,  70,  85, 122, 137, 174, 189, 226, 241, 278, 293, 330, 345, 382, 397,
  42.     19,  32,  71,  84, 123, 136, 175, 188, 227, 240, 279, 292, 331, 344, 383, 396,
  43.     20,  31,  72,  83, 124, 135, 176, 187, 228, 239, 280, 291, 332, 343, 384, 395,
  44.     21,  30,  73,  82, 125, 134, 177, 186, 229, 238, 281, 290, 333, 342, 385, 394,
  45.     22,  29,  74,  81, 126, 133, 178, 185, 230, 237, 282, 289, 334, 341, 386, 393,
  46.     23,  28,  75,  80, 127, 132, 179, 184, 231, 236, 283, 288, 335, 340, 387, 392,
  47.     24,  27,  76,  79, 128, 131, 180, 183, 232, 235, 284, 287, 336, 339, 388, 391,
  48.     25,  26,  77,  78, 129, 130, 181, 182, 233, 234, 285, 286, 337, 338, 389, 390
  49.   };
  50.  
  51. void setup()
  52. {
  53.   FastLED.addLeds<CHIPSET, DATA_PIN, GRB>(leds, NUM_LEDS); //see doc for different LED strips
  54.   FastLED.setBrightness(30);
  55.   //  Serial.begin(BAUD_RATE); // when using Glediator via usb
  56.   Serial.begin(115200);
  57.  
  58.   for (int y = 0 ; y < NUM_LEDS ; y++)
  59.   {
  60.     leds[y] = CRGB::Black; // set all leds to black during setup
  61.   }
  62.   FastLED.show();
  63.  
  64.   pinMode(10, OUTPUT); // CS/SS pin as output for SD library to work.
  65.   digitalWrite(10, HIGH); // workaround for sdcard failed error...
  66.  
  67.   if (!SD.begin(BUILTIN_SDCARD))
  68.   {
  69.     Serial.println("sdcard initialization failed!");
  70.     return;
  71.   }
  72.   Serial.println("sdcard initialization done.");
  73.  
  74.   // test file open
  75.   fxdata = SD.open("dwain1.out");  // read only
  76.   if (fxdata)
  77.   {
  78.     Serial.println("file open ok");
  79.     fxdata.close();
  80.   }
  81. }
  82.  
  83. int serialGlediator ()
  84. {
  85.   while (!Serial.available()) {}
  86.   return Serial.read();
  87. }
  88.  
  89. void loop()
  90. {
  91.   fxdata = SD.open("dwain.dat");  // read only
  92.   if (fxdata)
  93.   {
  94.     Serial.println("file open ok");
  95.   }
  96.  
  97.   while (fxdata.available())
  98.   {
  99.     for (int i=0; i < NUM_LEDS; i++) {
  100.       tmp[i].r = 0;//fxdata.read();
  101.       tmp[i].g = 0;//fxdata.read();
  102.       tmp[i].b = 0;//fxdata.read();
  103.     }
  104.     //fxdata.readBytes((char*)tmp, NUM_LEDS * 3);
  105.  
  106.     tmp[1].r=255;
  107.     //tmp[2].b=255;
  108.  
  109.     for (int i=0; i < NUM_LEDS; i++) {
  110.       //leds[i] = tmp[i];
  111.       leds[i] = tmp[XYTable[i]];
  112.  
  113.       Serial.print(i);
  114.       Serial.print(" = ");
  115.       Serial.print(XYTable[i]);
  116.       Serial.print(" = ");
  117.       Serial.print(tmp[i]);
  118.       //Serial.print(tmp[XYTable[i]].g);
  119.       //Serial.print(tmp[XYTable[i]].b);
  120.       Serial.println();
  121.     }
  122.    
  123.     FastLED.show();
  124.   }
  125.   fxdata.close();
  126. }
Advertisement
Add Comment
Please, Sign In to add comment