//
// "Basic Push Button Hookup"
// Check dev board, pins, upload speed, etc..
// Button used here is a 2-pins, tactical, push-to-break button
// You can watch the button in action via the serial monitor
#include <WiFi.h>
#include <HTTPClient.h>
#include <FastLED.h>
#define LED_PIN 32
#define BTN_PIN 26
#define COLOR_ORDER GRB
#define CHIPSET WS2811
#define NUM_LEDS 10
#define BRIGHTNESS 50
CRGB leds[NUM_LEDS]; //new array representing the number of leds we've enabled
//bool pressed = false;
HTTPClient http;
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const String url = "https://socket-app-bfhj.onrender.com";
void setup() {
delay(3000); // sanity delay
Serial.begin(115200);
WiFi.begin(ssid, password, 6);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.print("OK! IP=");
Serial.println(WiFi.localIP());
Serial.print("Fetching " + url + "... ");
http.begin(url);
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
Serial.print("HTTP ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println();
Serial.println(payload);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
Serial.println(":-(");
}
pinMode(BTN_PIN, INPUT_PULLUP);
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
// FastLED.setBrightness( BRIGHTNESS );
FastLED.setMaxPowerInVoltsAndMilliamps( 3.3, 500);
}
void loop() {
// digitalWrite(BTN_PIN, HIGH);
if (digitalRead(BTN_PIN) == 0) {
fill_solid(leds, NUM_LEDS, CRGB::Black);
Serial.print(digitalRead(BTN_PIN));
} else {
fill_solid(leds, NUM_LEDS, CRGB::Green);
Serial.print(digitalRead(BTN_PIN));
};
FastLED.show();
delay(100);
}