Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *
- * Net LED Project
- * V1.0
- *
- * This Program tries to ping on a IP4 Address every 2 seconds and shows the result via the color of the LED Stripe.
- *
- * State-Color Table:
- * State | Color
- * -------------------|------------------
- * connection to WLAN | red one moving blue pixel
- * ping failed | red one moving yellow pixel
- * ping ok | green one moving magenta pixel
- *
- * Hardware:
- * - LED Strip with APA102 chip.
- * - Board: ESP8266 D1 Mini.
- *
- * Arduino dev env, board settiungs:
- * - Board: Generic ESP8266 Module
- * - Upload Speed: 921600
- * - CPU Freq: 80MHz
- * - Crystak Freq: 26 MHz
- * - Flash Size: 4M (1M SPIFFS)
- * - Flash Mode: DOUT (comp)
- * - Flash Freq: 40MHz
- * - Reset Methode: ck
- * - Debug port: Dis
- * - Kbug Level: none
- * - IwIP Variant: v1.4 Highter Bandwidth
- * - VTables: Flash
- * - Excepions: Dis
- * - Biltin Led: 1
- * - Erase Flash: only Sktech
- * - Espressif FW: nonos-sdk 2.2.1 legacy
- * - SSL Support: All SSL ciphers
- * - Programmer: ArduinoISP.org
- */
- #include <ESP8266WiFi.h>
- #include <ESP8266Ping.h>
- #include <APA102.h>
- #include <Ticker.h> //Ticker Library
- //************************************************************
- // Network Setup
- //************************************************************
- const char* ssid = "SSID"; //SSID of the WALN
- const char* password = "password"; //WAP Password
- const IPAddress remote_ip(192, 156, 45, 21); //Ping destination
- //************************************************************
- //************************************************************
- // LED Setup
- //************************************************************
- const uint16_t ledCount = 20; //No of LEDs on the strip
- const uint8_t brightness = 5; // 0 = off, 31 bright
- //************************************************************
- //************************************************************
- // Globale Variablen
- //************************************************************
- const uint8_t dataPin = 5; //GPIO NO
- const uint8_t clockPin = 0; //GPIO NO
- APA102<dataPin, clockPin> ledStrip;
- rgb_color colors[ledCount];
- Ticker oLEDTimer;
- enum LED_STATE {
- ePingOK,
- ePingNOK,
- eNotCon
- } eLedState;
- #define BUILTIN_LED 2 //GPIO NO
- //************************************************************
- // Functions
- //************************************************************
- //************************************************************
- void UpdateStrip ()
- {
- static uint8_t offset= 0;
- rgb_color MainColor, RunColor ;
- switch (eLedState){
- case(ePingOK) : MainColor = rgb_color( 0,255, 0); RunColor = rgb_color( 0,225,0); break;
- case(ePingNOK): MainColor = rgb_color(225, 0, 0); RunColor = rgb_color(255, 0, 0); break;
- case(eNotCon) : MainColor = rgb_color(225, 0, 0); RunColor = rgb_color(225, 0, 0); break;
- default: MainColor = rgb_color( 0, 0,225); RunColor = rgb_color( 0, 0,225); break;
- }
- offset++;
- if (offset >= ledCount*3) {offset = 0;}
- for(uint16_t i = 0; i < ledCount; i++)
- {
- colors[i] = MainColor;
- if (i == offset )
- {
- colors[i] = RunColor;
- }
- }
- ledStrip.write(colors, ledCount, brightness);
- }
- //************************************************************
- //************************************************************
- void setup() {
- WiFi.setmode(WiFi.station)
- Serial.begin(115200);
- // Init LED strip timer
- oLEDTimer.attach(0.05, UpdateStrip);
- //Connecting to a WiFi network
- WiFi.begin(ssid, password);
- pinMode(BUILTIN_LED, OUTPUT);
- }
- //************************************************************
- //************************************************************
- void loop() {
- if (WiFi.status() == WL_CONNECTED)
- {
- Serial.print("WiFi connected with ip ");
- Serial.println(WiFi.localIP());
- Serial.print("Pinging ip ");
- Serial.println(remote_ip);
- if(Ping.ping(remote_ip))
- {
- eLedState = ePingOK;
- Serial.println("Ping OK!!");
- }
- else
- {
- eLedState = ePingNOK;
- Serial.println("Ping not OK!!");
- }
- }
- else
- {
- eLedState = eNotCon;
- Serial.println("Not Connected!!");
- }
- delay (100);
- digitalWrite(BUILTIN_LED, HIGH);
- delay (1900);
- digitalWrite(BUILTIN_LED, LOW);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement