Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "DHT.h"
- #define DHTPIN A0
- #define DHTTYPE DHT11
- DHT dht(DHTPIN, DHTTYPE);
- int C1 = 3;
- int C2 = 2;
- int a = 10;
- int b = 9;
- int c = 8;
- int d = 7;
- int e = 6;
- int f = 5;
- int g = 4;
- int firstDig, secDig;
- float t = 0;
- //----------------------------------
- void setup()
- {
- pinMode(C1, OUTPUT);
- pinMode(C2, OUTPUT);
- digitalWrite(C1, HIGH);
- digitalWrite(C2, HIGH);
- for (int i = 4; i < 11; i++)
- {
- pinMode(i, OUTPUT);
- }
- }
- //----------------------------------
- void loop()
- {
- t = dht.readTemperature();
- digitalWrite(C1, HIGH);
- digitalWrite(C2, HIGH);
- firstDig = (int)t / 10;
- pintar(firstDig);
- digitalWrite(C1, LOW); //liga c1
- delay(10);
- // if (not(secDig == (int)t % 10)) // para não ficar repintando o display se a temperatura não mudou
- // {
- digitalWrite(C1, HIGH);
- digitalWrite(C2, HIGH);
- secDig = (int)t % 10;
- pintar(secDig);
- digitalWrite(C2, LOW); //liga c2
- // }
- delay(10);
- }
- //----------------------------------
- void pintar(int numero)
- {
- switch (numero)
- {
- case 0:
- {
- digitalWrite(a, LOW);
- digitalWrite(b, LOW);
- digitalWrite(c, LOW);
- digitalWrite(d, LOW);
- digitalWrite(e, LOW);
- digitalWrite(f, LOW);
- digitalWrite(g, HIGH);
- break;
- }
- case 1:
- {
- digitalWrite(a, HIGH);
- digitalWrite(b, LOW);
- digitalWrite(c, LOW);
- digitalWrite(d, HIGH);
- digitalWrite(e, HIGH);
- digitalWrite(f, HIGH);
- digitalWrite(g, HIGH);
- break;
- }
- case 2:
- {
- digitalWrite(a, LOW);
- digitalWrite(b, LOW);
- digitalWrite(c, HIGH);
- digitalWrite(d, LOW);
- digitalWrite(e, LOW);
- digitalWrite(f, HIGH);
- digitalWrite(g, LOW);
- break;
- }
- case 3:
- {
- digitalWrite(a, LOW);
- digitalWrite(b, LOW);
- digitalWrite(c, LOW);
- digitalWrite(d, LOW);
- digitalWrite(e, HIGH);
- digitalWrite(f, HIGH);
- digitalWrite(g, LOW);
- break;
- }
- case 4:
- {
- digitalWrite(a, HIGH);
- digitalWrite(b, LOW);
- digitalWrite(c, LOW);
- digitalWrite(d, HIGH);
- digitalWrite(e, HIGH);
- digitalWrite(f, LOW);
- digitalWrite(g, LOW);
- break;
- }
- case 5:
- {
- digitalWrite(a, LOW);
- digitalWrite(b, HIGH);
- digitalWrite(c, LOW);
- digitalWrite(d, LOW);
- digitalWrite(e, HIGH);
- digitalWrite(f, LOW);
- digitalWrite(g, LOW);
- break;
- }
- case 6:
- {
- digitalWrite(a, LOW);
- digitalWrite(b, HIGH);
- digitalWrite(c, LOW);
- digitalWrite(d, LOW);
- digitalWrite(e, LOW);
- digitalWrite(f, LOW);
- digitalWrite(g, LOW);
- break;
- }
- case 7:
- {
- digitalWrite(a, LOW);
- digitalWrite(b, LOW);
- digitalWrite(c, LOW);
- digitalWrite(d, HIGH);
- digitalWrite(e, HIGH);
- digitalWrite(f, HIGH);
- digitalWrite(g, HIGH);
- break;
- }
- case 8:
- {
- digitalWrite(a, LOW);
- digitalWrite(b, LOW);
- digitalWrite(c, LOW);
- digitalWrite(d, LOW);
- digitalWrite(e, LOW);
- digitalWrite(f, LOW);
- digitalWrite(g, LOW);
- break;
- }
- case 9:
- {
- digitalWrite(a, LOW);
- digitalWrite(b, LOW);
- digitalWrite(c, LOW);
- digitalWrite(d, LOW);
- digitalWrite(e, HIGH);
- digitalWrite(f, LOW);
- digitalWrite(g, LOW);
- break;
- }
- default:
- {
- digitalWrite(a, LOW);
- digitalWrite(b, HIGH);
- digitalWrite(c, HIGH);
- digitalWrite(d, LOW);
- digitalWrite(e, LOW);
- digitalWrite(f, LOW);
- digitalWrite(g, LOW);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement