1000 Subs!

Here I left the code for the ESP8266, it is based on the youtubeapi example with minor modifications:

#include <YoutubeApi.h>

/*******************************************************************
* An example of bot that echos back any messages received *
* *
* written by Giacarlo Bacchio (Gianbacchio on Github) *
* adapted by Brian Lough *
*******************************************************************/
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

#define PIN 2

#define NUMPIXELS 9

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
//——- Replace the following! ——
char ssid[] = “……….”; // your network SSID (name)
char password[] = “…………”; // your network key
#define API_KEY “…….” // your google apps API Token
#define CHANNEL_ID “UCF3cDM_hQMtIEJvEW1BZugg” // makes up the url of channel
WiFiClientSecure client;
YoutubeApi api(API_KEY, client);

int api_mtbs = 5000; //mean time between api requests
long api_lasttime; //last time api request has been done

long subs = 0;
long oldsubs=0;
long howmany;
void setup() {

Serial.begin(115200);

// Set WiFi to station mode and disconnect from an AP if it was Previously
// connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
WiFi.begin(ssid, password);
// Attempt to connect to Wifi network:
Serial.print(“Connecting Wifi: “);
Serial.println(ssid);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(“.”);
delay(500);
}
Serial.println(“”);
Serial.println(“WiFi connected”);
Serial.println(“IP address: “);
IPAddress ip = WiFi.localIP();
Serial.println(ip);
pixels.begin();
delay(100);
for(int i=0;i<NUMPIXELS;i++)
{
pixels.setPixelColor(i, pixels.Color(0,0,255));
}
pixels.show();
delay(2000);
for(int i=0;i<NUMPIXELS;i++)
{
pixels.setPixelColor(i, pixels.Color(0,0,0));
}
pixels.show();
delay(2000);
if(api.getChannelStatistics(CHANNEL_ID))
{
oldsubs = api.channelStats.subscriberCount;
Serial.print(“Initialization: “);
Serial.println(oldsubs);
}

}

void all(int r,int g,int b)
{
for(int i=0;i<NUMPIXELS;i++)
{
pixels.setPixelColor(i, pixels.Color(r,g,b));
}
pixels.show();
}
void loop() {
long intersubs;
if (millis() > api_lasttime + api_mtbs) {
if(api.getChannelStatistics(CHANNEL_ID))
{
Serial.println(“———Stats———“);
Serial.print(“Subscriber Count: “);
Serial.println(api.channelStats.subscriberCount);
subs = api.channelStats.subscriberCount;
intersubs=subs;

while (oldsubs<intersubs)
{
Serial.println(intersubs-oldsubs);
all(255,255,255);
delay(2000);
all(0,0,0);
delay(2000);
intersubs–;
}
while (oldsubs>intersubs)
{
Serial.println(oldsubs-intersubs);
all(255,0,0);
delay(2000);
all(0,0,0);
delay(2000);
intersubs++;
}
oldsubs=subs;

}
api_lasttime = millis();
}
}

 

By | 2016-11-13T22:23:19+00:00 November 13th, 2016|Industrial Design, Projects, Prototyping|0 Comments

About the Author: