Skip to content

Instantly share code, notes, and snippets.

@kashimAstro
Created January 2, 2018 19:55
Show Gist options
  • Save kashimAstro/a534d9b311b095f3164b3e9e5f85dcd0 to your computer and use it in GitHub Desktop.
Save kashimAstro/a534d9b311b095f3164b3e9e5f85dcd0 to your computer and use it in GitHub Desktop.
ofxGPIO test 7 segment
#include <iostream>
#include "ofxGPIO.h"
#define CMD 0x80
#define ON 0x01
#define OFF 0
#define BRI 0xE0
#define ADD 0x70
I2c * i2c;
int brightness = 5;
vector<pair<char,int>> digit;
int main(int argc, char *argv[])
{
if(argc > 1)
{
digit.push_back(pair<char,int>('0',0x3F));
digit.push_back(pair<char,int>('1',0x06));
digit.push_back(pair<char,int>('2',0x5B));
digit.push_back(pair<char,int>('3',0x4F));
digit.push_back(pair<char,int>('4',0x66));
digit.push_back(pair<char,int>('5',0x6D));
digit.push_back(pair<char,int>('6',0x7D));
digit.push_back(pair<char,int>('7',0x07));
digit.push_back(pair<char,int>('8',0x7F));
digit.push_back(pair<char,int>('9',0x6F));
digit.push_back(pair<char,int>(' ',0));
i2c = new I2c(argv[1]);
i2c->addressSet(ADD);
i2c->write(0x21);
i2c->write(CMD | ON | (OFF << 1) );
i2c->write(BRI | brightness);
i2c->write(0x00);
i2c->writeByte(0,digit[0].second);
i2c->writeByte(2,digit[1].second);
i2c->writeByte(4,digit[2].second);
i2c->writeByte(6,digit[3].second);
}
else{
cout<<"Error parameter: device"<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment