diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dcc0a31 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +backup/ \ No newline at end of file diff --git a/achterbahn.ino b/achterbahn.ino index 2328bb5..16f87cd 100644 --- a/achterbahn.ino +++ b/achterbahn.ino @@ -5,6 +5,9 @@ #include #endif +#include +#define EEPROMSTARTADDRESS_HEIGHTMAP 8 + #include #include "wagon.h" #include "effect.h" @@ -57,6 +60,8 @@ Effect* effect = NULL; void setup() { Serial.begin(115200); + EEPROM.begin(4096); //set eeprom size, between 4 and 4096 bytes. + strip.begin(); strip.setBrightness(BRIGHTNESS_RUN); //150 strip.show(); // Initialize all pixels to 'off' @@ -65,46 +70,7 @@ void setup() { resetHeightmap(); //fixed heightmap -heightraw[0]=182; -heightraw[51]=100; -heightraw[91]=57; -heightraw[121]=100; -heightraw[147]=100; -heightraw[170]=75; -heightraw[184]=71; -heightraw[216]=100; -heightraw[228]=103; -heightraw[257]=101; -heightraw[305]=107; -heightraw[316]=100; -heightraw[349]=78; -heightraw[386]=100; -heightraw[420]=83; -heightraw[438]=78; -heightraw[460]=83; -heightraw[489]=95; -heightraw[515]=92; -heightraw[566]=100; -heightraw[580]=103; -heightraw[599]=89; - - - - - - - - - - - - - - - - - - + loadHeightmapRaw(); interpolateHeightValues(); @@ -312,6 +278,10 @@ void checkSerial(){ configmode=true; }else if (serialstring.equals("print")){ printHeightmapRaw(); + }else if (serialstring.equals("save")){ + saveHeightmapRaw(); //save to eeprom + }else if (serialstring.equals("load")){ + loadHeightmapRaw(); //load from eeprom }else if (serialstring.equals("remove")){ removeAllWagons(); }else if (serialstring.equals("clear")){ @@ -553,3 +523,25 @@ uint32_t Wheel(byte WheelPos) { WheelPos -= 170; return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); } + + + +void loadHeightmapRaw(){ + int c_eepromaddress=EEPROMSTARTADDRESS_HEIGHTMAP; + uint8_t lastvalue=0; + for (int i=0;i> 16; - uint8_t _g = _scannercolor >> 8; - uint8_t _b = _scannercolor; - - float distmult=1.0-(heightdistfromlaser/FEATHERDISTANCE); - _r*=distmult; - _g*=distmult; - _b*=distmult; - - 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_Scanner::active() -{ - if (_pos>256 || _pos<0){ - return false; - } - return true; -} - -uint32_t FX_Scanner::Wheel(byte WheelPos,float brightness) { - WheelPos = 255 - WheelPos; - if(WheelPos < 85) { - return _strip->Color(255 - WheelPos * 3*brightness, 0, WheelPos * 3*brightness); - } - if(WheelPos < 170) { - WheelPos -= 85; - return _strip->Color(0, WheelPos * 3*brightness, 255 - WheelPos * 3*brightness); - } - WheelPos -= 170; - return _strip->Color(WheelPos * 3*brightness, 255 - WheelPos * 3*brightness, 0); -} diff --git a/backup/fx_scanner (Kopie 1).h b/backup/fx_scanner (Kopie 1).h deleted file mode 100644 index bdf6aa7..0000000 --- a/backup/fx_scanner (Kopie 1).h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef FX_SCANNER_H -#define FX_SCANNER_H -#include -#include - -class FX_Scanner -{ - public: - FX_Scanner(int numpixels,Adafruit_NeoPixel *strip,uint8_t *height,int startpos,float scannervel,uint32_t scannercolor); - FX_Scanner(); - void updateRoutine(float updatedelayms); - void updateGraphics(); - uint32_t Wheel(byte WheelPos,float brightness); - bool active(); - private: - int _numpixels; - Adafruit_NeoPixel *_strip; - float _pos; - float _vel; - uint8_t *_height; - uint32_t _scannercolor; -}; - -#endif - -