Skip to content

Instantly share code, notes, and snippets.

@mePy2
Created December 23, 2019 21:42
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 mePy2/49ed30793a89e3f6fa24b09f28bf99d4 to your computer and use it in GitHub Desktop.
Save mePy2/49ed30793a89e3f6fa24b09f28bf99d4 to your computer and use it in GitHub Desktop.
Programma Arduino corso Automazione G. Ferraris a.s. 2019/20.
/*
23/12/2019
Umberto Cerrato
Questo programma mostra un numero a due cifre su due display a sette segmenti collegati ad Arduino ai pin digitali (D0-D13)
(Programma non commentato)
*/
int a=66;
int dec_b, unit_a;
char conv[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};
void setup()
{
int contatore;
for(contatore=0;contatore<14;contatore++)
pinMode(contatore, OUTPUT);
dec_b = a%10;
unit_a = a/10;
}
bool controlla_bit (int value, int position)
{
int mask;
mask = 1<<position;
return ((value&mask)==mask);
}
void mostra_display0 (int number)
{
int contatore, valore;
valore = conv[number];
for(contatore=0;contatore<7;contatore++) {
if(controlla_bit(valore, contatore))
digitalWrite(contatore, HIGH);
else
digitalWrite(contatore, LOW);
}
}
void mostra_display1(int number)
{
int contatore, valore;
valore = conv[number];
for(contatore=7;contatore<14;contatore++) {
if(controlla_bit(valore, contatore-7))
digitalWrite(contatore, HIGH);
else
digitalWrite(contatore, LOW);
}
}
void loop()
{
mostra_display0(unit_a);
mostra_display1(dec_b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment