Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. //first digit working, second glitched
  2. #include <dht11.h>
  3.  
  4. dht11 DHT11;
  5.  
  6. // Output pins.
  7. static int output[] = {0,1,2,3,4,5,6,7};
  8. // 8421 code lookup table.
  9. static int segs_encoding[][4] =
  10. {{0,0,0,0},
  11. {0,0,0,1},
  12. {0,0,1,0},
  13. {0,0,1,1},
  14. {0,1,0,0},
  15. {0,1,0,1},
  16. {0,1,1,0},
  17. {0,1,1,1},
  18. {1,0,0,0},
  19. {1,0,0,1}};
  20. // Outputs an 8421 decimal digit on the output pins from
  21. // base to base + 3 in big endian order.
  22. void show(int base, int num) {
  23. for (int i = 0; i < 4; ++i) {
  24. if(segs_encoding[num][i] == 1) {
  25. digitalWrite(base + 3 - i , HIGH);
  26. } else {
  27. digitalWrite(base + 3 - i , LOW);
  28. }
  29. }
  30. }
  31. // Output a decimal value.
  32. void show_decimal(int x, int y) {
  33. show(3, x);
  34. show(7, y);
  35. }
  36. // the setup routine runs once when you press reset:
  37. void setup() {
  38. DHT11.attach(13);
  39. Serial.begin(9600);
  40. for (int i = 3; i < 12; ++i)
  41. pinMode(i, OUTPUT);
  42. }
  43. // the loop routine runs over and over again forever:
  44. void loop() {
  45. Serial.print("Temperature (°F): ");
  46. Serial.println(DHT11.fahrenheit(), DEC);
  47.  
  48. int chk = DHT11.fahrenheit();
  49. int x = chk/10;
  50. int y = chk%10;
  51. Serial.println(chk);
  52. static int i = 0;
  53. Serial.println(chk%10);
  54. show_decimal(x,y);
  55. delay(1000);
  56. // Increases the counter.
  57. ++i;
  58. if (i == 10)
  59. i = 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement