Double_G

7 segment NTP direkt port interrupt

Oct 31st, 2018
257
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.  
  5. #define b 0   //b szegmens
  6. #define a 2   //a szegmens
  7. #define f 4   //f szegmens
  8. #define g 5   //g szegmens
  9. #define c 12  //c szegmens
  10. #define d 13  //d szegmens
  11. #define e 14  //e szegmens
  12. #define d1 15
  13. #define d2 16
  14. #define d3 17
  15. #define d4 18
  16. #define dot 19 //dp led
  17.  
  18. unsigned long szeg[80] = {
  19. 0b00001000000000000000, //x0xxx  
  20. 0b00001001000000000001, //x1xxx
  21. 0b00001110000000100101, //x2xxx
  22. 0b00001011000000100101, //x3xxx
  23. 0b00001001000000110001, //x4xxx
  24. 0b00001011000000110100, //x5xxx
  25. 0b00001111000000110100, //x6xxx
  26. 0b00001001000000000101, //x7xxx
  27. 0b00001111000000110101, //x8xxx
  28. 0b00001011000000110101, //x9xxx
  29. 0b00010111000000010101, //xx0xx
  30. 0b00010001000000000001, //xx1xx
  31. 0b00010110000000100101, //xx2xx
  32. 0b00010011000000100101, //xx3xx
  33. 0b00010001000000110001, //xx4xx
  34. 0b00010011000000110100, //xx5xx
  35. 0b00010111000000110100, //xx6xx
  36. 0b00010001000000000101, //xx7xx
  37. 0b00010111000000110101, //xx8xx
  38. 0b00010011000000110101, //xx9xx
  39. 0b00100111000000010101, //xxx0x
  40. 0b00100001000000000001, //xxx1x
  41. 0b00100110000000100101, //xxx2x
  42. 0b00100011000000100101, //xxx3x
  43. 0b00100001000000110001, //xxx4x
  44. 0b00100011000000110100, //xxx5x
  45. 0b00100111000000110100, //xxx6x
  46. 0b00100001000000000101, //xxx7x
  47. 0b00100111000000110101, //xxx8x
  48. 0b00100011000000110101, //xxx9x
  49. 0b01000111000000010101, //xxxx1
  50. 0b01000001000000000001, //xxxx1
  51. 0b01000110000000100101, //xxxx2
  52. 0b01000011000000100101, //xxxx3
  53. 0b01000001000000110001, //xxxx4
  54. 0b01000011000000110100, //xxxx5
  55. 0b01000111000000110100, //xxxx6
  56. 0b01000001000000000101, //xxxx7
  57. 0b01000111000000110101, //xxxx8
  58. 0b01000011000000110101, //xxxx9
  59.  
  60. 0b10001000000000000000, //.0xxx  
  61. 0b10001001000000000001, //.1xxx
  62. 0b10001110000000100101, //.2xxx
  63. 0b10001011000000100101, //.3xxx
  64. 0b10001001000000110001, //.4xxx
  65. 0b10001011000000110100, //.5xxx
  66. 0b10001111000000110100, //.6xxx
  67. 0b10001001000000000101, //.7xxx
  68. 0b10001111000000110101, //.8xxx
  69. 0b10001011000000110101, //.9xxx
  70. 0b10010111000000010101, //.x0xx
  71. 0b10010001000000000001, //.x1xx
  72. 0b10010110000000100101, //.x2xx
  73. 0b10010011000000100101, //.x3xx
  74. 0b10010001000000110001, //.x4xx
  75. 0b10010011000000110100, //.x5xx
  76. 0b10010111000000110100, //.x6xx
  77. 0b10010001000000000101, //.x7xx
  78. 0b10010111000000110101, //.x8xx
  79. 0b10010011000000110101, //.x9xx
  80. 0b10100111000000010101, //.xx0x
  81. 0b10100001000000000001, //.xx1x
  82. 0b10100110000000100101, //.xx2x
  83. 0b10100011000000100101, //.xx3x
  84. 0b10100001000000110001, //.xx4x
  85. 0b10100011000000110100, //.xx5x
  86. 0b10100111000000110100, //.xx6x
  87. 0b10100001000000000101, //.xx7x
  88. 0b10100111000000110101, //.xx8x
  89. 0b10100011000000110101, //.xx9x
  90. 0b11000111000000010101, //.xxx1
  91. 0b11000001000000000001, //.xxx1
  92. 0b11000110000000100101, //.xxx2
  93. 0b11000011000000100101, //.xxx3
  94. 0b11000001000000110001, //.xxx4
  95. 0b11000011000000110100, //.xxx5
  96. 0b11000111000000110100, //.xxx6
  97. 0b11000001000000000101, //.xxx7
  98. 0b11000111000000110101, //.xxx8
  99. 0b11000011000000110101, //.xxx9
  100. };
  101.  
  102. const char* ssid     = "WiFi";               // wifi SSD
  103. const char* password = "Password";        // wifi password
  104.  
  105. String NTPServer = "NTP server";                // NTP server address
  106.  
  107. int8_t minutesTimeZone = 0;
  108. int8_t timeZone = 1;                              // timezone in central europe (hour)
  109.  
  110. String ora1, ora2, perc1, perc2, masod, ido;
  111. int ORA1,ORA2, PERC1, PERC2, MIN;
  112. int DELAY =1;
  113. int pont =0;
  114.  
  115. int tomb[4];
  116. int kiirni=0;
  117. int digit = 0;
  118. int counter = 0;
  119.  
  120. /* create a hardware timer */
  121. hw_timer_t * timer = NULL;
  122.  
  123.  
  124. //------------- Kijelző frissítő interrupt rutin --------------------
  125.  
  126. void IRAM_ATTR onTimer(){
  127.   kiirni = (tomb[digit] + (10*digit));
  128.   if (counter>=200) kiirni += 40;  //pontot kigyújtani
  129.   if (counter>=400) counter=0;
  130.   REG_WRITE(GPIO_OUT_W1TS_REG, szeg[kiirni]);//GPIO2 HIGH (set)
  131.   REG_WRITE(GPIO_OUT_W1TC_REG, ~szeg[kiirni]);//GPIO2 LOW (clear)
  132.   digit++;
  133.   counter++;
  134.   if (digit>=4) digit=0;
  135. }
  136.  
  137.  
  138. void setup()
  139. {
  140.   pinMode(a, OUTPUT);
  141.   pinMode(b, OUTPUT);
  142.   pinMode(c, OUTPUT);
  143.   pinMode(d, OUTPUT);
  144.   pinMode(e, OUTPUT);
  145.   pinMode(f, OUTPUT);
  146.   pinMode(g, OUTPUT);
  147.   pinMode(d1, OUTPUT);
  148.   pinMode(d2, OUTPUT);
  149.   pinMode(d3, OUTPUT);
  150.   pinMode(d4, OUTPUT);
  151.   pinMode(dot, OUTPUT);
  152.  
  153.   WiFi.begin(ssid, password);             // initialize WiFi
  154.  
  155.   NTP.begin (NTPServer, timeZone, true, minutesTimeZone); // initialize NTP
  156.   NTP.setInterval (1440000);           // sync interval
  157.  
  158. /* Use 1st timer of 4 */
  159.   /* 1 tick take 1/(80MHZ/80) = 1us so we set divider 80 and count up */
  160.   timer = timerBegin(0, 80, true);
  161.  
  162.   /* Attach onTimer function to our timer */
  163.   timerAttachInterrupt(timer, &onTimer, true);
  164.  
  165.   /* Set alarm to call onTimer function every second 1 tick is 1us
  166.   => 1 second is 1000000us */
  167.   /* Repeat the alarm (third parameter) */
  168.   timerAlarmWrite(timer, 5000, true);   //100Hz
  169.  
  170.   /* Start an alarm */
  171.   timerAlarmEnable(timer);
  172.  
  173. }
  174.  
  175. void loop()
  176. {
  177.     ido = NTP.getTimeDateString ();
  178.     ora1 = (ido.substring(0,1));
  179.     ora2 = (ido.substring(1,2));
  180.     perc1 = (ido.substring(3,4));
  181.     perc2 = (ido.substring(4,5));
  182.     masod = (ido.substring(6,8));
  183.     tomb[0] = ora1.toInt();
  184.     tomb[1] = ora2.toInt();
  185.     tomb[2] = perc1.toInt();
  186.     tomb[3] = perc2.toInt();
  187.     Serial.print(counter);
  188.    
  189.   delay(1000);
  190. }
Advertisement
Add Comment
Please, Sign In to add comment