add led panel guides
This commit is contained in:
parent
f894134310
commit
f9e04c8dbf
|
@ -4,9 +4,20 @@
|
|||
* topics und handler implementieren
|
||||
*/
|
||||
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#ifdef __AVR__
|
||||
#include <avr/power.h>
|
||||
#endif
|
||||
|
||||
#define LEDPIN 8 //PB0 = D8
|
||||
Adafruit_NeoPixel leds = Adafruit_NeoPixel(9, LEDPIN, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
uint8_t wheelpos=0;
|
||||
#include "Ethernet.h"
|
||||
#include "PubSubClient.h"
|
||||
|
||||
boolean useethernet=false;
|
||||
|
||||
//Ethernet and MQTT
|
||||
String ip = "";
|
||||
uint8_t mac[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x06};
|
||||
|
@ -98,36 +109,47 @@ void setup() {
|
|||
while (!Serial) {};
|
||||
Serial.println("Booting");
|
||||
|
||||
|
||||
if (Ethernet.begin(mac) == 0) { // setup ethernet communication using DHCP
|
||||
Serial.println("Unable to configure Ethernet using DHCP");
|
||||
Serial.flush();
|
||||
delay(200);
|
||||
for (;;);
|
||||
leds.begin();
|
||||
for(uint8_t i=0;i<leds.numPixels();i++){ //set color of all leds
|
||||
leds.setPixelColor(i, leds.Color(100,100,100));
|
||||
}
|
||||
|
||||
Serial.println("Ethernet configured via DHCP");
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(Ethernet.localIP());
|
||||
Serial.println();
|
||||
|
||||
ip = String (Ethernet.localIP()[0]);
|
||||
ip = ip + ".";
|
||||
ip = ip + String (Ethernet.localIP()[1]);
|
||||
ip = ip + ".";
|
||||
ip = ip + String (Ethernet.localIP()[2]);
|
||||
ip = ip + ".";
|
||||
ip = ip + String (Ethernet.localIP()[3]);
|
||||
//Serial.println(ip);
|
||||
|
||||
// setup mqtt client
|
||||
mqttClient.setClient(ethClient);
|
||||
mqttClient.setServer("10.0.0.1", 1883);
|
||||
Serial.println("MQTT client configured");
|
||||
mqttClient.setCallback(callback);
|
||||
leds.show();
|
||||
|
||||
|
||||
Serial.println("Ready");
|
||||
if (Ethernet.begin(mac) == 0) { // setup ethernet communication using DHCP
|
||||
//Unable to configure Ethernet using DHCP
|
||||
Serial.println("Unable to configure Ethernet using DHCP");
|
||||
delay(200);
|
||||
//for (;;);
|
||||
|
||||
|
||||
}else{
|
||||
useethernet=true;
|
||||
Serial.println("Ethernet configured via DHCP");
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(Ethernet.localIP());
|
||||
Serial.println();
|
||||
|
||||
ip = String (Ethernet.localIP()[0]);
|
||||
ip = ip + ".";
|
||||
ip = ip + String (Ethernet.localIP()[1]);
|
||||
ip = ip + ".";
|
||||
ip = ip + String (Ethernet.localIP()[2]);
|
||||
ip = ip + ".";
|
||||
ip = ip + String (Ethernet.localIP()[3]);
|
||||
//Serial.println(ip);
|
||||
|
||||
// setup mqtt client
|
||||
mqttClient.setClient(ethClient);
|
||||
mqttClient.setServer("10.0.0.1", 1883);
|
||||
Serial.println("MQTT client configured");
|
||||
mqttClient.setCallback(callback);
|
||||
|
||||
|
||||
Serial.println("Ready");
|
||||
|
||||
}
|
||||
last_send = millis();
|
||||
|
||||
|
||||
|
@ -154,10 +176,13 @@ void reconnect() {
|
|||
|
||||
void loop() {
|
||||
long loopmillis=millis();
|
||||
if (!mqttClient.connected()) {
|
||||
reconnect();
|
||||
|
||||
if (useethernet){
|
||||
if (!mqttClient.connected()) {
|
||||
reconnect();
|
||||
}
|
||||
mqttClient.loop();
|
||||
}
|
||||
mqttClient.loop();
|
||||
|
||||
|
||||
|
||||
|
@ -272,6 +297,15 @@ void loop() {
|
|||
button_flag=false; //clear flag to reenable button triggering.
|
||||
}
|
||||
|
||||
for(uint8_t i=0;i<leds.numPixels();i++){ //set color of all leds
|
||||
leds.setPixelColor(i, Wheel(wheelpos+i*10));
|
||||
}
|
||||
wheelpos+=5;
|
||||
|
||||
leds.show();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -341,3 +375,17 @@ void srWrite(uint8_t pin, boolean state){
|
|||
boolean srRead(uint8_t pin){
|
||||
return (srbits >> pin) & 1U;
|
||||
}
|
||||
|
||||
|
||||
uint32_t Wheel(byte WheelPos) {
|
||||
WheelPos = 255 - WheelPos;
|
||||
if(WheelPos < 85) {
|
||||
return leds.Color(255 - WheelPos * 3, 0, WheelPos * 3);
|
||||
}
|
||||
if(WheelPos < 170) {
|
||||
WheelPos -= 85;
|
||||
return leds.Color(0, WheelPos * 3, 255 - WheelPos * 3);
|
||||
}
|
||||
WheelPos -= 170;
|
||||
return leds.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Loading…
Reference in New Issue