Skip to content

Instantly share code, notes, and snippets.

@adambutler
Created June 6, 2016 12:57
Show Gist options
  • Save adambutler/52e2043c51057c8fbceb35a96410f7c8 to your computer and use it in GitHub Desktop.
Save adambutler/52e2043c51057c8fbceb35a96410f7c8 to your computer and use it in GitHub Desktop.
var presses = 0;
setColor = function(red, green, blue) {
analogWrite(A8, red);
analogWrite(A5, red);
analogWrite(B4, green);
analogWrite(A6, green);
analogWrite(B6, blue);
analogWrite(B5, blue);
analogWrite(A7, blue);
analogWrite(B1, blue);
};
clearWatch();
setWatch(function(e) {
if(e.state) {
if(presses == 2) {
presses = 0;
} else {
presses++;
}
switch(presses) {
case 0:
setColor(1,0,0);
break;
case 1:
setColor(0,1,0);
break;
case 2:
setColor(0,0,1);
break;
default:
setColor(0,0,0);
}
}
console.log("Pressed "+presses);
}, BTN, { repeat: true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment