Heartache & LED-Based
Binary-Alphabet Blinkers
Last summer I had the amazing opportunity to potentially intern at one of my favorite organizations: Khan Academy. I was so nervous about potentially being rejected that I started to physically shake about five minutes before the Skype interview was scheduled to begin.
When the call came, I found that my interviewer was not just a developer at KA, but Joel Burget who I knew was, at the time, head of software development for Khan Academy. My shaking escalated to an 11 on the Richter scale. As one might expect, I fumbled the interview process and did so in a spectacular, bumbling fashion.
Unsurprisingly, I did not receive a spot on the intern board. I was a little upset:

That said, I was really grateful just to have been considered in the first place. Additionally, Joel was really nice, gave me plenty of advice, and seemed really sincere when he encouraged me to apply again the following year.
Okay, enough background — now on to the reason I’m writing this blog post: Of all the questions I was asked during the interview, this one stuck with me the most:
How would you explain binary to a kid in middle school?
Explaining this one without being able to use any sort of visual aid over Skype was difficult and I think it was my biggest fumble so I’ve always wanted to give it another go. Couple that desire with my very recent acquisition of an Arduino and you get the LED Binary-Alphabet Blinker:

This quick little project will blink any letter of the alphabet back to the user in binary via the LEDs. That said, it doesn’t use the typical HEX/DEC representations of the letters of the alphabet. Instead, it considers uppercase and lowercase to be the same values, and maps the characters such that:
a = 1 , b = 2 , c = 3 , … , z = 26
I think this is a better approach for teaching a younger crowd as you get to focus on representing a well-known set through binary without having to go through an explanation of ASCII. You can then do fun exercises like having the kids work out what their name would be in binary and then check them via the Arduino.
Another advantage is that this circuit is really simple to build and a great learning opportunity for the more “hands-on” learner:

If you’re interested in trying out this project for teaching purposes or personal use, the code is as follows (Medium formats it a little oddly):
/**
@file Binary_Blinker.ino
@author Jake Mason
@date 2015–07–26
@version 1.0
An Arduino program which will blink any letter of the alphabet back to the user in binary via LEDs!
NOTE: For learning/teaching purposes this program goes by the position of the character in the alphabet, NOT it’s DEC/HEX value. It also treats capitalized characters as their lowercase equivalent. Thus, the focus can be on binary representations of a familiar set and ASCII can be left for another lesson.
IE: a & A => 1, b & B => 2, … , z & Z => 26
*/
#include <math.h> // so we can use log()
char incomingByte; // we’ll be reading our input into here
int lightUp[5] = {0}; // we’ll use this to “mark” our LEDs for light up!
/*
* Determines the binary representation of an any integer
* less than or equal to 31 which is all we need for the alphabet.
*
* @param x — the int we’ll be determining the binary representation of
*/
void markBinary( int x ){
for (int i = 16; i >= 1; i /= 2){
if(x >= i){
lightUp[(int)(log(i)/log(2))] = 1; //Taking log of powers base 2
x -= i;
}
}
}
/*
* Converts any char to it’s lowercase equivalent
* and returns it’s integer equivalent in the English alphabet.
* a = 1, b = 2, c = 3, … z = 26.
*
* @param x — the char to convert
* @return — the integer equivalent x in the English alpha.
*/
int alphaToInt ( char x ){
return tolower((int)x) — 96; // ASCII value of ‘a’ is 97 so we subtract
// 96 to make it more intuitive and start at 1
}
void setup() {
// I’ve set up my Arduino such that I’ll be using pins 3 through 7
// such that their binary represetations are as follows:
// p3 => 2^0 || p4 => 2^1 || p5 => 2^2 || p6 => 2^3 || p7 => 2^4
for (int i = 3; i <= 7; i++){
pinMode(i, OUTPUT); // we’re blinking these pins!
digitalWrite(i, 0); // make sure they’re all turned off to start.
}Serial.begin(9600); //listening for input on this channel
}
void loop() {
if (Serial.available() > 0) {
incomingByte = Serial.read();
markBinary(alphaToInt(incomingByte));//lighting up our LEDs!
for (int i = 0; i < 5; i++){
if (lightUp[i] == 1){
digitalWrite(i + 3, 1);
}
}
delay(400);
//reset LEDs & lightUp array
for (int i = 3; i <= 7; i++){
digitalWrite(i, 0);
lightUp[i — 3] = 0;
}
delay(100);
}
}