Skip to content

Instantly share code, notes, and snippets.

@emceeaich
Last active December 7, 2018 18:45
Show Gist options
  • Save emceeaich/2ce5fa6eeaa421cff77840c96f492765 to your computer and use it in GitHub Desktop.
Save emceeaich/2ce5fa6eeaa421cff77840c96f492765 to your computer and use it in GitHub Desktop.
Namebadge for pixl.js
// Download/transmit this to your pixl.js
var name = "Emma";
var sites = ["@triagegirl", "https://emmah.net", "https://emmas.site"];
var pronouns = ["she/her", "they/them", "zie/zir"];
var pronounCount = 0;
require("Font8x12").add(Graphics);
// note: g is the global instance of Graphics
function writeName() {
g.clear();
g.setFont8x12();
g.drawString("Hello, I'm");
g.setFontVector(32);
g.drawString(name, (g.getWidth()-g.stringWidth(name))/2,15);
}
function writeOther(s) {
g.setFont8x12();
g.drawString(s, 0, 50);
}
// Factor out functionallity
function toggleLight() {
var state = digitalRead(LED);
digitalWrite(LED, !state);
}
function nextTag(tags) {
var next = tags.shift();
writeOther(next);
sites.push(next);
}
function resetName() {
writeName();
g.flip();
}
// set up buttons
function bindButton(fn, btn) {
setWatch(fn, btn, {edge:"rising", debounce:50, repeat:true});
}
bindButton(toggleLight, BTN1);
bindButton(function() {
writeName();
nextTag(sites);
g.flip();
}, BTN2);
bindButton(function() {
writeName();
nextTag(pronouns);
g.flip();
}, BTN3);
bindButton(resetName, BTN4);
digitalWrite(LED, 0);
writeName();
g.flip();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment