This commit is contained in:
Kekskurse 2020-01-17 17:13:11 +01:00
parent c4eafa227a
commit 47b1a0c730
3 changed files with 59 additions and 57 deletions

5
include/blink.h Normal file
View file

@ -0,0 +1,5 @@
void blink_fade();
void blink_short();
void blink_long();
void blink(int status);

52
src/blink.cpp Normal file
View file

@ -0,0 +1,52 @@
#include <Arduino.h>
int fadeLevel = 0;
int fadeMode = 0;
void blink_fade() {
if(fadeMode == 0) {
fadeLevel = fadeLevel + 10;
if(fadeLevel > 1023) {
fadeLevel = 1024;
fadeMode = 1;
}
}
if(fadeMode == 1) {
fadeLevel = fadeLevel - 10;
if(fadeLevel <= 0) {
fadeMode = 0;
fadeLevel = 0;
}
}
analogWrite(LED_BUILTIN, fadeLevel);
}
void blink_short() {
digitalWrite(LED_BUILTIN, LOW);
delay(200);
digitalWrite(LED_BUILTIN, HIGH);
delay(200);
}
void blink_long() {
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
digitalWrite(LED_BUILTIN, HIGH);
delay(200);
}
void blink(int status) {
if(status == 1) {
blink_short();
blink_short();
blink_short();
blink_short();
}
if(status == 2) {
blink_short();
blink_short();
blink_long();
blink_long();
}
if(status == 3) {
blink_long();
blink_long();
blink_long();
blink_long();
}
}

View file

@ -4,6 +4,7 @@
#include <LEDStripe.h>
#include <fade.h>
#include <config.h>
#include <blink.h>
#define REDPIN1 5
#define GREENPIN1 4
@ -25,59 +26,6 @@ LEDStripe led2 = {0, 0, 5000, 0, 0, 0, 0, 0, 0};
int debugLoop = 0;
//Blink
int fadeLevel = 0;
int fadeMode = 0;
void fadeled() {
if(fadeMode == 0) {
fadeLevel = fadeLevel + 10;
if(fadeLevel > 1023) {
fadeLevel = 1024;
fadeMode = 1;
}
}
if(fadeMode == 1) {
fadeLevel = fadeLevel - 10;
if(fadeLevel <= 0) {
fadeMode = 0;
fadeLevel = 0;
}
}
analogWrite(LED_BUILTIN, fadeLevel);
}
void blink_short() {
digitalWrite(LED_BUILTIN, LOW);
delay(200);
digitalWrite(LED_BUILTIN, HIGH);
delay(200);
}
void blink_long() {
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
digitalWrite(LED_BUILTIN, HIGH);
delay(200);
}
void blink(int status) {
if(status == 1) {
blink_short();
blink_short();
blink_short();
blink_short();
}
if(status == 2) {
blink_short();
blink_short();
blink_long();
blink_long();
}
if(status == 3) {
blink_long();
blink_long();
blink_long();
blink_long();
}
}
void connectWiFi() {
digitalWrite(LED_BUILTIN, LOW);
Serial.println("Start WiFi Connection");
@ -85,7 +33,7 @@ void connectWiFi() {
WiFi.begin(SSID, PSK);
while (WiFi.status() != WL_CONNECTED) {
delay(5);
fadeled();
blink_fade();
Serial.print(".");
wifiConnectionCount++;
if(wifiConnectionCount > 1000) {
@ -102,9 +50,6 @@ void connectWiFi() {
}
String getTopicNameString(String topic) {
String topicName = String(MQTT_TOPIC_START)+String(topic);
Serial.println("TopicName: "+topicName);