Zafer ŞAHİN
Mahna Mahna ...
Arduino ile Dijital Termometre
Sümer abi'den gelen istek üzerine kütüphane kullanmadan yazılmış, 4 digit 8 segment(nokta kullanılmazsa 7 segment) led ekran kodu. Seri porttan aldığı 4 basamağa kadar olan rakamı, LED ekrana yazıyor.
Sümer abi'den gelen istek üzerine kütüphane kullanmadan yazılmış, 4 digit 8 segment(nokta kullanılmazsa 7 segment) led ekran kodu. Seri porttan aldığı 4 basamağa kadar olan rakamı, LED ekrana yazıyor.
Kod:
int aPin = 2; // A
int bPin = 3; // _______
int cPin = 4; // | |
int dPin = 5; // F | G | B
int ePin = 6; // |_______|
int fPin = 7; // | |
int gPin = 8; // E | | C
int hPin = 9; // |_______| o H
int dig1 = 0; //
int dig2 = 0; // D
int dig3 = 0;
int dig4 = 0;
int DTime = 4;
long sNum = 1234; // Varsayılan olarak LED ekranda gosterilecek numara
void setup(){
pinMode(aPin, OUTPUT);
pinMode(bPin, OUTPUT);
pinMode(cPin, OUTPUT);
pinMode(dPin, OUTPUT);
pinMode(ePin, OUTPUT);
pinMode(fPin, OUTPUT);
pinMode(gPin, OUTPUT);
pinMode(hPin, OUTPUT);
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
digitalWrite( A0, LOW);
digitalWrite( A1, LOW);
digitalWrite( A2, LOW);
digitalWrite( A3, LOW);
Serial.begin(9600);
digiCalc(sNum);
}
void loop(){
if (Serial.available() > 0) {
sNum = Serial.parseInt();
digiCalc(sNum);
}
digitalWrite( A0, LOW); //digit 1
pickNumber(dig1);
digitalWrite( A0, HIGH);
delay(DTime);
digitalWrite( A0, LOW);
digitalWrite( A1, LOW); //digit 2
pickNumber(dig2);
digitalWrite( A1, HIGH);
delay(DTime);
digitalWrite( A1, LOW);
digitalWrite( A2, LOW); //digit 3
pickNumber(dig3);
digitalWrite( A2, HIGH);
delay(DTime);
digitalWrite( A2, LOW);
digitalWrite( A3, LOW); //digit 4
pickNumber(dig4);
digitalWrite( A3, HIGH);
delay(DTime);
digitalWrite( A3, LOW);
}
void digiCalc(long num){
Serial.println(num);
dig1 = num / 1000;
num = num - (dig1 * 1000);
dig2 = num / 100;
num = num - (dig2 * 100);
dig3 = num / 10;
num = num - (dig3 * 10);
dig4 = num;
}
void pickNumber(char x){
switch(x){
case 0: zero(0); break;
case 1: one(0); break;
case 2: two(0); break;
case 3: three(0); break;
case 4: four(0); break;
case 5: five(0); break;
case 6: six(0); break;
case 7: seven(0); break;
case 8: eight(0); break;
case 9: nine(0); break;
default: dot(); break;
}
}
void clearLEDs(){
digitalWrite(aPin, LOW); // A
digitalWrite(bPin, LOW); // B
digitalWrite(cPin, LOW); // C
digitalWrite(dPin, LOW); // D
digitalWrite(ePin, LOW); // E
digitalWrite(fPin, LOW); // F
digitalWrite(gPin, LOW); // G
digitalWrite(hPin, LOW); // H
}
void zero(boolean bDot){
digitalWrite( aPin, HIGH);
digitalWrite( bPin, HIGH);
digitalWrite( cPin, HIGH);
digitalWrite( dPin, HIGH);
digitalWrite( ePin, HIGH);
digitalWrite( fPin, HIGH);
digitalWrite( gPin, LOW);
digitalWrite( hPin, LOW);
if(bDot) digitalWrite( hPin, HIGH);
}
void one(boolean bDot){
digitalWrite( aPin, LOW);
digitalWrite( bPin, HIGH);
digitalWrite( cPin, HIGH);
digitalWrite( dPin, LOW);
digitalWrite( ePin, LOW);
digitalWrite( fPin, LOW);
digitalWrite( gPin, LOW);
digitalWrite( hPin, LOW);
if(bDot) digitalWrite( hPin, HIGH);
}
void two(boolean bDot){
digitalWrite( aPin, HIGH);
digitalWrite( bPin, HIGH);
digitalWrite( cPin, LOW);
digitalWrite( dPin, HIGH);
digitalWrite( ePin, HIGH);
digitalWrite( fPin, LOW);
digitalWrite( gPin, HIGH);
digitalWrite( hPin, LOW);
if(bDot) digitalWrite( hPin, HIGH);
}
void three(boolean bDot){
digitalWrite( aPin, HIGH);
digitalWrite( bPin, HIGH);
digitalWrite( cPin, HIGH);
digitalWrite( dPin, HIGH);
digitalWrite( ePin, LOW);
digitalWrite( fPin, LOW);
digitalWrite( gPin, HIGH);
digitalWrite( hPin, LOW);
if(bDot) digitalWrite( hPin, HIGH);
}
void four(boolean bDot){
digitalWrite( aPin, LOW);
digitalWrite( bPin, HIGH);
digitalWrite( cPin, HIGH);
digitalWrite( dPin, LOW);
digitalWrite( ePin, LOW);
digitalWrite( fPin, HIGH);
digitalWrite( gPin, HIGH);
digitalWrite( hPin, LOW);
if(bDot) digitalWrite( hPin, HIGH);
}
void five(boolean bDot){
digitalWrite( aPin, HIGH);
digitalWrite( bPin, LOW);
digitalWrite( cPin, HIGH);
digitalWrite( dPin, HIGH);
digitalWrite( ePin, LOW);
digitalWrite( fPin, HIGH);
digitalWrite( gPin, HIGH);
digitalWrite( hPin, LOW);
if(bDot) digitalWrite( hPin, HIGH);
}
void six(boolean bDot){
digitalWrite( aPin, HIGH);
digitalWrite( bPin, LOW);
digitalWrite( cPin, HIGH);
digitalWrite( dPin, HIGH);
digitalWrite( ePin, HIGH);
digitalWrite( fPin, HIGH);
digitalWrite( gPin, HIGH);
digitalWrite( hPin, LOW);
if(bDot) digitalWrite( hPin, HIGH);
}
void seven(boolean bDot){
digitalWrite( aPin, HIGH);
digitalWrite( bPin, HIGH);
digitalWrite( cPin, HIGH);
digitalWrite( dPin, LOW);
digitalWrite( ePin, LOW);
digitalWrite( fPin, LOW);
digitalWrite( gPin, LOW);
digitalWrite( hPin, LOW);
if(bDot) digitalWrite( hPin, HIGH);
}
void eight(boolean bDot){
digitalWrite( aPin, HIGH);
digitalWrite( bPin, HIGH);
digitalWrite( cPin, HIGH);
digitalWrite( dPin, HIGH);
digitalWrite( ePin, HIGH);
digitalWrite( fPin, HIGH);
digitalWrite( gPin, HIGH);
digitalWrite( hPin, LOW);
if(bDot) digitalWrite( hPin, HIGH);
}
void nine(boolean bDot){
digitalWrite( aPin, HIGH);
digitalWrite( bPin, HIGH);
digitalWrite( cPin, HIGH);
digitalWrite( dPin, HIGH);
digitalWrite( ePin, LOW);
digitalWrite( fPin, HIGH);
digitalWrite( gPin, HIGH);
digitalWrite( hPin, LOW);
if(bDot) digitalWrite( hPin, HIGH);
}
void dot(){
digitalWrite( aPin, LOW);
digitalWrite( bPin, LOW);
digitalWrite( cPin, LOW);
digitalWrite( dPin, LOW);
digitalWrite( ePin, LOW);
digitalWrite( fPin, LOW);
digitalWrite( gPin, LOW);
digitalWrite( hPin, HIGH);
}