add effect flash

This commit is contained in:
interfisch 2018-07-15 17:26:07 +02:00
parent 12acffc57c
commit 4bee3e6286
4 changed files with 100 additions and 2 deletions

View File

@ -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));
}
}
}

View File

@ -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);
}

59
fx_flash.cpp Normal file
View File

@ -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;
}

25
fx_flash.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef FX_FLASH_H
#define FX_FLASH_H
#include <Adafruit_NeoPixel.h>
#include <math.h>
#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