Code
#include <LedControl.h>
#include <DHT11.h>
int pin=4;
DHT11 dht11(pin);
LedControl lc=LedControl(8,10,9,1);
// Pin 8->DIN, 10->CLK, 9->CS(LOAD), 1 = No.of devices
void show2digit(int h,int t)
{
int seg1,seg2,seg3,seg4;
seg1 = h%10;
seg2 = h/10;
lc.setDigit(0,4,seg1,false);
lc.setDigit(0,5,seg2,false);
seg3 = t%10;
seg4 = t/10;
lc.setDigit(0,0,seg3,false);
lc.setDigit(0,1,seg4,false);
delay(300);
}
void setup()
{
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
lc.shutdown(0,false);
lc.setIntensity(0,5);
lc.clearDisplay(0);
}
void loop()
{
int err;
float temp, humi;
if((err=dht11.read(humi, temp))==0)
{
Serial.print("temperature:");
Serial.print(temp);
Serial.print(" humidity:");
Serial.print(humi);
Serial.println();
}
else
{
Serial.println();
Serial.print("Error No :");
Serial.print(err);
Serial.println();
}
lc.clearDisplay(0);
show2digit(humi,temp);
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น