Skip to content

Instantly share code, notes, and snippets.

@JasonMillward
Last active July 5, 2017 03:16
Show Gist options
  • Save JasonMillward/c73a994adcb8f3926780302970b5b279 to your computer and use it in GitHub Desktop.
Save JasonMillward/c73a994adcb8f3926780302970b5b279 to your computer and use it in GitHub Desktop.
#include <Adafruit_NeoPixel.h>
#include "ESP8266WiFi.h"
#define PIN D4
Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, PIN, NEO_GRB + NEO_KHZ800);
bool discomode = true;
void setup() {
WiFi.mode(WIFI_STA);
WiFi.disconnect();
strip.begin();
strip.show();
WiFi.forceSleepBegin();
}
void loop() {
strip.setBrightness(10);
rainbowCycle(20);
WiFi.forceSleepWake();
WiFi.scanNetworksAsync(prinScanResult);
discomode = true;
}
void prinScanResult(int networksFound)
{
uint16_t i, j;
String wifiname = "test wifi";
bool found = false;
for (int i = 0; i < networksFound; i++) {
if (wifiname == WiFi.SSID(i)) {
found = true;
}
}
if (found) {
discomode = false;
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, 255, 255, 255);
}
strip.show();
}
WiFi.forceSleepBegin();
}
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for (j = 0; j < 256 * 5; j++) {
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
if (discomode) {
strip.show();
}
delay(wait);
}
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment