Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Dec 20th, 2017 110 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <SPI.h>
  3. #include <SD.h>
  4. #include <Wire.h>
  5. #include <Adafruit_GFX.h>
  6. #include <Adafruit_SSD1306.h>
  7. #include <ESP8266WiFi.h>
  8. #include <WiFiClientSecure.h>
  9.  
  10.  
  11. // Use web browser to view and copy
  12. // SHA1 fingerprint of the certificate
  13. const char* fingerprint = "CF 05 98 89 CA FF 8E D8 5E 5C E0 C2 E4 F7 E6 C3 C7 50 DD 5C";
  14.  
  15. File myFile;
  16. #define OLED_RESET LED_BUILTIN //4
  17. Adafruit_SSD1306 display(OLED_RESET);
  18.  
  19. #define NUMFLAKES 2
  20. #define XPOS 0
  21. #define YPOS 1
  22. #define DELTAY 2
  23. static int iter = 0;
  24. static String addr1 = "";
  25. static String currbal = "0.0";
  26. static String curr = "";
  27. static float addrval = 0;
  28. static String ssid;
  29. static String passwd;
  30. String line;
  31. WiFiClientSecure client;
  32.  
  33. byte smbtc[] = { 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x7f, 0xfe, 0x00, 0x01, 0xff, 0xff, 0x80, 0x03, 0xe0, 0x07, 0xc0,
  34. 0x07, 0x80, 0x01, 0xe0, 0x0f, 0x01, 0x90, 0xf0, 0x1e, 0x01, 0x98, 0x78, 0x3c, 0x11, 0x30, 0x3c,
  35. 0x38, 0x3f, 0xb0, 0x1c, 0x70, 0x1f, 0xf0, 0x0e, 0x70, 0x0f, 0xfc, 0x0e, 0x60, 0x0f, 0x7e, 0x06,
  36. 0xe0, 0x0e, 0x1e, 0x07, 0xe0, 0x1e, 0x0f, 0x07, 0xe0, 0x1e, 0x0e, 0x07, 0xe0, 0x1f, 0x9e, 0x07,
  37. 0xe0, 0x1f, 0xfc, 0x07, 0xe0, 0x1c, 0x3c, 0x07, 0xe0, 0x3c, 0x1e, 0x07, 0xe0, 0x3c, 0x0e, 0x07,
  38. 0x60, 0xfc, 0x1e, 0x06, 0x70, 0xff, 0xfe, 0x0e, 0x70, 0x1f, 0xfc, 0x0e, 0x38, 0x19, 0xf8, 0x1c,
  39. 0x3c, 0x19, 0x00, 0x3c, 0x1e, 0x13, 0x00, 0x78, 0x0f, 0x03, 0x00, 0xf0, 0x07, 0x80, 0x01, 0xe0,
  40. 0x03, 0xe0, 0x07, 0xc0, 0x01, 0xff, 0xff, 0x80, 0x00, 0x7f, 0xfe, 0x00, 0x00, 0x0f, 0xf0, 0x00 };
  41.  
  42. byte splashbtc[] =
  43. { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  44. 0xff, 0xff, 0xff, 0xff, 0xff, 0xf9, 0xf9, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  45. 0xff, 0xff, 0xff, 0xff, 0xff, 0xf9, 0xf9, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  46. 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0x9f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  47. 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  48. 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x73, 0x0e, 0x18, 0x73, 0x87, 0xff, 0xff, 0xff, 0xff, 0xff,
  49. 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x33, 0x0c, 0x10, 0x33, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff,
  50. 0xff, 0xff, 0xff, 0xff, 0xff, 0xe3, 0x32, 0x79, 0xe3, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
  51. 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0x26, 0x79, 0xe7, 0x26, 0x73, 0xff, 0xff, 0xff, 0xff, 0xff,
  52. 0xff, 0xff, 0xff, 0xff, 0xff, 0xe6, 0x26, 0x79, 0xe6, 0x26, 0x67, 0xff, 0xff, 0xff, 0xff, 0xff,
  53. 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x66, 0x18, 0x20, 0x66, 0x67, 0xff, 0xff, 0xff, 0xff, 0xff,
  54. 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xe7, 0x1c, 0x30, 0xe6, 0x67, 0xff, 0xff, 0xff, 0xff, 0xff,
  55. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  56. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  57. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  58. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  59. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  60. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  61. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  62. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  63. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x1f, 0xf8, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  64. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  65. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  66. 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x07, 0xfe, 0x7f, 0xe0, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff,
  67. 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x1f, 0xfe, 0x33, 0xf8, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
  68. 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x3f, 0xfc, 0x71, 0xfc, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff,
  69. 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x7f, 0xfc, 0x71, 0xfe, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff,
  70. 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xff, 0x1c, 0x73, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff,
  71. 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xfe, 0x00, 0x63, 0xff, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff,
  72. 0xff, 0xff, 0xff, 0xff, 0xff, 0xc1, 0xff, 0x00, 0x03, 0xff, 0x83, 0xff, 0xff, 0xff, 0xff, 0xff,
  73. 0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0xff, 0x80, 0x01, 0xff, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
  74. 0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0xff, 0xc0, 0x00, 0x7f, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
  75. 0xff, 0xff, 0xff, 0xff, 0xff, 0x87, 0xff, 0xc0, 0x00, 0x3f, 0xe1, 0xff, 0xff, 0xff, 0xff, 0xff,
  76. 0xff, 0xff, 0xff, 0xff, 0xff, 0x87, 0xff, 0xc1, 0xe0, 0x1f, 0xe1, 0xff, 0xff, 0xff, 0xff, 0xff,
  77. 0xff, 0xff, 0xff, 0xff, 0xff, 0x87, 0xff, 0xc1, 0xf8, 0x1f, 0xe1, 0xff, 0xff, 0xff, 0xff, 0xff,
  78. 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0x81, 0xfc, 0x1f, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff,
  79. 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0x81, 0xfc, 0x1f, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff,
  80. 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0x83, 0xfc, 0x1f, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff,
  81. 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0x81, 0xf8, 0x1f, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff,
  82. 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0x00, 0x00, 0x3f, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff,
  83. 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0x00, 0x00, 0x3f, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff,
  84. 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0x03, 0x00, 0x7f, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff,
  85. 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0x07, 0xf0, 0x3f, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff,
  86. 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xfe, 0x07, 0xf8, 0x3f, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff,
  87. 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xfe, 0x07, 0xf8, 0x3f, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff,
  88. 0xff, 0xff, 0xff, 0xff, 0xff, 0x87, 0xfc, 0x07, 0xf8, 0x3f, 0xe1, 0xff, 0xff, 0xff, 0xff, 0xff,
  89. 0xff, 0xff, 0xff, 0xff, 0xff, 0x87, 0xf0, 0x07, 0xf8, 0x3f, 0xe1, 0xff, 0xff, 0xff, 0xff, 0xff,
  90. 0xff, 0xff, 0xff, 0xff, 0xff, 0x87, 0xe0, 0x00, 0x70, 0x3f, 0xe1, 0xff, 0xff, 0xff, 0xff, 0xff,
  91. 0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0xf0, 0x00, 0x00, 0x3f, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
  92. 0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0xff, 0x00, 0x00, 0x7f, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
  93. 0xff, 0xff, 0xff, 0xff, 0xff, 0xc1, 0xff, 0x88, 0x00, 0xff, 0x83, 0xff, 0xff, 0xff, 0xff, 0xff,
  94. 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0x1c, 0x01, 0xff, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff,
  95. 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xff, 0x1c, 0x7f, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff,
  96. 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x7f, 0x1c, 0xff, 0xfe, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff,
  97. 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x3f, 0x18, 0xff, 0xfc, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff,
  98. 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x1f, 0xf8, 0xff, 0xf8, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
  99. 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x07, 0xfd, 0xff, 0xe0, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff,
  100. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  101. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  102. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x1f, 0xf8, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  103. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  104. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  105. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  106. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  107.  
  108. #if (SSD1306_LCDHEIGHT != 64)
  109. #error("Height incorrect, please fix Adafruit_SSD1306.h!");
  110.  
  111. #endif
  112.  
  113. void setup()   {                
  114.   Serial.begin(9600);
  115.   while (!Serial) {
  116.     ; // wait for serial port to connect. Needed for native USB port only
  117.   }
  118.  
  119.   Serial.print("Initializing SD card...");
  120.  
  121.   if (!SD.begin(15)) {
  122.     Serial.println("initialization failed!");
  123.     return;
  124.   }
  125.   Serial.println("initialization done.");
  126.   String readstr = "";
  127.   myFile = SD.open("setup.txt");
  128.   if (myFile) {
  129.     while (myFile.available()) {
  130.       char c = myFile.read();
  131.       readstr += c;
  132.     }
  133.     myFile.close();
  134.   } else {
  135.     Serial.println("error opening setup.txt");
  136.     myFile = SD.open("setup.txt", FILE_WRITE);
  137.     if (myFile) {
  138.       Serial.print("Writing to setup.txt...");
  139.       myFile.println("wifi_ssid;wifi_password;btc_address;");
  140.       myFile.close();
  141.       Serial.println("done.");
  142.     } else {
  143.       Serial.println("error opening setup.txt for writing");
  144.     }
  145.   }
  146.   ssid = getValue(readstr,';',0);
  147.   passwd = getValue(readstr,';',1);
  148.   addr1 = getValue(readstr,';',2);
  149.  
  150.   display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  
  151.   display.clearDisplay();
  152.  
  153.   display.drawBitmap(0, 0,  splashbtc, 128, 64, 1);
  154.   display.display();
  155.  
  156.  
  157.   Serial.println();
  158.   Serial.print("connecting to ");
  159.   Serial.println(ssid);
  160.   WiFi.mode(WIFI_STA);
  161.   char *s = const_cast<char*>(ssid.c_str());
  162.   char *p = const_cast<char*>(passwd.c_str());
  163.   WiFi.begin(s, p);
  164.   while (WiFi.status() != WL_CONNECTED) {
  165.     delay(500);
  166.     Serial.print(".");
  167.   }
  168.   Serial.println("");
  169.   Serial.println("WiFi connected");
  170.   Serial.println("IP address: ");
  171.   Serial.println(WiFi.localIP());
  172.  
  173. }
  174.  
  175.  
  176. void loop() {
  177.  
  178.   iter++;
  179.  
  180.   if (WiFi.status() != WL_CONNECTED){
  181.  
  182.     Serial.println();
  183.     Serial.print("connecting to ");
  184.     Serial.println(ssid);
  185.     WiFi.mode(WIFI_STA);
  186.     char *s = const_cast<char*>(ssid.c_str());
  187.     char *p = const_cast<char*>(passwd.c_str());
  188.     WiFi.begin(s, p);
  189.     while (WiFi.status() != WL_CONNECTED) {
  190.       delay(500);
  191.       Serial.print(".");
  192.     }
  193.     Serial.println("");
  194.     Serial.println("WiFi connected");
  195.     Serial.println("IP address: ");
  196.     Serial.println(WiFi.localIP());
  197.  
  198.   }
  199.  
  200.  
  201.  
  202.  
  203.   Serial.print("connecting to ");
  204.   Serial.println("api.gdax.com");
  205.   if (!client.connect("api.gdax.com", 443)) {
  206.     Serial.println("connection failed");
  207.     delay(1000);
  208.     return;
  209.   }
  210.  
  211.  
  212.   String  url = "/products/BTC-USD/ticker";
  213.   Serial.print("requesting URL: ");
  214.   Serial.println(url);
  215.  
  216.   client.print(String("GET ") + url + " HTTP/1.1\r\n" +
  217.                "Host: api.gdax.com\r\n" +
  218.                "User-Agent: btc\r\n" +
  219.                "Connection: close\r\n\r\n");
  220.  
  221.   Serial.println("request sent");
  222.   while (client.connected()) {
  223.     line = client.readStringUntil('\n');
  224.     if (line == "\r") {
  225.       Serial.println("headers received");
  226.       break;
  227.     }
  228.   }
  229.   line = client.readStringUntil('\n');
  230.  
  231.   curr = getValue(line,'"',5);
  232.   Serial.println("reply was:");
  233.   Serial.println("==========");
  234.   Serial.println(curr);
  235.   Serial.println("==========");
  236.   Serial.println("closing connection");
  237.  
  238.   client.stop();
  239.  
  240.  
  241.  
  242.  
  243.  
  244.   Serial.print("connecting to ");
  245.   Serial.println("blockchain.info");
  246.   if (!client.connect("blockchain.info", 443)) {
  247.     Serial.println("connection failed");
  248.     delay(1000);
  249.     return;
  250.   }
  251.  
  252.  
  253.   url = "/rawaddr/" + addr1;
  254.   Serial.print("requesting URL: ");
  255.   Serial.println(url);
  256.  
  257.   client.print(String("GET ") + url + " HTTP/1.1\r\n" +
  258.                "Host: blockchain.info\r\n" +
  259.                "User-Agent: btc\r\n" +
  260.                "Connection: close\r\n\r\n");
  261.  
  262.   Serial.println("request sent");
  263.   while (client.connected()) {
  264.     line = client.readStringUntil('\n');
  265.     if (line == "\r") {
  266.       Serial.println("headers received");
  267.       break;
  268.     }
  269.   }
  270.   line = client.readStringUntil('}');
  271.   Serial.println("reply was:");
  272.   Serial.println("==========");
  273.  
  274.   if (line[0] != 'M'){
  275.  
  276.  
  277.     currbal = getValue(line,'\n',7);
  278.     currbal = getValue(currbal,':',1) + "x";
  279.     currbal = getValue(currbal,',',0);
  280.    
  281.     if (currbal.length() <= 8){
  282.    
  283.       String addt = "0.";
  284.    
  285.       int diff = 8 - currbal.length();
  286.       for (int i = 0; i < diff; i++){
  287.         addt = addt + "0";
  288.       }
  289.       currbal = addt + currbal;
  290.     }else{
  291.       int diff = currbal.length() - 8;
  292.       String rslt = currbal.substring(0, diff) + "." + currbal.substring(diff, currbal.length() - diff);
  293.       currbal = rslt;
  294.      
  295.     }
  296.   }
  297.  
  298.   Serial.println(currbal);
  299.   Serial.println("==========");
  300.   Serial.println("closing connection");
  301.   client.stop();
  302.  
  303.   display.clearDisplay();
  304.   display.setTextSize(2);
  305.   display.setTextColor(WHITE);
  306.   display.setCursor(0,0);
  307.   display.print("$" + getValue(curr,'.',0));
  308.   display.setTextSize(1);
  309.   display.println("/BTC");
  310.   display.println("");
  311.   display.println("");
  312.   display.println(currbal + " BTC");
  313.   display.println("");
  314.   display.setTextSize(2);
  315.   display.print("= $");
  316.   addrval = getValue(curr,'.',0).toFloat() * currbal.toFloat();
  317.   display.println(addrval, 0);
  318.   display.display();
  319.  
  320.   delay(20000);
  321.  
  322.   if (iter > 20){
  323.     iter = 0;
  324.     display.clearDisplay();
  325.     testdrawbitmap(smbtc, 32, 32);
  326.   }
  327.  
  328. }
  329.  
  330.  
  331. void testdrawbitmap(byte *bitmap, uint8_t w, uint8_t h) {
  332.   uint8_t icons[NUMFLAKES][3];
  333.  
  334.   // initialize
  335.   for (uint8_t f=0; f< NUMFLAKES; f++) {
  336.     icons[f][XPOS] = random(display.width());
  337.     icons[f][YPOS] = 0;
  338.     icons[f][DELTAY] = random(5) + 1;
  339.    
  340.     Serial.print("x: ");
  341.     Serial.print(icons[f][XPOS], DEC);
  342.     Serial.print(" y: ");
  343.     Serial.print(icons[f][YPOS], DEC);
  344.     Serial.print(" dy: ");
  345.     Serial.println(icons[f][DELTAY], DEC);
  346.   }
  347.   int k = 0;
  348.   while (k < 50) {
  349.     k++;
  350.     // draw each icon
  351.     for (uint8_t f=0; f< NUMFLAKES; f++) {
  352.       display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, WHITE);
  353.     }
  354.     display.display();
  355.     delay(200);
  356.    
  357.     // then erase it + move it
  358.     for (uint8_t f=0; f< NUMFLAKES; f++) {
  359.       display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK);
  360.       // move it
  361.       icons[f][YPOS] += icons[f][DELTAY];
  362.       // if its gone, reinit
  363.       if (icons[f][YPOS] > display.height()) {
  364.         icons[f][XPOS] = random(display.width());
  365.         icons[f][YPOS] = 0;
  366.         icons[f][DELTAY] = random(5) + 1;
  367.       }
  368.     }
  369.    }
  370. }
  371.  
  372. // https://stackoverflow.com/questions/9072320/split-string-into-string-array
  373. String getValue(String data, char separator, int index)
  374. {
  375.   int found = 0;
  376.   int strIndex[] = {0, -1};
  377.   int maxIndex = data.length()-1;
  378.  
  379.   for(int i=0; i<=maxIndex && found<=index; i++){
  380.     if(data.charAt(i)==separator || i==maxIndex){
  381.         found++;
  382.         strIndex[0] = strIndex[1]+1;
  383.         strIndex[1] = (i == maxIndex) ? i+1 : i;
  384.     }
  385.   }
  386.  
  387.   return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
  388. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top