Skip to content

Instantly share code, notes, and snippets.

@samueltcsantos
Created October 23, 2016 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samueltcsantos/adcc0837512d2b93f8e9a2fe1d32c3eb to your computer and use it in GitHub Desktop.
Save samueltcsantos/adcc0837512d2b93f8e9a2fe1d32c3eb to your computer and use it in GitHub Desktop.
Arduino Display 7 segmentos
/**
* Display 7 segments
* Samuel T. C. Santos
* Date: 23 Out 2016
*/
const int SEG_A = 2;
const int SEG_B = 3;
const int SEG_C = 4;
const int SEG_D = 5;
const int SEG_E = 6;
const int SEG_F = 7;
const int SEG_G = 8;
const int DELAY = 1000;
const int DIGITS = 10;
const int SEGMENTS = 7;
byte digits[DIGITS][SEGMENTS] = {
// remember { A, B, C, D, E, F, G }
{ HIGH, HIGH , HIGH, HIGH, HIGH, HIGH, LOW }, // 0
{ LOW, HIGH , HIGH, LOW, LOW, LOW, LOW}, // 1
{ HIGH, HIGH , LOW, HIGH, HIGH, LOW, HIGH }, // 2
{ HIGH, HIGH , HIGH, HIGH, LOW, LOW, HIGH }, // 3
{ LOW, HIGH , HIGH, LOW, LOW, HIGH, HIGH }, // 4
{ HIGH, LOW, HIGH, HIGH, LOW, HIGH, HIGH}, // 5
{ HIGH, LOW , HIGH, HIGH, HIGH, HIGH, HIGH }, // 6
{ HIGH, HIGH , HIGH, LOW, LOW, LOW, LOW }, // 7
{ HIGH, HIGH , HIGH, HIGH, HIGH, HIGH, HIGH }, // 8
{ HIGH, HIGH , HIGH, LOW, LOW, HIGH, HIGH } // 9
};
void writeDigit(int digit){
int pin = 2;
for (int segment=0; segment < 7; segment++){
digitalWrite(pin, digits[digit][segment]);
pin++;
}
}
void setup() {
// put your setup code here, to run once:
pinMode(SEG_A, OUTPUT);
pinMode(SEG_B, OUTPUT);
pinMode(SEG_C, OUTPUT);
pinMode(SEG_D, OUTPUT);
pinMode(SEG_E, OUTPUT);
pinMode(SEG_F, OUTPUT);
pinMode(SEG_G, OUTPUT);
}
void turnOff(){
digitalWrite(SEG_A, LOW);
digitalWrite(SEG_B, LOW);
digitalWrite(SEG_C, LOW);
digitalWrite(SEG_D, LOW);
digitalWrite(SEG_E, LOW);
digitalWrite(SEG_F, LOW);
digitalWrite(SEG_G, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
for (int digit = 0; digit < DIGITS; digit++){
writeDigit(digit);
delay(DELAY);
}
turnOff();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment