jvsdisplayotron
Version:
A lightweight but powerful module, that allows you to easily control a Display-O-Tron 3000 / HAT from Node.js
71 lines (60 loc) • 2.3 kB
JavaScript
// Load dependencies.
var JVSDisplayOTron = require('../../index.js');
// Initialize the Display-O-Tron.
var dothat = new JVSDisplayOTron.DOTHAT();
// Set the display contrast to a better-readable value.
dothat.lcd.setContrast(45);
// Create an animated Space Invader character.
var spaceInvaderAnimatedCharacter = dothat.lcd.createAnimatedCharacter({
memoryPosition: 0,
frames: [
[],
[]
],
frameRate: 2,
repeatCount: 4 // Remove or set to 0 for an infinite animation.
});
/**
* Handles the 'startAnimating' event of the Space Invader character.
*/
spaceInvaderAnimatedCharacter.on('startAnimating', function() {
console.log('Space Invader character has started animating.');
});
/**
* Handles the 'stopAnimating' event of the Space Invader character.
*/
spaceInvaderAnimatedCharacter.on('stopAnimating', function() {
console.log('Space Invader character has stopped animating.');
});
// Create an animated Pac-Man character.
var pacManAnimatedCharacter = dothat.lcd.createAnimatedCharacter({
memoryPosition: 1,
frames: [
[],
[]
],
frameRate: 2
});
// Create an animated pirate character.
var pirateAnimatedCharacter = dothat.lcd.createAnimatedCharacter({
memoryPosition: 2,
frames: [
[],
[],
[],
[]
],
frameRate: 2
});
// Write the animated Space Invader character on the first row of the display.
dothat.lcd.setCursorPosition(0, 0);
dothat.lcd.writeAnimatedCharacter(spaceInvaderAnimatedCharacter);
dothat.lcd.write(' Space Invader');
// Write the animated Pac-Man character on the second row of the display.
dothat.lcd.setCursorPosition(0, 1);
dothat.lcd.writeAnimatedCharacter(pacManAnimatedCharacter);
dothat.lcd.write(' Pac-Man');
// Write the animated pirate character on the third row of the display.
dothat.lcd.setCursorPosition(0, 2);
dothat.lcd.writeAnimatedCharacter(pirateAnimatedCharacter);
dothat.lcd.write(' Pirate');