Advertisement
mkeyno

SPI sketch

Oct 17th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include <Arduino.h>
  2. #include <ESP8266WiFi.h>
  3. #include <FS.h>
  4. #include <Hash.h>
  5. #include <NeoPixelBus.h>
  6.  
  7. NeoPixelBus<DotStarBgrFeature, DotStarSpiMethod> strip(144);
  8.  
  9. static int Current_imageLine=0;
  10. static uint32_t _raw_location;
  11. uint8_t  * LED_BUFFER;
  12. static uint32_t _memory_pointer=0,frame_time=0;
  13. IPAddress apIP(192, 168, 4, 1);
  14. void setup() {
  15. Serial.begin(115200);
  16. delay(500);
  17. Serial.setDebugOutput(true);
  18. Serial.println(F("\n \nStarting....."));
  19. SPIFFS.begin();
  20. strip.Begin();
  21. WiFi.mode(WIFI_AP);
  22. WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
  23. WiFi.softAP("ESP_SPI","12345678");                                
  24. delay(500);  
  25. Serial.print("AP IP address: ");Serial.println(WiFi.softAPIP());
  26.                   _raw_location=(ESP.getSketchSize() + FLASH_SECTOR_SIZE - 1) & (~(FLASH_SECTOR_SIZE - 1));
  27.   _memory_pointer=_raw_location;
  28.   Serial.printf("New Start Address= %u\n",_raw_location);
  29.   LED_BUFFER = (uint8_t *)malloc(432);
  30. }
  31. void loop()
  32. {
  33.   ESP.flashRead(_memory_pointer,(uint32_t *) LED_BUFFER,432);  // it took around 13ms
  34.   for( int i = 0;i<432;  )    strip.SetPixelColor(i/3, RgbColor((byte)LED_BUFFER[i++], (byte)LED_BUFFER[i++],(byte)LED_BUFFER[i++])  );    
  35.   strip.Show();
  36. /*
  37. code of source  lib
  38. https://github.com/Makuna/NeoPixelBus/blob/70e3611bdff0274ac7e75700f83d7af680611547/src/internal/DotStarSpiMethod.h#L67-L90
  39. */
  40.   _memory_pointer+=(432);
  41.   Current_imageLine++;
  42.   if(Current_imageLine>=200)
  43.   {
  44.     Serial.printf("\nFrame took %u ms line=%d\n",  micros() - frame_time,Current_imageLine);
  45.                    //Frame took 241860 ms line=200
  46.     Current_imageLine=0;
  47.     _memory_pointer=_raw_location;
  48.     frame_time=micros();  
  49.   }    
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement