Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <YoutubeApi.h>
  2. #include <ESP8266WiFi.h>
  3. #include <WiFiClientSecure.h>
  4. #include <ArduinoJson.h> // This Sketch doesn't technically need this, but the library does so it must be installed.
  5. //This are just for the Hello message
  6. #include "7seg_helo.h"
  7. #include "shift.h"
  8.  
  9. //Outputs
  10. #define MAX7219_Data_IN 2 //D4 of WeMos
  11. #define MAX7219_Chip_Select 0 //D3 of WeMos
  12. #define MAX7219_Clock 4 //D2 of WeMos
  13.  
  14. int buzzer = 15; //D8 of WeMos
  15.  
  16. //Variabels
  17. byte adr = 0x08;
  18. byte num = 0x00;
  19. int i = 0;
  20. long subs = 0;
  21. String thisString_prev;
  22.  
  23.  
  24. //////////////////////////////////////////////////////////////////////////////////
  25. //------- Replace the following! ------
  26. char ssid[] = "You shall not pass!"; // your network SSID (name)
  27. char password[] = "0889565101"; // your network key
  28. #define API_KEY "AIzaSyAYP811eRHcoPBCqodOIA2reTb2UWa870E"
  29. #define CHANNEL_ID "UCu7_D0o48KbfhpEohoP7YSQ" // makes up the url of channel
  30.  
  31. WiFiClientSecure client;
  32. YoutubeApi api(API_KEY, client);
  33. unsigned long api_mtbs = 60000; //mean time between api requests
  34. unsigned long api_lasttime; //last time api request has been done
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43. void setup() {
  44. Serial.begin(115200);
  45. delay(100);
  46. pinMode(buzzer, OUTPUT);
  47. digitalWrite(buzzer, LOW);
  48. delay(100);
  49.  
  50. //Define the pins as outputs and disable CS
  51. pinMode(MAX7219_Data_IN, OUTPUT);
  52. pinMode(MAX7219_Chip_Select, OUTPUT);
  53. pinMode(MAX7219_Clock, OUTPUT);
  54. digitalWrite(MAX7219_Chip_Select, HIGH);
  55. delay(200);
  56. //Setup of the 7seg module
  57. shift(0x0f, 0x00); //display test register - test mode off
  58. shift(0x0c, 0x01); //shutdown register - normal operation
  59. shift(0x0b, 0x07); //scan limit register - display digits 0 - 7
  60. shift(0x0a, 0x0f); //intensity register - max brightness
  61. shift(0x09, 0xff); //decode mode register - CodeB decode all digits
  62.  
  63. //Print the hello message
  64. hello(0,2,100);
  65.  
  66.  
  67.  
  68. // Set WiFi to station mode and disconnect from an AP if it was Previously
  69. // connected
  70. WiFi.mode(WIFI_STA);
  71. WiFi.disconnect();
  72. delay(100);
  73. // Attempt to connect to Wifi network:
  74. Serial.print("Connecting Wifi: ");
  75. Serial.println(ssid);
  76. WiFi.begin(ssid, password);
  77. while (WiFi.status() != WL_CONNECTED) {
  78. Serial.print(".");
  79. delay(500);
  80. }
  81. Serial.println("");
  82. Serial.println("WiFi connected");
  83. Serial.println("IP address: ");
  84. IPAddress ip = WiFi.localIP();
  85. Serial.println(ip);
  86. }
  87.  
  88. void loop() {
  89.  
  90. if (millis() - api_lasttime > api_mtbs) {
  91. Serial.println("1");
  92. if(api.getChannelStatistics(CHANNEL_ID))
  93. {
  94. Serial.println("2");
  95. unsigned long Count = api.channelStats.subscriberCount;
  96. String thisString = String(Count, DEC);
  97.  
  98. if(thisString != thisString_prev)
  99. {
  100. Serial.println("3");
  101. digitalWrite(buzzer,HIGH);
  102. delay(1000);
  103. digitalWrite(buzzer,LOW);
  104. }
  105.  
  106. thisString_prev = thisString;
  107.  
  108.  
  109. i = thisString.length();//This variable will go character by cahracter and send the value to the 7 segment display
  110. Serial.println("4");
  111. Serial.println("---");
  112. Serial.println(i);
  113. Serial.println("---");
  114. if(i==8)
  115. {
  116. shift(0x0b, 0x07); //scan limit register - display digits 0 thru 7
  117. adr=0x01;
  118. }
  119. if(i==7)
  120. {
  121. shift(0x0b, 0x06); //scan limit register - display digits 0 thru 7
  122. adr=0x01;
  123. }
  124. if(i==6)
  125. {
  126. shift(0x0b, 0x05); //scan limit register - display digits 0 thru 7
  127. adr=0x01;
  128. }
  129. if(i==5)
  130. {
  131. shift(0x0b, 0x04); //scan limit register - display digits 0 thru 7
  132. adr=0x01;
  133. }
  134. if(i==4)
  135. {
  136. shift(0x0b, 0x03); //scan limit register - display digits 0 thru 7
  137. adr=0x01;
  138. }
  139. if(i==3)
  140. {
  141. shift(0x0b, 0x02); //scan limit register - display digits 0 thru 7
  142. adr=0x01;
  143. }
  144. if(i==2)
  145. {
  146. shift(0x0b, 0x01); //scan limit register - display digits 0 thru 7
  147. adr=0x01;
  148. }
  149. if(i==1)
  150. {
  151. shift(0x0b, 0x00); //scan limit register - display digits 0 thru 7
  152. adr=0x01;
  153. }
  154. i=i-1;
  155.  
  156.  
  157. Serial.println("5");
  158.  
  159.  
  160. while (i >= 0)
  161. {
  162. if(thisString[i] == '0')
  163. {
  164. num = 0x00;
  165. }
  166. if(thisString[i] == '1')
  167. {
  168. num = 0x01;
  169. }
  170. if(thisString[i] == '2')
  171. {
  172. num = 0x02;
  173. }
  174. if(thisString[i] == '3')
  175. {
  176. num = 0x03;
  177. }
  178. if(thisString[i] == '4')
  179. {
  180. num = 0x04;
  181. }
  182. if(thisString[i] == '5')
  183. {
  184. num = 0x05;
  185. }
  186. if(thisString[i] == '6')
  187. {
  188. num = 0x06;
  189. }
  190. if(thisString[i] == '7')
  191. {
  192. num = 0x07;
  193. }
  194. if(thisString[i] == '8')
  195. {
  196. num = 0x08;
  197. }
  198. if(thisString[i] == '9')
  199. {
  200. num = 0x09;
  201. }
  202.  
  203.  
  204. shift(adr, num);
  205.  
  206.  
  207. adr=adr+0x01;
  208. i=i-1;
  209. }
  210.  
  211. Serial.println("6");
  212. }
  213. api_lasttime = millis();
  214. }
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement