Hi there!
I am having a huge issue that couldn't resolve for the past week with the LED that indicates number of Instagram followers with the intensity of the light. The problem is that whenever the pull request is being sent by the boar- the LED turns off for like 1000-1500ms.
I need this led to stay lit while the data is coming in because I am going to have dozens of them and cannot afford having a stroboscope instead of my model.
The ideal setup on how it should work (and almost is working) The Esp32 board is pulling the number of followers from the given Instagram account. The more followers the brighter the LED lights up.
Link to the VIDEOhttps://youtu.be/tGKjcJ2xN0I
/*******************************************************************
* An example of usisng the InstagramStats library to get
* info on a given user
*
* Written by Brian Lough
* https://www.youtube.com/channel/UCezJOfu7OtqGzd5xrP3q6WA
*******************************************************************/
// ----------------------------
// Standard Libraries - Already Installed if you have ESP32 set up
// ----------------------------
#include "InstagramStats.h"
#include "Arduino.h"
#include <Servo.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
//Instagram Followers range for mapping
#define MinFollowers 74024206
#define MaxFollowers MinFollowers+100
//SERVO_SETUP
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
static const int servo1Pin = 21;
static const int servo2Pin = 22;
static const int servo3Pin = 19;
static const int servo4Pin = 23;
static const int servo5Pin = 18;
// static const int potentiometerPin = 14;
//int LED value and setup
int freq = 5000;
int ledChannel = 0;
int resolution = 8;
#define LedPin 25
// int value;
int followedByCount;
// ----------------------------
// Additional Libraries - each one of these will need to be installed.
// ----------------------------
#include "JsonStreamingParser.h"
// Used to parse the Json code within the library
// Available on the library manager (Search for "Json Streamer Parser")
// https://github.com/squix78/json-streaming-parser
//------- Replace the following! ------
char ssid[] = "VM6722315"; // your network SSID (name) iPhone Maciek VM6722315
char password[] = "w6vpPnqFrwvv"; // your network key o9h2gott w6vpPnqFrwvv
WiFiClientSecure client;
InstagramStats instaStats(client);
unsigned long delayBetweenChecks = 3000; //mean time between api requests
unsigned long whenDueToCheck = 0;
//Inputs
String userName = "katyperry"; // from their instagram url https://www.instagram.com/brian_lough/
void setup() {
Serial.begin(115200);
servo1.attach(servo1Pin);
servo2.attach(servo2Pin);
servo3.attach(servo3Pin);
servo4.attach(servo4Pin);
servo5.attach(servo5Pin);
ledcSetup(ledChannel, freq, resolution);
ledcAttachPin(LedPin, ledChannel);
// Attempt to connect to Wifi network:
Serial.print("Connecting Wifi: ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
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);
}
void getInstagramStatsForUser() {
Serial.println("Getting instagram user stats for " + userName );
InstagramUserStats response = instaStats.getUserStats(userName);
Serial.println("Response:");
Serial.print("Number of followers: ");
Serial.println(response.followedByCount);
////SERVO__MOVEMENT_FROM_FOLLOWS
if(response.followedByCount != 0){
int servoPosition = map(response.followedByCount, MinFollowers, MaxFollowers, 0, 180);
servo1.write(servoPosition);
servo2.write(servoPosition);
servo3.write(servoPosition);
servo4.write(servoPosition);
servo5.write(servoPosition);
Serial.print("Servo Position: ");
Serial.println(servoPosition);
}
////LED__INTENSITY__FROM__FOLLOWS
if(response.followedByCount != 0){
InstagramUserStats response = instaStats.getUserStats(userName);
int ledintensity = map(response.followedByCount, MinFollowers, MaxFollowers, 255, 0);
ledcWrite(ledChannel, ledintensity);
Serial.print("Led Intensity: ");
Serial.println(255-ledintensity);
//&& ledintensity < 255
}
}
void loop() {
unsigned long timeNow = millis();
if ((timeNow > whenDueToCheck)) {
getInstagramStatsForUser();
whenDueToCheck = timeNow + delayBetweenChecks;
}
}