forked from Agent725/ESP32C3
added delay to ensure OLED is initialized upon cold boot
This commit is contained in:
parent
ef76c8f579
commit
5e1a34c9d7
|
|
@ -2,45 +2,48 @@
|
||||||
* SCREENSAVER: bounces a nice little text over the screen
|
* SCREENSAVER: bounces a nice little text over the screen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// offsets must be defined for correct display on screen!
|
// for some reason the OLED screen needs this timeout
|
||||||
const Xoffset = 8;
|
setTimeout(function() {
|
||||||
const Yoffset = 8;
|
// offsets must be defined for correct display on screen!
|
||||||
|
const Xoffset = 8;
|
||||||
|
const Yoffset = 8;
|
||||||
|
|
||||||
// define the function first, before using it below
|
// define the function first, before using it below
|
||||||
function displayText(textString, x,y) {
|
function displayText(textString, x, y) {
|
||||||
// write some text
|
// write some text
|
||||||
scrn.drawString(textString, Xoffset + x, Yoffset + y);
|
scrn.drawString(textString, Xoffset + x, Yoffset + y);
|
||||||
// write to the screen
|
// write to the screen
|
||||||
scrn.flip();
|
scrn.flip();
|
||||||
// clear a bit of the screen in preparation before next update
|
// clear a bit of the screen in preparation before next update
|
||||||
scrn.clearRect(Xoffset + x, Yoffset + y, Xoffset + x + 30, Yoffset + y + 8);
|
scrn.clearRect(Xoffset + x, Yoffset + y, Xoffset + x + 30, Yoffset + y + 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
// MAIN FUNCTION: bounce text and flash LED (D8)
|
// MAIN: flash LED (D8)
|
||||||
let on = false;
|
let on = false;
|
||||||
let x = 0;
|
let x = 0;
|
||||||
let y = 0;
|
let y = 0;
|
||||||
let ix = 1;
|
let ix = 1;
|
||||||
let iy = 1;
|
let iy = 1;
|
||||||
const txt = 'HELLO';
|
const txt = 'HELLO';
|
||||||
function main() {
|
function go() {
|
||||||
setInterval(function() {
|
setInterval(function() {
|
||||||
on = !on;
|
on = !on;
|
||||||
digitalWrite("D8",on);
|
digitalWrite("D8",on);
|
||||||
y += iy;
|
y += iy;
|
||||||
x += ix;
|
x += ix;
|
||||||
if (x > (72-(txt.length*8))) ix = -ix;
|
if (x > (72-(txt.length*8))) ix = -ix;
|
||||||
if (y > 34) iy = -iy;
|
if (y > 34) iy = -iy;
|
||||||
if (x < 1) ix = -ix;
|
if (x < 1) ix = -ix;
|
||||||
if (y < 1) iy = -iy;
|
if (y < 1) iy = -iy;
|
||||||
displayText(txt,x,y);
|
displayText(txt, x, y);
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// required modules/libraries (in Espruino must be included at the end due to needing functions)
|
// required modules/libraries (in Espruino must be included at the end due to needing functions)
|
||||||
//
|
//
|
||||||
I2C1.setup({scl:"D6",sda:"D5"}); // I2C setup
|
I2C1.setup({scl:"D6",sda:"D5"}); // I2C setup
|
||||||
// initialize the screen and its dimensions (null can be replaced by a callback)
|
// initialize the screen and its dimensions (null can be replaced by a callback)
|
||||||
const scrn = require("SSD1306").connect(I2C1, main, { width:72, height:48 }); // for 72x48 LCD
|
const scrn = require("SSD1306").connect(I2C1, main, { width:72, height:48 }); // for 72x48 LCD
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue