function attachscreen(sda, scl, i2cadd) try ( function () i2c.setpins(0,sda,scl) gdisplay.attach(gdisplay.SSD1306_128_64, gdisplay.LANDSCAPE, false, i2cadd) gdisplay.clear() gdisplay.setfont(gdisplay.FONT_LCD) gdisplay.setwrap(false) end, function (where, line, error, message) print("Couldn't attach the screen.\nError in "..where.." at "..line.." "..error..": "..message) end, function () end ) end local consolepos = 0 local consoletab = {} local consolemax = 6 local oledflip = 1 function flip() oledflip = oledflip+1; if oledflip > 3 then oledflip = 0 end if oledflip==0 then consolemax = 6 gdisplay.attach(gdisplay.SSD1306_128_64, gdisplay.LANDSCAPE_FLIP, false, i2cadd) elseif oledflip==1 then consolemax = 6 gdisplay.attach(gdisplay.SSD1306_128_64, gdisplay.LANDSCAPE, false, i2cadd) elseif oledflip==2 then consolemax = 13 gdisplay.attach(gdisplay.SSD1306_128_64, gdisplay.PORTRAIT, false, i2cadd) else consolemax = 13 gdisplay.attach(gdisplay.SSD1306_128_64, gdisplay.PORTRAIT_FLIP, false, i2cadd) end cls() end function cls() if (consolemax==6) then gdisplay.clear() else gdisplay.rect( {0,0}, 128, 9*consolemax, {0,0,0}, {0,0,0} ) end if oledflip ~= 1 then gdisplay.clear() end consolepos = 0 consoletab={} for i=0, consolemax do consoletab[i] = "" end end function console(msg) if (consolepos <= consolemax) then consoletab[consolepos] = msg gdisplay.write({0, consolepos*9},msg) consolepos = consolepos+1 else for i = 1, consolemax do consoletab[i-1] = consoletab[i] end consoletab[consolemax] = msg if (consolemax==6) then gdisplay.clear() else gdisplay.rect( {0,0}, 128, 9*consolemax+9, {0,0,0}, {0,0,0} ) end for i=0, consolemax do gdisplay.write({0, i*9},consoletab[i]) end end end