Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <DHT.h>
- // Pins connected to 74HC595
- const int latchPin = 8;
- const int clockPin = 12;
- const int dataPin = 11;
- // Mapping of digits to segments for a common-anode 7-segment display
- const byte digitToSegment[10] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90};
- // DHT setup
- #define DHTPIN 2
- #define DHTTYPE DHT11
- DHT dht(DHTPIN, DHTTYPE);
- void setup() {
- pinMode(latchPin, OUTPUT);
- pinMode(clockPin, OUTPUT);
- pinMode(dataPin, OUTPUT);
- dht.begin();
- }
- void loop() {
- float temp = dht.readTemperature();
- int tempInt = (int)temp; // truncate decimal
- int digit1 = tempInt / 10; // tens place
- int digit2 = tempInt % 10; // ones place
- digitalWrite(latchPin, LOW);
- shiftOut(dataPin, clockPin, MSBFIRST, digitToSegment[digit1]);
- shiftOut(dataPin, clockPin, MSBFIRST, digitToSegment[digit2]);
- digitalWrite(latchPin, HIGH);
- delay(2000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement