Skip to content

Instantly share code, notes, and snippets.

@jrockway
Created August 27, 2012 08:43
Show Gist options
  • Save jrockway/3486723 to your computer and use it in GitHub Desktop.
Save jrockway/3486723 to your computer and use it in GitHub Desktop.
driver for adafruit led backpack
#include "display.h"
#include "third_party/i2cmaster.h"
static const uint8_t number_table[] = {
0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x77, 0x7C,
0x39, 0x5E, 0x79, 0x71 };
void init_display(int address) {
i2c_start_wait(address + I2C_WRITE);
i2c_write(0x21);
i2c_stop();
i2c_start_wait(address + I2C_WRITE);
i2c_write(0x81);
i2c_stop();
i2c_start_wait(address + I2C_WRITE);
i2c_write(0xef);
i2c_stop();
}
void display_digits(int address, int a, int b, int c, int d, int colon,
int a_dot, int b_dot, int c_dot, int d_dot) {
i2c_start_wait(address + I2C_WRITE);
i2c_write(0x0);
i2c_write(number_table[a % 16] | (a_dot ? _BV(7) : 0));
i2c_write(0x0);
i2c_write(number_table[b % 16] | (b_dot ? _BV(7) : 0));
i2c_write(0x0);
if (colon) {
i2c_write(0xff);
}
else {
i2c_write(0x0);
}
i2c_write(0x0);
i2c_write(number_table[c % 16] | (c_dot ? _BV(7) : 0));
i2c_write(0x0);
i2c_write(number_table[d % 16] | (d_dot ? _BV(7) : 0));
i2c_write(0x00);
i2c_write(0x00);
i2c_write(0x00);
i2c_write(0x00);
i2c_write(0x00);
i2c_write(0x00);
i2c_write(0x00);
i2c_stop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment