Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //first digit working, second glitched
- #include <dht11.h>
- dht11 DHT11;
- // Output pins.
- static int output[] = {0,1,2,3,4,5,6,7};
- // 8421 code lookup table.
- static int segs_encoding[][4] =
- {{0,0,0,0},
- {0,0,0,1},
- {0,0,1,0},
- {0,0,1,1},
- {0,1,0,0},
- {0,1,0,1},
- {0,1,1,0},
- {0,1,1,1},
- {1,0,0,0},
- {1,0,0,1}};
- // Outputs an 8421 decimal digit on the output pins from
- // base to base + 3 in big endian order.
- void show(int base, int num) {
- for (int i = 0; i < 4; ++i) {
- if(segs_encoding[num][i] == 1) {
- digitalWrite(base + 3 - i , HIGH);
- } else {
- digitalWrite(base + 3 - i , LOW);
- }
- }
- }
- // Output a decimal value.
- void show_decimal(int x, int y) {
- show(3, x);
- show(7, y);
- }
- // the setup routine runs once when you press reset:
- void setup() {
- DHT11.attach(13);
- Serial.begin(9600);
- for (int i = 3; i < 12; ++i)
- pinMode(i, OUTPUT);
- }
- // the loop routine runs over and over again forever:
- void loop() {
- Serial.print("Temperature (°F): ");
- Serial.println(DHT11.fahrenheit(), DEC);
- int chk = DHT11.fahrenheit();
- int x = chk/10;
- int y = chk%10;
- Serial.println(chk);
- static int i = 0;
- Serial.println(chk%10);
- show_decimal(x,y);
- delay(1000);
- // Increases the counter.
- ++i;
- if (i == 10)
- i = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement