Guest User

Untitled

a guest
Dec 8th, 2017
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.25 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.  
  21. void setup()
  22. {
  23.   FastLED.addLeds<CHIPSET, DATA_PIN, GRB>(leds, NUM_LEDS); //see doc for different LED strips
  24.   FastLED.setBrightness(50);
  25. //  Serial.begin(BAUD_RATE); // when using Glediator via usb
  26.   Serial.begin(115200);
  27.  
  28.   for(int y = 0 ; y < NUM_LEDS ; y++)
  29.   {
  30.     leds[y] = CRGB::Black; // set all leds to black during setup
  31.   }
  32.   FastLED.show();
  33.  
  34.   pinMode(10, OUTPUT); // CS/SS pin as output for SD library to work.
  35.   digitalWrite(10, HIGH); // workaround for sdcard failed error...
  36.  
  37.   if (!SD.begin(BUILTIN_SDCARD))
  38.   {
  39.     Serial.println("sdcard initialization failed!");
  40.     return;
  41.   }
  42.   Serial.println("sdcard initialization done.");
  43.  
  44.   // test file open
  45.   fxdata = SD.open("dwain1.out");  // read only
  46.   if (fxdata)
  47.   {
  48.     Serial.println("file open ok");
  49.     fxdata.close();
  50.   }
  51. }
  52.  
  53. int serialGlediator ()
  54. {
  55.   while (!Serial.available()) {}
  56.   return Serial.read();
  57. }
  58.  
  59. void loop()
  60. {
  61.  
  62. // uncomment for Glediator
  63. //while (fileGlediator () != CMD_NEW_DATA) {}
  64. //Serial.readBytes((char*)leds, NUM_LEDS*3);
  65.  
  66.   fxdata = SD.open("dwain1.out");  // read only
  67.   if (fxdata)
  68.     {
  69.       Serial.println("file open ok");
  70.     }
  71.  
  72.   while (fxdata.available())
  73.   {
  74.     fxdata.readBytes((char*)leds, NUM_LEDS*3);
  75.      /*for (int i=0; i < NUM_LEDS; i++) {
  76.       leds[i].r = fxdata.read();
  77.       leds[i].g = fxdata.read();
  78.       leds[i].b = fxdata.read();
  79.     }*/
  80.    
  81.     ledSort(1);  //1-4 possible, set your first LED's position. Change the number: 1=TL(top left),2=TR(top right),3=BL(bottom left),4=BR(bottom right)
  82.      FastLED.show();
  83.     delay(150); // set the speed of the animation. 20 is appx ~ 500k bauds
  84.   }
  85.  
  86.   // close the file in order to prevent hanging IO or similar throughout time
  87.   fxdata.close();
  88. }
  89.  
  90. int ledSort (int modus) { //1=TL,2=TR,3=BL,4=BR, this function will rearrange the led array ;-)
  91.     CRGB tmp[x];
  92.     if(modus == 3 || modus == 4) {
  93.  
  94.     for(int i = 0; i < (y / 2);i++) {
  95.         for(int j = 0; j < x;j++) {
  96.         tmp[j] = leds[i * x + j];
  97.         leds[i * x] = leds[(y - i - 1) * x];
  98.         leds[(y - i - 1) * x] = tmp[j];
  99.          }
  100.         }
  101.      }
  102.  
  103.      if(modus == 1 || modus == 3) {
  104.        for(int i = 1; i < y; i = i + 2) {
  105.        for(int j = x; j > 0;j--) {
  106.         tmp[(x - j)] = leds[i * x + j - 1];
  107.           }
  108.            for(int j = 0; j < x;j++) {
  109.         leds[i * x + j] = tmp[j];
  110.         }
  111.        }
  112.  
  113.       }
  114.  
  115.  
  116.      if(modus == 2 | modus == 4) {
  117.       for(int i = 0; i < y; i = i + 2) {
  118.        for(int j = x; j > 0;j--) {
  119.         tmp[(x - j)] = leds[i * x + j - 1];
  120.           }
  121.            for(int j = 0; j < x;j++) {
  122.         leds[i * x + j] = tmp[j];
  123.         }
  124.        }
  125.  
  126.       }
  127.       return 1;
  128. }
Advertisement
Add Comment
Please, Sign In to add comment