Hello,
after getting started with arduino and reading some tuts and posts and trying things out - today I proudly present my first selfmade gadget ![]()
I had a two digits LED Display lying around that I wanted to control it with my new arduino duemilanove. So I connected it up to two shift registers and figured out how to let it count from 0 up to 99. And today I looked for a useful purpose of "my display" so I worked hard to find out how to use it as an Thermometer.
It has only a range from 0 to 99 °C but I think it works. Have a look at my sketch and tell me where to optimize it:
You may want to have a look at my blog for a picture of it: http://cojakewi.blogspot.com/
//**************************************************************//
// Name : Digital Thermometer with Shift Register & LM35 //
// Author : Jan www.cojakewi.de //
// Date : 02.02.2010 //
// Version : 1.0 //
// Notes : Code for using a 74HC595 Shift Register //
// : to control a 2 digit 7 segment LED Display //
// : to build a digital Thermometer //
//****************************************************************
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
//digit is the array for numbers 192 for 0, 249 for 1,... 255 for nothing and 191 for -
byte digit[] ={192, 249, 164, 176, 153, 146, 130, 248, 128, 144, 255, 191};
int d = 1000;//delay time
int dig1;
int dig2;
int tempPin = 0;// LM35 Pin
float temperature = 0;
void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
Serial.begin(9600);
Serial.println("cojakewi digital thermometer");
dig1 = 11;
dig2 = 11;
anzeige();
delay(d);//wait a d
analogReference(INTERNAL); //for Temp
}
void loop() {
temp();
}
void temp() {
int span = 20;
int aRead = 0;
for (int i = 0; i < span; i++) {
aRead = aRead+analogRead(tempPin);
}
aRead = aRead / 20;
temperature = (100*1.1*aRead)/1024;
temperature = constrain(temperature, 0, 99);// t>0 and <99 because of display range
Serial.print("Temperatur: ");
Serial.println(long(temperature));
if (temperature<10) {
dig1 = 10; //show nothing
dig2 = temperature; //ones
anzeige();
}
else {
dig1 = temperature/10; //first digit tens
dig2 = temperature - dig1*10; // second digit ones
anzeige (); // Programm to run
}
delay(d);
}
void anzeige () { //controls the display with shift registers
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, digit[dig2]); //ones
shiftOut(dataPin, clockPin, MSBFIRST, digit[dig1]); //tens
digitalWrite(latchPin, HIGH);
}