Skip to content

Commit

Permalink
eboled: Sparkfun OLED Block Improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Gibson <tgibson@microsoft.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
  • Loading branch information
tylergibson authored and Propanu committed Sep 21, 2015
1 parent 7935ef1 commit 14a3924
Show file tree
Hide file tree
Showing 4 changed files with 798 additions and 102 deletions.
137 changes: 118 additions & 19 deletions examples/javascript/eboled.js
Expand Up @@ -5,6 +5,9 @@
* Author: Jon Trulson <jtrulson@ics.com> * Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 Intel Corporation. * Copyright (c) 2015 Intel Corporation.
* *
* Author: Tyler Gibson <tgibson@microsoft.com>
* Copyright (c) 2015 Microsoft Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including * "Software"), to deal in the Software without restriction, including
Expand All @@ -25,27 +28,123 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */


function exit()
{
lcd = null;
lcdObj.cleanUp();
lcdObj = null;
process.exit(0);
}

// Load i2clcd module
var lcdObj = require('jsupm_i2clcd'); var lcdObj = require('jsupm_i2clcd');
var oled = new lcdObj.EBOLED();


var lcd = new lcdObj.EBOLED(); var sample = 0;

var samples = 13;
lcd.clear();
lcd.setCursor(2, 0);
lcd.write("Hello");
lcd.setCursor(3, 5);
lcd.write("World!");

console.log("Sleeping for 5 seconds...");
setTimeout(exit, 5000);


function exit()
{
oled = null;
lcdObj.cleanUp();
lcdObj = null;
process.exit(0);
}


setInterval( function()
{
if(sample>samples)
{
exit();
}
oled.clearScreenBuffer();
runSample(sample++);
oled.refresh();
}, 1500);


function runSample(sample)
{
switch(sample) {
case 0:
// x/y coords are 0 based, using 1 here for padding.
oled.setCursor(1,1);
// nowrap = 0, wrapping = 1
oled.setTextWrap(1);
oled.write("HELLO WORLD! Mixed with #123 and y's, g's and q's.");
break;
case 1:
oled.setCursor(12, 1);
//multiply text size, only integers
oled.setTextSize(3);
oled.write("BOO!");
oled.setTextSize(1);
break;
case 2:
oled.drawRectangleFilled(0,0,48,9);
oled.setCursor(1,1);
// 0=Black, 1=White, 2=Xor (Toggle)
oled.setTextColor(2);
oled.write("Cutout");
break;
case 3:
var total = Math.random()*100;
for(var stars=0; stars<total; stars++ )
oled.drawPixel(Math.floor(Math.random()*63), Math.floor(Math.random()*47), 1);
break;
case 4:
for(var burst=0; burst<12; burst++)
oled.drawLine(31, 24, Math.floor(Math.random()*63), Math.floor(Math.random()*47), 1);
break;
case 5:
var lastPeak = 24;
for(var peak=0; peak < 64; peak++)
{
var thisPeak = Math.abs(lastPeak + Math.floor(Math.random()*(-6) + Math.random()*6));
oled.drawLine(peak, thisPeak, peak, 47, 1);
lastPeak = thisPeak;
}
break;
case 6:
for(var y=0; y<47; y++)
{
oled.drawLineHorizontal(0,y+1,63,2);
oled.refresh();
oled.drawLineHorizontal(0,y,63,2);
}
break;
case 7:
var eqbarHeights = [ Math.floor(Math.random()*32),
Math.floor(Math.random()*32),
Math.floor(Math.random()*32),
Math.floor(Math.random()*32),
Math.floor(Math.random()*32),
Math.floor(Math.random()*32),
Math.floor(Math.random()*32) ];
var begin = Date.now();
while(Date.now()-begin < 2000)
{
oled.clearScreenBuffer();
for(var eqbar=0; eqbar<7; eqbar++)
{
oled.drawRectangleFilled(eqbar*9, 49 - eqbarHeights[eqbar], 8, eqbarHeights[eqbar], 1);
eqbarHeights[eqbar] = eqbarHeights[eqbar] + Math.random()*(-2) + Math.random()*2;
if(eqbarHeights[eqbar]<0)
eqbarHeights[eqbar] = 1;
}
oled.refresh();
}
oled.clear();
break;
case 8:
oled.drawRoundedRectangle(8, 8, 48, 16, 4, 1);
oled.setCursor(12, 16);
oled.write("Cancel");
break;
case 9:
oled.drawTriangle(2, 2, 52, 7, 17, 37, 1);
break;
case 10:
oled.drawTriangleFilled(2, 2, 52, 7, 17, 37, 1);
break;
case 11:
oled.drawCircle(32, 24, 14, 1);
break;
case 12:
oled.drawCircleFilled(32, 24, 14, 1);
break;
case 13:
oled.fillScreen(1);
break;
}
}

0 comments on commit 14a3924

Please sign in to comment.