Advertisement
Double_G

7 segment NTP direkt port

Oct 31st, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <WiFi.h>         // WiFi library for network
  2. #include <NtpClientLib.h> // NTP Client library fot network time
  3.  
  4. #define b 0   //b szegmens
  5. #define a 2   //a szegmens
  6. #define f 4   //f szegmens
  7. #define g 5   //g szegmens
  8. #define c 12  //c szegmens
  9. #define d 13  //d szegmens
  10. #define e 14  //e szegmens
  11. #define d1 15
  12. #define d2 16
  13. #define d3 17
  14. #define d4 18
  15. #define dot 19 //dp led
  16.  
  17. unsigned long szeg[80] = {
  18. 0b00001000000000000000, //x0xxx  
  19. 0b00001001000000000001, //x1xxx
  20. 0b00001110000000100101, //x2xxx
  21. 0b00001011000000100101, //x3xxx
  22. 0b00001001000000110001, //x4xxx
  23. 0b00001011000000110100, //x5xxx
  24. 0b00001111000000110100, //x6xxx
  25. 0b00001001000000000101, //x7xxx
  26. 0b00001111000000110101, //x8xxx
  27. 0b00001011000000110101, //x9xxx
  28. 0b00010111000000010101, //xx0xx
  29. 0b00010001000000000001, //xx1xx
  30. 0b00010110000000100101, //xx2xx
  31. 0b00010011000000100101, //xx3xx
  32. 0b00010001000000110001, //xx4xx
  33. 0b00010011000000110100, //xx5xx
  34. 0b00010111000000110100, //xx6xx
  35. 0b00010001000000000101, //xx7xx
  36. 0b00010111000000110101, //xx8xx
  37. 0b00010011000000110101, //xx9xx
  38. 0b00100111000000010101, //xxx0x
  39. 0b00100001000000000001, //xxx1x
  40. 0b00100110000000100101, //xxx2x
  41. 0b00100011000000100101, //xxx3x
  42. 0b00100001000000110001, //xxx4x
  43. 0b00100011000000110100, //xxx5x
  44. 0b00100111000000110100, //xxx6x
  45. 0b00100001000000000101, //xxx7x
  46. 0b00100111000000110101, //xxx8x
  47. 0b00100011000000110101, //xxx9x
  48. 0b01000111000000010101, //xxxx1
  49. 0b01000001000000000001, //xxxx1
  50. 0b01000110000000100101, //xxxx2
  51. 0b01000011000000100101, //xxxx3
  52. 0b01000001000000110001, //xxxx4
  53. 0b01000011000000110100, //xxxx5
  54. 0b01000111000000110100, //xxxx6
  55. 0b01000001000000000101, //xxxx7
  56. 0b01000111000000110101, //xxxx8
  57. 0b01000011000000110101, //xxxx9
  58.  
  59. 0b10001000000000000000, //.0xxx  
  60. 0b10001001000000000001, //.1xxx
  61. 0b10001110000000100101, //.2xxx
  62. 0b10001011000000100101, //.3xxx
  63. 0b10001001000000110001, //.4xxx
  64. 0b10001011000000110100, //.5xxx
  65. 0b10001111000000110100, //.6xxx
  66. 0b10001001000000000101, //.7xxx
  67. 0b10001111000000110101, //.8xxx
  68. 0b10001011000000110101, //.9xxx
  69. 0b10010111000000010101, //.x0xx
  70. 0b10010001000000000001, //.x1xx
  71. 0b10010110000000100101, //.x2xx
  72. 0b10010011000000100101, //.x3xx
  73. 0b10010001000000110001, //.x4xx
  74. 0b10010011000000110100, //.x5xx
  75. 0b10010111000000110100, //.x6xx
  76. 0b10010001000000000101, //.x7xx
  77. 0b10010111000000110101, //.x8xx
  78. 0b10010011000000110101, //.x9xx
  79. 0b10100111000000010101, //.xx0x
  80. 0b10100001000000000001, //.xx1x
  81. 0b10100110000000100101, //.xx2x
  82. 0b10100011000000100101, //.xx3x
  83. 0b10100001000000110001, //.xx4x
  84. 0b10100011000000110100, //.xx5x
  85. 0b10100111000000110100, //.xx6x
  86. 0b10100001000000000101, //.xx7x
  87. 0b10100111000000110101, //.xx8x
  88. 0b10100011000000110101, //.xx9x
  89. 0b11000111000000010101, //.xxx1
  90. 0b11000001000000000001, //.xxx1
  91. 0b11000110000000100101, //.xxx2
  92. 0b11000011000000100101, //.xxx3
  93. 0b11000001000000110001, //.xxx4
  94. 0b11000011000000110100, //.xxx5
  95. 0b11000111000000110100, //.xxx6
  96. 0b11000001000000000101, //.xxx7
  97. 0b11000111000000110101, //.xxx8
  98. 0b11000011000000110101, //.xxx9
  99. };
  100.  
  101. const char* ssid     = "WiFi";               // wifi SSD
  102. const char* password = "Password";        // wifi password
  103.  
  104. String NTPServer = "NTP server";                // NTP server address
  105.  
  106. int8_t minutesTimeZone = 0;
  107. int8_t timeZone = 1;                              // timezone in central europe (hour)
  108.  
  109. String ora1, ora2, perc1, perc2, masod, ido;
  110. int ORA1,ORA2, PERC1, PERC2, MIN, lastcheck;
  111. int DELAY =1;
  112. int pont =0;
  113.  
  114. void setup()
  115. {
  116.   pinMode(a, OUTPUT);
  117.   pinMode(b, OUTPUT);
  118.   pinMode(c, OUTPUT);
  119.   pinMode(d, OUTPUT);
  120.   pinMode(e, OUTPUT);
  121.   pinMode(f, OUTPUT);
  122.   pinMode(g, OUTPUT);
  123.   pinMode(d1, OUTPUT);
  124.   pinMode(d2, OUTPUT);
  125.   pinMode(d3, OUTPUT);
  126.   pinMode(d4, OUTPUT);
  127.   pinMode(dot, OUTPUT);
  128.  
  129.   WiFi.begin(ssid, password);             // initialize WiFi
  130.  
  131.   NTP.begin (NTPServer, timeZone, true, minutesTimeZone); // initialize NTP
  132.   NTP.setInterval (1440000);           // sync interval
  133.  
  134. }
  135.  
  136. void loop()
  137. {
  138.   if ((millis()-lastcheck)>=1000) {
  139.     lastcheck = millis();
  140.     ido = NTP.getTimeDateString ();
  141.     ora1 = (ido.substring(0,1));
  142.     ora2 = (ido.substring(1,2));
  143.     perc1 = (ido.substring(3,4));
  144.     perc2 = (ido.substring(4,5));
  145.     masod = (ido.substring(6,8));
  146.     ORA1=ora1.toInt();
  147.     ORA2=ora2.toInt();
  148.     PERC1=perc1.toInt();
  149.     PERC2=perc2.toInt();
  150.   }
  151.  
  152.   MIN=masod.toInt();
  153.   if ( (MIN % 2) == 0) // páros és áratlan észelése a másodpercben.
  154.   {
  155.     pont=0; //ha páros, nem világit a dp led
  156.   }
  157.      else {
  158.    pont=40; //ha páratlan akkor világit a dp led
  159.      }
  160.  
  161.   int tomb[4]= {ORA1,ORA2,PERC1,PERC2};
  162.    
  163.   for (int i=0;i<4;i++) {
  164.   int kiirni = (tomb[i] + (10*i))+pont;
  165.   portDISABLE_INTERRUPTS();
  166.   REG_WRITE(GPIO_OUT_W1TS_REG, szeg[kiirni]);//GPIO2 HIGH (set)
  167.   REG_WRITE(GPIO_OUT_W1TC_REG, ~szeg[kiirni]);//GPIO2 LOW (clear)
  168.   portENABLE_INTERRUPTS();
  169.   delay(2);
  170.   }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement