From 4bee3e6286b364b480f9eef702de50849089dcc7 Mon Sep 17 00:00:00 2001 From: Fisch Date: Sun, 15 Jul 2018 17:26:07 +0200 Subject: [PATCH] add effect flash --- achterbahn.ino | 11 +++- .../achterbahnconfig/achterbahnconfig.pde | 7 +++ fx_flash.cpp | 59 +++++++++++++++++++ fx_flash.h | 25 ++++++++ 4 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 fx_flash.cpp create mode 100644 fx_flash.h diff --git a/achterbahn.ino b/achterbahn.ino index 306bce0..9d3a63a 100644 --- a/achterbahn.ino +++ b/achterbahn.ino @@ -9,6 +9,7 @@ #include "wagon.h" #include "effect.h" #include "fx_scanner.h" +#include "fx_flash.h" #define PIN D2 #define NUMPIXELS 600 @@ -378,12 +379,18 @@ void checkSerial(){ }else{ Serial.println("Error: Value too high!"); } - }else if (serialstring.equals("fx_scanner")){ + }else if (serialstring.startsWith("fx_")){ Serial.println("Effect Scanner"); if (effect!=NULL){ delete effect; } - effect=new FX_Scanner(NUMPIXELS,&strip,height,255,-200,strip.Color(100,0,0)); + if (serialstring.equals("fx_scanner")){ + Serial.println("Effect Scanner"); + effect=new FX_Scanner(NUMPIXELS,&strip,height,255,-200,strip.Color(100,0,0)); + }else if (serialstring.equals("fx_flash")){ + Serial.println("Effect Flash"); + effect=new FX_Flash(NUMPIXELS,&strip,strip.Color(200,200,200)); + } } } diff --git a/achterbahnconfig/achterbahnconfig/achterbahnconfig.pde b/achterbahnconfig/achterbahnconfig/achterbahnconfig.pde index cfc2d71..078bfda 100644 --- a/achterbahnconfig/achterbahnconfig/achterbahnconfig.pde +++ b/achterbahnconfig/achterbahnconfig/achterbahnconfig.pde @@ -139,6 +139,9 @@ void setup() { cp5.addButton("FX_Scanner") .setPosition(200, 200) .setSize(100, 20); + cp5.addButton("FX_Flash") + .setPosition(200, 220) + .setSize(100, 20); myPort = new Serial(this, "/dev/ttyUSB0", 115200); @@ -186,6 +189,10 @@ void FX_Scanner() { String writeserial="fx_scanner\n"; myPort.write(writeserial); } +void FX_Flash() { + String writeserial="fx_flash\n"; + myPort.write(writeserial); +} diff --git a/fx_flash.cpp b/fx_flash.cpp new file mode 100644 index 0000000..74ef012 --- /dev/null +++ b/fx_flash.cpp @@ -0,0 +1,59 @@ +#include "fx_flash.h" +#include "effect.h" + +#define FLASHTIME 10 //in ms + +FX_Flash::FX_Flash(int numpixels,Adafruit_NeoPixel *strip,uint32_t flashcolor) +{ + _numpixels=numpixels; + _strip=strip; + _flashcolor=flashcolor; + _starttime=millis(); +} + +FX_Flash::FX_Flash() +{ +} + +void FX_Flash::updateRoutine(float updatedelayms) +{ +} + +void FX_Flash::updateGraphics() +{ + for(int i=0;i<_numpixels;i++){ + + uint8_t _r = _flashcolor >> 16; + uint8_t _g = _flashcolor >> 8; + uint8_t _b = _flashcolor; + + + uint32_t _pxcolor=_strip->getPixelColor(i); //get current color of that pixel + uint8_t _pxr = _pxcolor >> 16; + uint8_t _pxg = _pxcolor >> 8; + uint8_t _pxb = _pxcolor; + uint16_t _tmpr=_pxr+_r; //add colors + uint16_t _tmpg=_pxg+_g; + uint16_t _tmpb=_pxb+_b; + if (_tmpr>255){ //clamp + _tmpr=255; + } + if (_tmpg>255){ + _tmpg=255; + } + if (_tmpb>255){ + _tmpb=255; + } + _strip->setPixelColor(i,_tmpr,_tmpg,_tmpb); //draw pixel + + } +} + +bool FX_Flash::active() +{ + if (millis()-_starttime>FLASHTIME){ + return false; + } + return true; +} + diff --git a/fx_flash.h b/fx_flash.h new file mode 100644 index 0000000..95162ee --- /dev/null +++ b/fx_flash.h @@ -0,0 +1,25 @@ +#ifndef FX_FLASH_H +#define FX_FLASH_H +#include +#include +#include "effect.h" + +class FX_Flash : public Effect +{ + public: + FX_Flash(int numpixels,Adafruit_NeoPixel *strip,uint32_t flashcolor); + FX_Flash(); + void updateRoutine(float updatedelayms); + void updateGraphics(); + uint32_t Wheel(byte WheelPos,float brightness); + bool active(); + private: + int _numpixels; + Adafruit_NeoPixel *_strip; + uint32_t _flashcolor; + long _starttime; +}; + +#endif + +