Stap 3: Code voor OLED lezer
Deze sketch laadt de adafruit oled en graphix bibliotheek.
Als geladen op een arduinoUNO, zal met inbegrip van de SD.h libarary verknoeien het. Het maakt gebruik van teveel SRAM. Dit probleem kan worden opgelost door:
1 - schrijven van efficiënte code (Ja... geen)
2 - met behulp van een Arduino mega (werkt, en bevestigt dat er een geheugenprobleem)
3 - het toevoegen van meer SRAM (moet u de SpiRAM bibliotheek http://playground.arduino.cc/Main/SpiRAM en een fysieke chip met meer SRAM
http://WW1.microchip.com/downloads/en/DeviceDoc/22... bij digikey
http://www.digikey.com/product-detail/en/23A256-I%...
4 - commentaar uit de SD.h-bibliotheek voor nu.
5 - Vervang SD.h met SdFat.h)
https://github.com/greiman/SdFat )
6 - uitgevoerd op Teensey 3.1--veel geheugen, code compileert en ladingen maar nog niet getest met OLED
Hier is de code voor de UNO zonder de SD.h-bibliotheek:
<span style="color: rgb(126,126,126);">///note - D10 set to output</span> <span style="color: rgb(126,126,126);">//for sd</span> <span style="color: rgb(126,126,126);">//#include <SD.h></span> #include <<span style="color: rgb(204,102,0);">SPI</span>.h> #include <<span style="color: rgb(204,102,0);">Wire</span>.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> <span style="color: rgb(126,126,126);">//////////////MPC New PINS /////////////</span> <span style="color: rgb(126,126,126);">// If using software SPI (the default case):</span> #define OLED_MOSI 11 #define OLED_CLK 13 #define OLED_DC 6 #define OLED_CS 9 #define OLED_RESET 8 Adafruit_SSD1306 <span style="color: rgb(204,102,0);">display</span>(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); <span style="color: rgb(204,102,0);">void</span> <span style="color: rgb(204,102,0);"><b>setup</b></span>() { <span style="color: rgb(204,102,0);"><b>Serial</b></span>.<span style="color: rgb(204,102,0);">begin</span>(9600); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">begin</span>(SSD1306_SWITCHCAPVCC); <span style="color: rgb(126,126,126);">// internal 3.3V line</span> <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">display</span>(); <span style="color: rgb(204,102,0);">delay</span>(2000); <span style="color: rgb(204,102,0);">display</span>.clearDisplay(); <span style="color: rgb(204,102,0);">pinMode</span>(10,<span style="color: rgb(0,102,153);">OUTPUT</span>); } <span style="color: rgb(204,102,0);">void</span> <span style="color: rgb(204,102,0);"><b>loop</b></span>(){ <span style="color: rgb(126,126,126);">//FlashRead Test</span> <span style="color: rgb(204,102,0);">int</span> t = 55; <span style="color: rgb(204,102,0);">int</span> x = 0; <span style="color: rgb(204,102,0);">int</span> y = 20; <span style="color: rgb(204,102,0);">int</span> s = 2; <span style="color: rgb(126,126,126);">//text scale</span> <span style="color: rgb(204,102,0);">int</span> w =12; <span style="color: rgb(126,126,126);">//pixel width of one letter</span> <span style="color: rgb(204,102,0);">display</span>.setTextSize(s); <span style="color: rgb(204,102,0);">display</span>.setTextColor(WHITE); <span style="color: rgb(126,126,126);">//is this needed?</span> <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">setCursor</span>(0,0); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">print</span>(<span style="color: rgb(0,102,153);">"t="</span>); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">print</span>(t); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">println</span>(<span style="color: rgb(0,102,153);">","</span>); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">print</span>(<span style="color: rgb(0,102,153);">"Size="</span>); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">print</span>(s); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">display</span>(); <span style="color: rgb(204,102,0);">delay</span>(1000); <span style="color: rgb(204,102,0);">display</span>.clearDisplay(); <span style="color: rgb(204,102,0);">delay</span>(2000); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">setCursor</span>(64-1.5*w,y); <span style="color: rgb(126,126,126);">// x = screen width - letter count x letter width</span> <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">print</span>(<span style="color: rgb(0,102,153);">"Now, "</span>); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">display</span>(); <span style="color: rgb(204,102,0);">delay</span>(3*t); <span style="color: rgb(204,102,0);">delay</span>(2*t); <span style="color: rgb(126,126,126);">//punctuations get 2t</span> <span style="color: rgb(204,102,0);">display</span>.clearDisplay(); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">setCursor</span>(64-1*w,y); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">print</span>(<span style="color: rgb(0,102,153);">"is "</span>); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">display</span>(); <span style="color: rgb(204,102,0);">delay</span>(3*t); <span style="color: rgb(126,126,126);">//minimum is 3t</span> <span style="color: rgb(204,102,0);">display</span>.clearDisplay(); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">setCursor</span>(64-1.5*w,y); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">print</span>(<span style="color: rgb(0,102,153);">"the "</span>); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">display</span>(); <span style="color: rgb(204,102,0);">delay</span>(3*t); <span style="color: rgb(204,102,0);">display</span>.clearDisplay(); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">setCursor</span>(64-3*w,y); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">print</span>(<span style="color: rgb(0,102,153);">"winter "</span>); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">display</span>(); <span style="color: rgb(204,102,0);">delay</span>(5*t); <span style="color: rgb(204,102,0);">display</span>.clearDisplay(); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">setCursor</span>(64-1*w,y); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">print</span>(<span style="color: rgb(0,102,153);">"of "</span>); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">display</span>(); <span style="color: rgb(204,102,0);">delay</span>(3*t); <span style="color: rgb(126,126,126);">//minimum is 3t</span> <span style="color: rgb(204,102,0);">display</span>.clearDisplay(); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">setCursor</span>(64-1.5*w,y); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">print</span>(<span style="color: rgb(0,102,153);">"our "</span>); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">display</span>(); <span style="color: rgb(204,102,0);">delay</span>(3*t); <span style="color: rgb(204,102,0);">display</span>.clearDisplay(); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">setCursor</span>(64-5*w,y); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">print</span>(<span style="color: rgb(0,102,153);">"discontent "</span>); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">display</span>(); <span style="color: rgb(204,102,0);">delay</span>(10*t); <span style="color: rgb(204,102,0);">display</span>.clearDisplay(); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">setCursor</span>(64-2*w,y); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">print</span>(<span style="color: rgb(0,102,153);">"made "</span>); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">display</span>(); <span style="color: rgb(204,102,0);">delay</span>(4*t); <span style="color: rgb(204,102,0);">display</span>.clearDisplay(); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">setCursor</span>(64-4*w,y); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">print</span>(<span style="color: rgb(0,102,153);">"glorious "</span>); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">display</span>(); <span style="color: rgb(204,102,0);">delay</span>(8*t); <span style="color: rgb(204,102,0);">display</span>.clearDisplay(); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">setCursor</span>(64-3*w,y); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">print</span>(<span style="color: rgb(0,102,153);">"summer "</span>); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">display</span>(); <span style="color: rgb(204,102,0);">delay</span>(6*t); <span style="color: rgb(204,102,0);">display</span>.clearDisplay(); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">setCursor</span>(64-1*w,y); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">print</span>(<span style="color: rgb(0,102,153);">"by "</span>); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">display</span>(); <span style="color: rgb(204,102,0);">delay</span>(3*t); <span style="color: rgb(126,126,126);">//minimum is 3t</span> <span style="color: rgb(204,102,0);">display</span>.clearDisplay(); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">setCursor</span>(64-2*w,y); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">print</span>(<span style="color: rgb(0,102,153);">"this "</span>); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">display</span>(); <span style="color: rgb(204,102,0);">delay</span>(4*t); <span style="color: rgb(204,102,0);">display</span>.clearDisplay(); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">setCursor</span>(64-1.5*w,y); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">print</span>(<span style="color: rgb(0,102,153);">"son "</span>); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">display</span>(); <span style="color: rgb(204,102,0);">delay</span>(3*t); <span style="color: rgb(204,102,0);">display</span>.clearDisplay(); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">setCursor</span>(64-1*w,y); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">print</span>(<span style="color: rgb(0,102,153);">"of "</span>); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">display</span>(); <span style="color: rgb(204,102,0);">delay</span>(3*t); <span style="color: rgb(126,126,126);">//minimum is 3t //minimum is 3t //minimum is 3t</span> <span style="color: rgb(204,102,0);">display</span>.clearDisplay(); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">setCursor</span>(64-2*w,y); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">print</span>(<span style="color: rgb(0,102,153);">"York. "</span>); <span style="color: rgb(204,102,0);">display</span>.<span style="color: rgb(204,102,0);">display</span>(); <span style="color: rgb(204,102,0);">delay</span>(5*t); <span style="color: rgb(204,102,0);">display</span>.clearDisplay(); <span style="color: rgb(204,102,0);">delay</span>(2000); }