Created
December 23, 2019 21:42
-
-
Save mePy2/49ed30793a89e3f6fa24b09f28bf99d4 to your computer and use it in GitHub Desktop.
Programma Arduino corso Automazione G. Ferraris a.s. 2019/20.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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