├── TikiCannon ├── Constants.h ├── IProgram.h ├── TestColorEffect.cpp ├── SolidColorEffect.cpp ├── RainbowEffect.h ├── TestColorEffect.h ├── SolidColorEffect.h ├── CannonBallEffect.h ├── TikiCannon.sln ├── RunningColorEffect.h ├── RunningColorEffect.cpp ├── CannonBallEffect.cpp ├── RainbowEffect.cpp ├── Visual Micro │ ├── .TikiCannon.vsarduino.h │ ├── Configuration.Debug.vmps.xml │ ├── Compile.vmps.xml │ └── Upload.vmps.xml ├── TikiCannon.vcxproj.filters ├── TikiCannon.ino └── TikiCannon.vcxproj ├── .gitattributes ├── TikiTank ├── Constants.h ├── TikiTank.sln ├── RainbowEffect.h ├── SolidColorEffect.h ├── StrobeEffect.h ├── View.h ├── AutoThreadEffect.h ├── EffectRotator.cpp ├── EffectRotator.h ├── ThreadEffect.h ├── TestColorEffect.h ├── IProgram.h ├── SolidColorEffect.cpp ├── Controller.h ├── StrobeEffect.cpp ├── AutoThreadEffect.cpp ├── TestColorEffect.cpp ├── View.cpp ├── RainbowEffect.cpp ├── Visual Micro │ ├── .TikiTank.vsarduino.h │ ├── Configuration.Debug.vmps.xml │ ├── Compile.vmps.xml │ └── Upload.vmps.xml ├── ThreadEffect.cpp ├── TikiTank.ino ├── TikiTank.vcxproj.filters ├── Controller.cpp └── TikiTank.vcxproj ├── TikiSpeedSensor ├── TikiSpeedSensor.sln ├── Visual Micro │ ├── .TikiSpeedSensor.vsarduino.h │ ├── Configuration.Debug.vmps.xml │ ├── Upload.vmps.xml │ └── Compile.vmps.xml ├── TikiSpeedSensor.vcxproj.filters ├── TikiSpeedSensor.ino └── TikiSpeedSensor.vcxproj ├── README.md └── .gitignore /TikiCannon/Constants.h: -------------------------------------------------------------------------------- 1 | #ifndef _CONSTANTS_h 2 | #define _CONSTANTS_h 3 | 4 | #if defined(ARDUINO) && ARDUINO >= 100 5 | #include "Arduino.h" 6 | #else 7 | #include "WProgram.h" 8 | #endif 9 | 10 | // Bitmask for Trigger button 11 | #define BUTTON_TRIGGER 0x04 12 | // Bitmask for Mode button 13 | #define BUTTON_MODE 0x02 14 | // Bitmas for program button 15 | #define BUTTON_PROGRAM 0x01 16 | 17 | // Number or color modes 18 | #define MAX_COLOR_MODE_COUNT 9 19 | 20 | #endif 21 | 22 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /TikiCannon/IProgram.h: -------------------------------------------------------------------------------- 1 | #ifndef IProgram_h 2 | #define IProgram_h 3 | 4 | /** 5 | IProgram is an interface that represents any program (effect) for the Cannon 6 | 7 | Every effect needs to implement this interface in order to be executable 8 | */ 9 | class IProgram 10 | { 11 | public: 12 | // Initialization of the program 13 | virtual void init() = 0; 14 | // Perform ONE effect step - this method is periodically called every cycle of main program 15 | virtual void step() = 0; 16 | // Get number of modes that program suports 17 | virtual byte getModeCount() = 0; 18 | // Set active mode for the program 19 | virtual void setMode(byte mode) = 0; 20 | }; 21 | 22 | #endif -------------------------------------------------------------------------------- /TikiTank/Constants.h: -------------------------------------------------------------------------------- 1 | #ifndef _CONSTANTS_h 2 | #define _CONSTANTS_h 3 | 4 | #if defined(ARDUINO) && ARDUINO >= 100 5 | #include "Arduino.h" 6 | #else 7 | #include "WProgram.h" 8 | #endif 9 | 10 | /** 11 | LCD backlight colors 12 | */ 13 | #define RED 0x1 14 | #define YELLOW 0x3 15 | #define GREEN 0x2 16 | #define TEAL 0x6 17 | #define BLUE 0x4 18 | #define VIOLET 0x5 19 | #define WHITE 0x7 20 | 21 | // Number or color modes 22 | #define MAX_COLOR_MODE_COUNT 9 23 | 24 | // Maximum length of the string for the display item 25 | #define LABEL_LENGTH 10 26 | 27 | const byte DIRECTION_STOP = 0; 28 | const byte DIRECTION_FORWARD = 1; 29 | const byte DIRECTION_BACKWARD = 2; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /TikiCannon/TestColorEffect.cpp: -------------------------------------------------------------------------------- 1 | #include "TestColorEffect.h" 2 | 3 | 4 | /** 5 | Constructor 6 | 7 | @param ledStrip pointer to LED strip controlling class 8 | @param clrs pointer to array of colors for color modes 9 | */ 10 | TestColorEffect::TestColorEffect(LPD8806 *ledStrip, uint32_t *clrs) 11 | { 12 | strip = ledStrip; 13 | colors = clrs; 14 | activeMode = 0; 15 | } 16 | 17 | void TestColorEffect::init() 18 | { 19 | strip->solidColor(colors[activeMode]); 20 | } 21 | 22 | void TestColorEffect::step() 23 | { 24 | strip->show(); 25 | delay(10); 26 | } 27 | 28 | void TestColorEffect::setMode(byte mode) 29 | { 30 | if (mode >= 0 && mode < MAX_COLOR_MODE_COUNT) 31 | { 32 | activeMode = mode; 33 | init(); 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /TikiCannon/SolidColorEffect.cpp: -------------------------------------------------------------------------------- 1 | #include "SolidColorEffect.h" 2 | 3 | /** 4 | Constructor 5 | 6 | @param ledStrip pointer to LED strip controlling class 7 | @param clrs pointer to array of colors for color modes 8 | */ 9 | SolidColorEffect::SolidColorEffect(LPD8806 *ledStrip, uint32_t *clrs) 10 | { 11 | strip = ledStrip; 12 | colors = clrs; 13 | 14 | argument = 0; 15 | direction = 1; 16 | } 17 | 18 | void SolidColorEffect::init() 19 | { 20 | strip->solidColor(colors[argument]); 21 | } 22 | 23 | void SolidColorEffect::step() 24 | { 25 | init(); 26 | argument += direction; 27 | strip->show(); 28 | delay(100); 29 | 30 | if (argument >= MAX_COLOR_MODE_COUNT) 31 | { 32 | direction=-1; 33 | } 34 | else if (argument <= 0) 35 | { 36 | direction=1; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /TikiCannon/RainbowEffect.h: -------------------------------------------------------------------------------- 1 | // RainbowEffect.h 2 | 3 | #ifndef _RAINBOWEFFECT_h 4 | #define _RAINBOWEFFECT_h 5 | 6 | #if defined(ARDUINO) && ARDUINO >= 100 7 | #include "Arduino.h" 8 | #else 9 | #include "WProgram.h" 10 | #endif 11 | 12 | #include 13 | #include "IProgram.h" 14 | #include "Constants.h" 15 | 16 | /** 17 | Rainbow Effect 18 | 19 | Program displays runnin rainbow on the tank cannon 20 | */ 21 | class RainbowEffect : public IProgram 22 | { 23 | public: 24 | RainbowEffect(LPD8806 *ledStrip); 25 | virtual void init(); 26 | virtual void step(); 27 | virtual byte getModeCount() { return 0; } 28 | virtual void setMode(byte mode) { return; } 29 | private: 30 | uint32_t wheel(uint16_t WheelPos); 31 | LPD8806 * strip; 32 | short counter; 33 | }; 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /TikiCannon/TestColorEffect.h: -------------------------------------------------------------------------------- 1 | #ifndef _TESTCOLOREFFECT_h 2 | #define _TESTCOLOREFFECT_h 3 | 4 | #if defined(ARDUINO) && ARDUINO >= 100 5 | #include "Arduino.h" 6 | #else 7 | #include "WProgram.h" 8 | #endif 9 | 10 | #include 11 | #include "IProgram.h" 12 | #include "Constants.h" 13 | 14 | /** 15 | Test Color Effect 16 | 17 | Program changes color of the LED strip based on user input 18 | */ 19 | class TestColorEffect : public IProgram 20 | { 21 | public: 22 | TestColorEffect(LPD8806 *ledStrip, uint32_t *clrs); 23 | virtual void init(); 24 | virtual void step(); 25 | virtual byte getModeCount() { return MAX_COLOR_MODE_COUNT; } 26 | virtual void setMode(byte mode); 27 | private: 28 | LPD8806 * strip; 29 | int activeMode; 30 | 31 | uint32_t *colors; 32 | }; 33 | 34 | #endif 35 | 36 | -------------------------------------------------------------------------------- /TikiCannon/SolidColorEffect.h: -------------------------------------------------------------------------------- 1 | #ifndef _SOLIDCOLOREFFECT_h 2 | #define _SOLIDCOLOREFFECT_h 3 | 4 | #if defined(ARDUINO) && ARDUINO >= 100 5 | #include "Arduino.h" 6 | #else 7 | #include "WProgram.h" 8 | #endif 9 | 10 | #include 11 | #include "IProgram.h" 12 | #include "Constants.h" 13 | 14 | /** 15 | Solid Color Effect 16 | 17 | Program periodically changes color of the LED strip 18 | */ 19 | class SolidColorEffect : public IProgram 20 | { 21 | public: 22 | SolidColorEffect(LPD8806 *ledStrip, uint32_t *clrs); 23 | virtual void init(); 24 | virtual void step(); 25 | virtual byte getModeCount() { return 0; } 26 | virtual void setMode(byte mode) { return; } 27 | private: 28 | LPD8806 *strip; 29 | int argument; 30 | short direction; 31 | 32 | uint32_t *colors; 33 | }; 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /TikiCannon/CannonBallEffect.h: -------------------------------------------------------------------------------- 1 | // CannonBallEffect.h 2 | 3 | #ifndef _CANNONBALLEFFECT_h 4 | #define _CANNONBALLEFFECT_h 5 | 6 | #if defined(ARDUINO) && ARDUINO >= 100 7 | #include "Arduino.h" 8 | #else 9 | #include "WProgram.h" 10 | #endif 11 | 12 | #include 13 | #include "IProgram.h" 14 | #include "Constants.h" 15 | 16 | /** 17 | Cannon Ball Effect 18 | 19 | Program for cannon shot and explosion effect 20 | */ 21 | class CannonBallEffect : public IProgram 22 | { 23 | public: 24 | CannonBallEffect(LPD8806 *ledStrip); 25 | virtual void init(); 26 | virtual void step(); 27 | virtual byte getModeCount() { return 0; } 28 | virtual void setMode(byte mode) { return; } 29 | private: 30 | uint32_t wheel(uint16_t WheelPos); 31 | LPD8806 * strip; 32 | short counter; 33 | }; 34 | 35 | 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /TikiTank/TikiTank.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TikiTank", "TikiTank.vcxproj", "{C3574ADD-879F-4082-9C1F-8C433CB597B7}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {C3574ADD-879F-4082-9C1F-8C433CB597B7}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {C3574ADD-879F-4082-9C1F-8C433CB597B7}.Debug|Win32.Build.0 = Debug|Win32 14 | {C3574ADD-879F-4082-9C1F-8C433CB597B7}.Release|Win32.ActiveCfg = Release|Win32 15 | {C3574ADD-879F-4082-9C1F-8C433CB597B7}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /TikiCannon/TikiCannon.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TikiCannon", "TikiCannon.vcxproj", "{0779EE18-868D-4F1D-94DD-9D40FA6A6644}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {0779EE18-868D-4F1D-94DD-9D40FA6A6644}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {0779EE18-868D-4F1D-94DD-9D40FA6A6644}.Debug|Win32.Build.0 = Debug|Win32 14 | {0779EE18-868D-4F1D-94DD-9D40FA6A6644}.Release|Win32.ActiveCfg = Release|Win32 15 | {0779EE18-868D-4F1D-94DD-9D40FA6A6644}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /TikiSpeedSensor/TikiSpeedSensor.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TikiSpeedSensor", "TikiSpeedSensor.vcxproj", "{4C2A8C1D-DD92-4F85-ACC2-2C391886EAEF}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {4C2A8C1D-DD92-4F85-ACC2-2C391886EAEF}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {4C2A8C1D-DD92-4F85-ACC2-2C391886EAEF}.Debug|Win32.Build.0 = Debug|Win32 14 | {4C2A8C1D-DD92-4F85-ACC2-2C391886EAEF}.Release|Win32.ActiveCfg = Release|Win32 15 | {4C2A8C1D-DD92-4F85-ACC2-2C391886EAEF}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /TikiSpeedSensor/Visual Micro/.TikiSpeedSensor.vsarduino.h: -------------------------------------------------------------------------------- 1 | #ifndef _VSARDUINO_H_ 2 | #define _VSARDUINO_H_ 3 | //Board = Arduino Uno 4 | #define __AVR_ATmega328P__ 5 | #define ARDUINO 105 6 | #define __AVR__ 7 | #define F_CPU 16000000L 8 | #define __cplusplus 9 | #define __attribute__(x) 10 | #define __inline__ 11 | #define __asm__(x) 12 | #define __extension__ 13 | #define __ATTR_PURE__ 14 | #define __ATTR_CONST__ 15 | #define __inline__ 16 | #define __asm__ 17 | #define __volatile__ 18 | #define __builtin_va_list 19 | #define __builtin_va_start 20 | #define __builtin_va_end 21 | #define __DOXYGEN__ 22 | #define prog_void 23 | #define PGM_VOID_P int 24 | #define NOINLINE __attribute__((noinline)) 25 | 26 | typedef unsigned char byte; 27 | extern "C" void __cxa_pure_virtual() {;} 28 | 29 | // 30 | // 31 | void interruptHandler(); 32 | 33 | #include "c:\Program Files (x86)\arduino-1.0.5\hardware\arduino\variants\standard\pins_arduino.h" 34 | #include "c:\Program Files (x86)\arduino-1.0.5\hardware\arduino\cores\arduino\arduino.h" 35 | #include "D:\Home\Documents\Arduino\TikiSpeedSensor\TikiSpeedSensor.ino" 36 | #endif 37 | -------------------------------------------------------------------------------- /TikiCannon/RunningColorEffect.h: -------------------------------------------------------------------------------- 1 | // RunningColorEffect.h 2 | 3 | #ifndef _RUNNINGCOLOREFFECT_h 4 | #define _RUNNINGCOLOREFFECT_h 5 | 6 | #if defined(ARDUINO) && ARDUINO >= 100 7 | #include "Arduino.h" 8 | #else 9 | #include "WProgram.h" 10 | #endif 11 | 12 | #include 13 | #include "IProgram.h" 14 | #include "Constants.h" 15 | 16 | /** 17 | Running Color Effect 18 | 19 | Program displays running solid color light on the tank cannon 20 | */ 21 | class RunningColorEffect : public IProgram 22 | { 23 | public: 24 | RunningColorEffect(LPD8806 *ledStrip, uint32_t *clrs, bool automatic); 25 | virtual void init(); 26 | virtual void step(); 27 | virtual int getRotationPeriod() { return 3000; } 28 | virtual byte getModeCount() { return MAX_COLOR_MODE_COUNT; } 29 | virtual void setMode(byte mode); 30 | private: 31 | void internalInit(); 32 | void changeModeColor(); 33 | LPD8806 *strip; 34 | byte activeMode; 35 | short position; 36 | byte sleepDelay; 37 | short cnt; 38 | bool cleaning; 39 | bool autoMode; 40 | 41 | uint32_t activeColor; 42 | uint32_t *colors; 43 | }; 44 | 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /TikiSpeedSensor/TikiSpeedSensor.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Header Files 23 | 24 | 25 | -------------------------------------------------------------------------------- /TikiTank/RainbowEffect.h: -------------------------------------------------------------------------------- 1 | // RainbowEffect.h 2 | 3 | #ifndef _RAINBOWEFFECT_h 4 | #define _RAINBOWEFFECT_h 5 | 6 | #if defined(ARDUINO) && ARDUINO >= 100 7 | #include "Arduino.h" 8 | #else 9 | #include "WProgram.h" 10 | #endif 11 | 12 | #include 13 | #include "IProgram.h" 14 | #include "Constants.h" 15 | 16 | /** 17 | Rainbow Effect 18 | 19 | Program displays rotating rainbow on the tank thread 20 | */ 21 | class RainbowEffect : public IProgram 22 | { 23 | public: 24 | RainbowEffect(char name[], LPD8806 *ledStrip); 25 | virtual void init(); 26 | virtual void step(); 27 | virtual bool isInterruptDriven() { return false; } 28 | virtual void setArgument(short arg) { return; } 29 | virtual void getArgumentText(char *output); 30 | virtual void getName(char *programName); 31 | virtual int getArgumentMin() { return 0; } 32 | virtual int getArgumentMax() { return 0; } 33 | virtual int getRotationPeriod() { return 3000; } 34 | virtual byte getModeCount() { return 0; } 35 | virtual void setMode(byte mode) { return; } 36 | private: 37 | uint32_t wheel(uint16_t WheelPos); 38 | LPD8806 * strip; 39 | char name[LABEL_LENGTH]; 40 | short counter; 41 | }; 42 | 43 | #endif 44 | 45 | -------------------------------------------------------------------------------- /TikiTank/SolidColorEffect.h: -------------------------------------------------------------------------------- 1 | #ifndef _SOLIDCOLOREFFECT_h 2 | #define _SOLIDCOLOREFFECT_h 3 | 4 | #if defined(ARDUINO) && ARDUINO >= 100 5 | #include "Arduino.h" 6 | #else 7 | #include "WProgram.h" 8 | #endif 9 | 10 | #include 11 | #include "IProgram.h" 12 | #include "Constants.h" 13 | 14 | /** 15 | Solid Color Effect 16 | 17 | Program periodically changes color of the LED strip 18 | */ 19 | class SolidColorEffect : public IProgram 20 | { 21 | public: 22 | SolidColorEffect(char name[], LPD8806 *ledStrip, uint32_t *clrs); 23 | virtual void init(); 24 | virtual void step(); 25 | virtual bool isInterruptDriven() { return false; } 26 | virtual void setArgument(short arg); 27 | virtual void getArgumentText(char *output); 28 | virtual void getName(char *programName); 29 | virtual int getArgumentMin() { return 0; } 30 | virtual int getArgumentMax() { return 0; } 31 | virtual int getRotationPeriod() { return 3000; } 32 | virtual byte getModeCount() { return 0; } 33 | virtual void setMode(byte mode) { return; } 34 | private: 35 | LPD8806 * strip; 36 | char name[LABEL_LENGTH]; 37 | short argument; 38 | short direction; 39 | 40 | uint32_t *colors; 41 | }; 42 | 43 | #endif 44 | 45 | -------------------------------------------------------------------------------- /TikiTank/StrobeEffect.h: -------------------------------------------------------------------------------- 1 | #ifndef _STROBEEFFECT_h 2 | #define _STROBEEFFECT_h 3 | 4 | #if defined(ARDUINO) && ARDUINO >= 100 5 | #include "Arduino.h" 6 | #else 7 | #include "WProgram.h" 8 | #endif 9 | 10 | #include 11 | #include "IProgram.h" 12 | #include "Constants.h" 13 | 14 | /** 15 | Strobe Effect 16 | 17 | Ummmm, I guess this is a strobe effect 18 | */ 19 | class StrobeEffect : public IProgram 20 | { 21 | public: 22 | StrobeEffect(char programName[], LPD8806 *ledStrip, uint32_t *clrs); 23 | virtual void init(); 24 | virtual void step(); 25 | virtual bool isInterruptDriven() { return false; } 26 | virtual void setArgument(short arg); 27 | virtual void getArgumentText(char *output); 28 | virtual void getName(char *programName); 29 | virtual int getArgumentMin() { return 0; } 30 | virtual int getArgumentMax() { return 1; } 31 | virtual int getRotationPeriod() { return 1500; } 32 | virtual byte getModeCount() { return MAX_COLOR_MODE_COUNT; } 33 | virtual void setMode(byte mode); 34 | 35 | private: 36 | LPD8806 * strip; 37 | char name[LABEL_LENGTH]; 38 | byte activeMode; 39 | short argument; 40 | byte speed; 41 | boolean lightSwitch; 42 | 43 | uint32_t *colors; 44 | }; 45 | 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /TikiTank/View.h: -------------------------------------------------------------------------------- 1 | #ifndef VIEW_h 2 | #define VIEW_h 3 | 4 | #if defined(ARDUINO) && ARDUINO >= 100 5 | #include "Arduino.h" 6 | #else 7 | #include "WProgram.h" 8 | #endif 9 | 10 | #include 11 | #include "Constants.h" 12 | 13 | /* 14 | View class is an abstraction layer for LCD and button hardware, 15 | */ 16 | class View 17 | { 18 | public: 19 | // Constructor 20 | View(); 21 | // Initialization of the LCD 22 | void init(); 23 | // Display given string as active menu item 24 | void setMenuItem(char *name); 25 | // Display given string as active program 26 | void setProgram(char *name); 27 | // Display given string as a active program argument 28 | void setArgument(char *arg); 29 | // Blink the display as warning/error 30 | void errorBlink(); 31 | // Read status of the hardware buttons 32 | uint8_t readLCDButtons(); 33 | 34 | int argument; 35 | 36 | private: 37 | // Redraw menu items 38 | void updateMenu(); 39 | // Redraw statu bar with active program and argument 40 | void updateStatusBar(); 41 | 42 | 43 | byte backlightColor; 44 | char menuItem[LABEL_LENGTH]; 45 | char programName[LABEL_LENGTH]; 46 | char argStr[LABEL_LENGTH]; 47 | 48 | Adafruit_RGBLCDShield lcd; 49 | }; 50 | 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /TikiTank/AutoThreadEffect.h: -------------------------------------------------------------------------------- 1 | // AutoThreadEffect.h 2 | 3 | #ifndef _AUTOTHREADEFFECT_h 4 | #define _AUTOTHREADEFFECT_h 5 | 6 | #if defined(ARDUINO) && ARDUINO >= 100 7 | #include "Arduino.h" 8 | #else 9 | #include "WProgram.h" 10 | #endif 11 | 12 | #include 13 | #include "IProgram.h" 14 | #include "Constants.h" 15 | 16 | /** 17 | Auto Thread Effect 18 | 19 | Program to control tank thread effect based on the data from speed sensor 20 | */ 21 | class AutoThreadEffect : public IProgram 22 | { 23 | public: 24 | AutoThreadEffect(char name[], LPD8806 *ledStrip, uint32_t *clrs); 25 | virtual void init(); 26 | virtual void step(); 27 | virtual bool isInterruptDriven() { return true; } 28 | virtual void setArgument(short arg); 29 | virtual void getArgumentText(char *output); 30 | virtual void getName(char *programName); 31 | virtual int getArgumentMin() { return 0; } 32 | virtual int getArgumentMax() { return 1; } 33 | virtual int getRotationPeriod() { return 0; } 34 | virtual byte getModeCount() { return MAX_COLOR_MODE_COUNT; } 35 | virtual void setMode(byte mode); 36 | private: 37 | LPD8806 * strip; 38 | char name[LABEL_LENGTH]; 39 | short argument; 40 | byte activeMode; 41 | byte direction; 42 | 43 | uint32_t *colors; 44 | }; 45 | 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /TikiTank/EffectRotator.cpp: -------------------------------------------------------------------------------- 1 | #include "EffectRotator.h" 2 | 3 | /** 4 | Constructor 5 | 6 | @param programName name of the program that will appear on the display 7 | @param pprograms[] array of programs for rotation 8 | @param prgCount number of programs in the array 9 | */ 10 | EffectRotator::EffectRotator(char programName[], IProgram *pprograms[], byte prgCount) 11 | { 12 | strncpy(name, programName, sizeof(name)); 13 | programs = pprograms; 14 | programCount = prgCount; 15 | effect = 0; 16 | } 17 | 18 | void EffectRotator::init() 19 | { 20 | startTime = millis(); 21 | 22 | while(programs[effect]->getRotationPeriod() == 0 ) 23 | { 24 | effect++; 25 | if (effect >= programCount) 26 | effect = 0; 27 | } 28 | 29 | programs[effect]->init(); 30 | } 31 | 32 | 33 | void EffectRotator::step() 34 | { 35 | if ((millis() - startTime) < programs[effect]->getRotationPeriod()) 36 | { 37 | programs[effect]->step(); 38 | } 39 | else 40 | { 41 | effect++; 42 | init(); 43 | } 44 | } 45 | 46 | 47 | void EffectRotator::getArgumentText(char *output) 48 | { 49 | char outstr[LABEL_LENGTH] = ""; 50 | strncpy(output, outstr, sizeof(outstr)); 51 | } 52 | 53 | void EffectRotator::getName(char *programName) 54 | { 55 | strncpy(programName, name, sizeof(name)); 56 | } 57 | 58 | 59 | -------------------------------------------------------------------------------- /TikiTank/EffectRotator.h: -------------------------------------------------------------------------------- 1 | // EffectRotator.h 2 | 3 | #ifndef _EFFECTROTATOR_h 4 | #define _EFFECTROTATOR_h 5 | 6 | #if defined(ARDUINO) && ARDUINO >= 100 7 | #include "Arduino.h" 8 | #else 9 | #include "WProgram.h" 10 | #endif 11 | 12 | #include 13 | #include "IProgram.h" 14 | #include "Constants.h" 15 | 16 | /** 17 | Effect Rotator 18 | 19 | Program that periodically executes other effect 20 | */ 21 | class EffectRotator : public IProgram 22 | { 23 | public: 24 | EffectRotator(char programName[], IProgram *pprograms[], byte max_program_number); 25 | virtual void init(); 26 | virtual void step(); 27 | virtual bool isInterruptDriven() { return false; } 28 | virtual void setArgument(short arg) { return; } 29 | virtual void getArgumentText(char *output); 30 | virtual void getName(char *programName); 31 | virtual int getArgumentMin() { return 0; } 32 | virtual int getArgumentMax() { return 0; } 33 | virtual int getRotationPeriod() { return 0; } 34 | virtual byte getModeCount() { return 0; } 35 | virtual void setMode(byte mode) { return; } 36 | private: 37 | char name[LABEL_LENGTH]; 38 | int argument; 39 | //byte speed; 40 | byte effect; 41 | byte programCount; 42 | unsigned long startTime; 43 | unsigned long elapsedTime; 44 | 45 | IProgram** programs; 46 | }; 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /TikiTank/ThreadEffect.h: -------------------------------------------------------------------------------- 1 | // ThreadEffect.h 2 | 3 | #ifndef _THREADEFFECT_h 4 | #define _THREADEFFECT_h 5 | 6 | #if defined(ARDUINO) && ARDUINO >= 100 7 | #include "Arduino.h" 8 | #else 9 | #include "WProgram.h" 10 | #endif 11 | 12 | #include 13 | #include "IProgram.h" 14 | #include "Constants.h" 15 | 16 | /** 17 | Thread Effect 18 | 19 | Program to control tank thread effect based on the user input (manual mode) 20 | */ 21 | class ThreadEffect : public IProgram 22 | { 23 | public: 24 | ThreadEffect(char name[], int minArg, int maxArg, LPD8806 *ledStrip, uint32_t *clrs); 25 | virtual void init(); 26 | virtual void step(); 27 | virtual bool isInterruptDriven() { return false; } 28 | virtual void setArgument(short arg); 29 | virtual void getArgumentText(char *output); 30 | virtual void getName(char *programName); 31 | virtual int getArgumentMin() { return argMin; } 32 | virtual int getArgumentMax() { return argMax; } 33 | virtual int getRotationPeriod() { return 0; } 34 | virtual byte getModeCount() { return MAX_COLOR_MODE_COUNT; } 35 | virtual void setMode(byte mode); 36 | private: 37 | LPD8806 * strip; 38 | char name[LABEL_LENGTH]; 39 | short pause; 40 | short argMax; 41 | short argMin; 42 | short argument; 43 | byte activeMode; 44 | byte direction; 45 | 46 | uint32_t *colors; 47 | }; 48 | 49 | #endif -------------------------------------------------------------------------------- /TikiTank/TestColorEffect.h: -------------------------------------------------------------------------------- 1 | // TestColorEffect.h 2 | 3 | #ifndef _TESTCOLOREFFECT_h 4 | #define _TESTCOLOREFFECT_h 5 | 6 | #if defined(ARDUINO) && ARDUINO >= 100 7 | #include "Arduino.h" 8 | #else 9 | #include "WProgram.h" 10 | #endif 11 | 12 | #include 13 | #include "IProgram.h" 14 | #include "Constants.h" 15 | 16 | #define MAX_SOLID_COLOR_COUNT 9 17 | 18 | struct Color { 19 | int32_t color; 20 | char name[LABEL_LENGTH]; 21 | }; 22 | 23 | /** 24 | Test Color Effect 25 | 26 | Program changes color of the LED strip based on user input 27 | */ 28 | class TestColorEffect : public IProgram 29 | { 30 | public: 31 | TestColorEffect(char name[], LPD8806 *ledStrip); 32 | virtual void init(); 33 | virtual void step(); 34 | virtual bool isInterruptDriven() { return false; } 35 | virtual void setArgument(short arg); 36 | virtual void getArgumentText(char *output); 37 | virtual void getName(char *programName); 38 | virtual int getArgumentMin() { return 0; } 39 | virtual int getArgumentMax() { return MAX_SOLID_COLOR_COUNT-1; } 40 | virtual int getRotationPeriod() { return 0; } 41 | virtual byte getModeCount() { return 0; } 42 | virtual void setMode(byte mode) { return; } 43 | private: 44 | LPD8806 * strip; 45 | char name[LABEL_LENGTH]; 46 | short argument; 47 | 48 | Color colors[MAX_SOLID_COLOR_COUNT]; 49 | }; 50 | 51 | #endif 52 | 53 | -------------------------------------------------------------------------------- /TikiTank/IProgram.h: -------------------------------------------------------------------------------- 1 | #ifndef IProgram_h 2 | #define IProgram_h 3 | 4 | /** 5 | IProgram is an interface that represents any program (effect) for the Tank. 6 | 7 | Every effect needs to implement this interface in order to be executable by 8 | the Controller class. 9 | */ 10 | class IProgram 11 | { 12 | public: 13 | // Initialization of the program 14 | virtual void init() = 0; 15 | // Perform ONE effect step - this method is periodically called every cycle of main program 16 | virtual void step() = 0; 17 | // Returns name of the program 18 | virtual void getName(char *programName) = 0; 19 | 20 | // Returns true if program is dependent on the speed sensor data 21 | virtual bool isInterruptDriven() = 0; 22 | // Set argument value for the program 23 | virtual void setArgument(short argument) = 0; 24 | // Get textual meaning of the current argument 25 | virtual void getArgumentText(char *output) = 0; 26 | // Get minimal argument value that program supports 27 | virtual int getArgumentMin() = 0; 28 | // Get maximal argument value that program supports 29 | virtual int getArgumentMax() = 0; 30 | 31 | // Get number of modes that program suports 32 | virtual byte getModeCount() = 0; 33 | // Set active mode for the program 34 | virtual void setMode(byte mode) = 0; 35 | 36 | // Returns minimal execution time in miliseconds for FX rotator 37 | // 0 -> means program is not suitable for FX rotation 38 | virtual int getRotationPeriod() = 0; 39 | }; 40 | 41 | #endif -------------------------------------------------------------------------------- /TikiTank/SolidColorEffect.cpp: -------------------------------------------------------------------------------- 1 | #include "SolidColorEffect.h" 2 | 3 | /** 4 | Constructor 5 | 6 | @param programName name of the program that will appear on the display 7 | @param ledStrip pointer to LED strip controlling class 8 | @param clrs pointer to array of colors for color modes 9 | */ 10 | SolidColorEffect::SolidColorEffect(char programName[], LPD8806 *ledStrip, uint32_t *clrs) 11 | { 12 | strncpy(name, programName, sizeof(name)); 13 | strip = ledStrip; 14 | colors = clrs; 15 | 16 | argument = 0; 17 | direction = 1; 18 | } 19 | 20 | void SolidColorEffect::init() 21 | { 22 | strip->solidColor(colors[argument]); 23 | } 24 | 25 | void SolidColorEffect::step() 26 | { 27 | init(); 28 | argument += direction; 29 | strip->show(); 30 | delay(100); 31 | 32 | if (argument >= MAX_COLOR_MODE_COUNT) 33 | { 34 | direction=-1; 35 | } 36 | else if (argument <= 0) 37 | { 38 | direction=1; 39 | } 40 | } 41 | 42 | void SolidColorEffect::setArgument(short arg) 43 | { 44 | argument = arg; 45 | // sanity check 46 | if (argument < 0) 47 | argument = 0; 48 | else if (argument >= MAX_COLOR_MODE_COUNT) 49 | argument = MAX_COLOR_MODE_COUNT-1; 50 | 51 | init(); 52 | } 53 | 54 | void SolidColorEffect::getArgumentText(char *output) 55 | { 56 | char outstr[LABEL_LENGTH] = ""; 57 | strncpy(output, outstr, sizeof(outstr)); 58 | } 59 | 60 | void SolidColorEffect::getName(char *programName) 61 | { 62 | strncpy(programName, name, sizeof(name)); 63 | } 64 | 65 | 66 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Tiki Tank 2 | ========= 3 | 4 | Source repository for [Tiki Tank](http://www.tikitank.com) mutant vehicle and related software projects 5 | 6 | What the hell is Tiki Tank? 7 | --------------------------- 8 | 9 | Tiki Tank is *mutant vehicle* created as a technological art piece, that demonstrates symbiosis of mechanical, electrotechnical and computer engineering blended with unique design into a DIY masterpiece. 10 | 11 | Ok, cut the crap! It is an art car for Burning Man, that's it.... 12 | 13 | 14 | What's inside? 15 | -------------- 16 | 17 | The repository contains three Arduino projects written in C++. Each project can be opened and compiled in Arduino IDE. However, Visual Studio 2012 with [Arduino extensions](http://www.visualmicro.com/) is recommended as a best way to edit and compile the source code. 18 | 19 | **TikiTank** is firmware for Teensy++ 2.0 unit that controls the tank thread effects 20 | 21 | **TikiCannon** is firmware for ATmega328 that controls the tank cannon effect 22 | 23 | **TikiSpeesSensor** is firmware for ATmega328 that controls the HAL sensor and sends speed information to the main unit 24 | 25 | 26 | ### Dependencies ### 27 | 28 | - Arduino >= 1.00 29 | - [LPD8806 LED strip library for Tiki Tank](https://github.com/pbansky/LPD8806) 30 | - [Adafruit RGB LCD Shield Library](Adafruit-RGB-LCD-Shield-Library) 31 | - [Teensyduino add-in for arduino](https://www.pjrc.com/teensy/teensyduino.html) 32 | 33 | 34 | Hardware 35 | -------- 36 | 37 | The whole project requires two Arduino Uno (ATmega328/ATmega168) and one Teensy++ 2.0 38 | 39 | 40 | More information 41 | ---------------- 42 | 43 | For more information visit [http://www.tikitank.com](http://www.tikitank.com) -------------------------------------------------------------------------------- /TikiTank/Controller.h: -------------------------------------------------------------------------------- 1 | #if defined(ARDUINO) && ARDUINO >= 100 2 | #include "Arduino.h" 3 | #else 4 | #include "WProgram.h" 5 | #endif 6 | 7 | #include "IProgram.h" 8 | #include "View.h" 9 | 10 | const byte STATE_IDLE = 1; // Auto program is in idle mode (screen saver) 11 | const byte STATE_RUNNING = 0; // Auto program is running 12 | 13 | /* 14 | Controller class is the main class that process inputs from user and sensors, 15 | in order to changes the light effect and its behavior. 16 | 17 | Controller class contains array of effects and is responsible for effect switching 18 | based on outside events. 19 | */ 20 | class Controller 21 | { 22 | public: 23 | // Constructor 24 | Controller(IProgram *pprograms[], byte prgCount, byte idleIndex, long idleTout, View *pview); 25 | // Initialization of inputs and outputs 26 | void init(); 27 | // Main method to process all the events 28 | void processEvents(); 29 | private: 30 | // Process events based on the serial data 31 | void processEvents(byte serialData); 32 | // Set given program (effect) as active 33 | void setProgram(byte program); 34 | // Change mode of the current program 35 | void changeMode(); 36 | // Display given menu item 37 | void setMenuItem(byte index); 38 | // Set program argument value 39 | void setArgument(int arg); 40 | // Process button events 41 | void processButtons(); 42 | 43 | byte menuPosition; 44 | byte activeProgram; 45 | byte programCount; 46 | byte activeMode; 47 | 48 | bool buttonsPressed; 49 | 50 | int programArg; 51 | int argMax; 52 | int argMin; 53 | 54 | unsigned long tickTimeout; 55 | volatile byte state; 56 | volatile long idleTimeout; 57 | byte idleProgram; 58 | 59 | HardwareSerial Uart; 60 | IProgram** programs; 61 | View *view; 62 | }; 63 | 64 | 65 | -------------------------------------------------------------------------------- /TikiCannon/RunningColorEffect.cpp: -------------------------------------------------------------------------------- 1 | #include "RunningColorEffect.h" 2 | 3 | /** 4 | Constructor 5 | 6 | @param ledStrip pointer to LED strip controlling class 7 | @param clrs pointer to array of colors for color modes 8 | @param automatic automatic color mode change 9 | */ 10 | RunningColorEffect::RunningColorEffect(LPD8806 *ledStrip, uint32_t *clrs, bool automatic) 11 | { 12 | strip = ledStrip; 13 | colors = clrs; 14 | activeMode = 0; 15 | autoMode = automatic; 16 | cleaning = false; 17 | } 18 | 19 | void RunningColorEffect::init() 20 | { 21 | strip->solidColor(strip->Color(0, 0, 0)); 22 | strip->show(); 23 | internalInit(); 24 | } 25 | 26 | void RunningColorEffect::internalInit() 27 | { 28 | if (cleaning) 29 | { 30 | activeColor = strip->Color(0, 0, 0); 31 | if (autoMode) 32 | changeModeColor(); 33 | } 34 | else 35 | activeColor = colors[activeMode]; 36 | 37 | position = 0; 38 | cnt = 0; 39 | sleepDelay = 12; 40 | } 41 | 42 | void RunningColorEffect::step() 43 | { 44 | strip->setPixelColor(position, activeColor); 45 | strip->show(); 46 | 47 | cnt++; 48 | if (cnt > (strip->numPixels() / 3)) 49 | { 50 | cnt=0; 51 | sleepDelay /= 2; 52 | } 53 | 54 | if (sleepDelay <=0) sleepDelay = 1; 55 | delay(sleepDelay); 56 | 57 | position++; 58 | 59 | // clean after end 60 | if (position > strip->numPixels()) 61 | { 62 | cleaning = (cleaning) ? false : true; 63 | 64 | internalInit(); 65 | } 66 | } 67 | 68 | void RunningColorEffect::setMode(byte mode) 69 | { 70 | if (mode >= 0 && mode < getModeCount()) 71 | { 72 | activeMode = mode; 73 | init(); 74 | } 75 | } 76 | 77 | void RunningColorEffect::changeModeColor() 78 | { 79 | activeMode++; 80 | if (activeMode >= getModeCount()) 81 | { 82 | activeMode = 0; 83 | } 84 | } 85 | 86 | 87 | -------------------------------------------------------------------------------- /TikiTank/StrobeEffect.cpp: -------------------------------------------------------------------------------- 1 | #include "StrobeEffect.h" 2 | 3 | /** 4 | Constructor 5 | 6 | @param programName name of the program that will appear on the display 7 | @param ledStrip pointer to LED strip controlling class 8 | @param clrs pointer to array of colors for color modes 9 | */ 10 | StrobeEffect::StrobeEffect(char programName[], LPD8806 *ledStrip, uint32_t *clrs) 11 | { 12 | strncpy(name, programName, sizeof(name)); 13 | strip = ledStrip; 14 | colors = clrs; 15 | 16 | activeMode = 0; 17 | argument = 0; 18 | speed = 5; 19 | lightSwitch = true; 20 | } 21 | 22 | void StrobeEffect::init() 23 | { 24 | strip->solidColor(colors[activeMode]); 25 | 26 | strip->show(); 27 | } 28 | 29 | void StrobeEffect::step() 30 | { 31 | uint32_t color; 32 | if (lightSwitch) 33 | { 34 | delay(speed); 35 | color = strip->Color(0, 0, 0); 36 | lightSwitch = false; 37 | } 38 | else 39 | { 40 | delay(speed*3); 41 | color = colors[activeMode]; 42 | lightSwitch = true; 43 | } 44 | 45 | strip->solidColor(color); 46 | 47 | strip->show(); 48 | } 49 | 50 | void StrobeEffect::setMode(byte mode) 51 | { 52 | if (mode >= 0 && mode < MAX_COLOR_MODE_COUNT) 53 | { 54 | activeMode = mode; 55 | init(); 56 | } 57 | } 58 | 59 | void StrobeEffect::setArgument(short arg) 60 | { 61 | argument = arg; 62 | if (argument == 0) 63 | speed = 20; 64 | else 65 | speed = 25; 66 | } 67 | 68 | void StrobeEffect::getArgumentText(char *output) 69 | { 70 | char outstr[LABEL_LENGTH] = ""; 71 | 72 | if (argument == 0) 73 | strcat(outstr, "Fast"); 74 | else 75 | strcat(outstr, "Slow"); 76 | 77 | strncpy(output, outstr, sizeof(outstr)); 78 | } 79 | 80 | void StrobeEffect::getName(char *programName) 81 | { 82 | strncpy(programName, name, sizeof(name)); 83 | } 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /TikiCannon/CannonBallEffect.cpp: -------------------------------------------------------------------------------- 1 | #include "CannonBallEffect.h" 2 | 3 | /** 4 | Constructor 5 | 6 | @param ledStrip pointer to LED strip controlling class 7 | */ 8 | CannonBallEffect::CannonBallEffect(LPD8806 *ledStrip) 9 | { 10 | strip = ledStrip; 11 | } 12 | 13 | void CannonBallEffect::init() 14 | { 15 | strip->solidColor(strip->Color(0, 0, 0)); 16 | strip->show(); 17 | } 18 | 19 | void CannonBallEffect::step() 20 | { 21 | // Cannon ball 22 | byte cnt = 0; 23 | int sleepDelay; 24 | 25 | for(int j=0; j <= 4; j++) 26 | { 27 | sleepDelay = 12 - (j*2); 28 | for(int i=0; i <= strip->numPixels(); i++) 29 | { 30 | strip->setPixelColor(i, strip->Color(0, 32+i, 32+i)); 31 | strip->show(); 32 | 33 | cnt++; 34 | if (cnt > (strip->numPixels() / 3)) 35 | { 36 | cnt=0; 37 | sleepDelay /= 2; 38 | } 39 | 40 | if (sleepDelay <=0) sleepDelay = 1; 41 | delay(sleepDelay); 42 | } 43 | 44 | strip->solidColor(strip->Color(0, 0, 0)); 45 | strip->show(); 46 | } 47 | 48 | // blast 49 | for(int i=0; i < 1; i++) 50 | { 51 | strip->solidColor(strip->Color(64, 0, 0)); // Dark red 52 | strip->show(); 53 | delay(40); 54 | strip->solidColor(strip->Color(127, 0, 0)); // Red 55 | strip->show(); 56 | delay(40); 57 | strip->solidColor(strip->Color(127, 64, 0)); // Orange 58 | strip->show(); 59 | delay(40); 60 | strip->solidColor(strip->Color(127, 127, 0)); // Yellow 61 | strip->show(); 62 | delay(40); 63 | strip->solidColor(strip->Color(127, 127, 64)); // Warm white 64 | strip->show(); 65 | delay(40); 66 | strip->solidColor(strip->Color(127, 127, 127)); // White 67 | strip->show(); 68 | delay(40); 69 | } 70 | delay(260); 71 | 72 | 73 | // pause after blast 74 | strip->solidColor(strip->Color(0, 0, 0)); 75 | strip->show(); 76 | //delay(200); 77 | } 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /TikiCannon/RainbowEffect.cpp: -------------------------------------------------------------------------------- 1 | #include "RainbowEffect.h" 2 | 3 | /** 4 | Constructor 5 | 6 | @param ledStrip pointer to LED strip controlling class 7 | */ 8 | RainbowEffect::RainbowEffect(LPD8806 *ledStrip) 9 | { 10 | strip = ledStrip; 11 | } 12 | 13 | void RainbowEffect::init() 14 | { 15 | counter = 0; 16 | } 17 | 18 | void RainbowEffect::step() 19 | { 20 | uint16_t i; 21 | 22 | for (i=0; i < strip->numPixels(); i++) { 23 | // tricky math! we use each pixel as a fraction of the full 384-color 24 | // wheel (thats the i / strip.numPixels() part) 25 | // Then add in j which makes the colors go around per pixel 26 | // the % 384 is to make the wheel cycle around 27 | strip->setPixelColor((strip->numPixels() -1)- i, wheel(((i * 384 / strip->numPixels()) + counter) % 384)); 28 | } 29 | strip->show(); // write all the pixels out 30 | 31 | //cycles of all 384 colors in the wheel 32 | counter = (counter < 384) ? counter+1 : 0; 33 | delay(1); 34 | } 35 | 36 | /* Helper functions */ 37 | 38 | //Input a value 0 to 384 to get a color value. 39 | //The colours are a transition r - g - b - back to r 40 | 41 | uint32_t RainbowEffect::wheel(uint16_t WheelPos) 42 | { 43 | byte r, g, b; 44 | switch(WheelPos / 128) 45 | { 46 | case 0: 47 | r = 127 - WheelPos % 128; // red down 48 | g = WheelPos % 128; // green up 49 | b = 0; // blue off 50 | break; 51 | case 1: 52 | g = 127 - WheelPos % 128; // green down 53 | b = WheelPos % 128; // blue up 54 | r = 0; // red off 55 | break; 56 | case 2: 57 | b = 127 - WheelPos % 128; // blue down 58 | r = WheelPos % 128; // red up 59 | g = 0; // green off 60 | break; 61 | } 62 | return(strip->Color(r,g,b)); 63 | } 64 | 65 | -------------------------------------------------------------------------------- /TikiTank/AutoThreadEffect.cpp: -------------------------------------------------------------------------------- 1 | #include "AutoThreadEffect.h" 2 | 3 | /** 4 | Constructor 5 | 6 | @param programName name of the program that will appear on the display 7 | @param ledStrip pointer to LED strip controlling class 8 | @param clrs pointer to array of colors for color modes 9 | */ 10 | AutoThreadEffect::AutoThreadEffect(char programName[], LPD8806 *ledStrip, uint32_t *clrs) 11 | { 12 | strncpy(name, programName, sizeof(name)); 13 | strip = ledStrip; 14 | colors = clrs; 15 | 16 | activeMode = 0; 17 | setArgument(0); 18 | } 19 | 20 | void AutoThreadEffect::init() 21 | { 22 | int32_t shortColor, longColor; 23 | 24 | shortColor = colors[activeMode]; 25 | longColor = strip->Color(0, 0, 0); 26 | 27 | // draw the tank thread pattern 28 | strip->drawThread(shortColor, longColor); 29 | 30 | strip->show(); 31 | } 32 | 33 | void AutoThreadEffect::step() 34 | { 35 | if (direction == DIRECTION_FORWARD) 36 | strip->rotateRight(); 37 | else if (direction == DIRECTION_BACKWARD) 38 | strip->rotateLeft(); 39 | 40 | strip->show(); 41 | } 42 | 43 | void AutoThreadEffect::setArgument(short arg) 44 | { 45 | argument = arg; 46 | if (argument == 0) 47 | { 48 | direction = DIRECTION_FORWARD; 49 | } 50 | else 51 | { 52 | direction = DIRECTION_BACKWARD; 53 | } 54 | } 55 | 56 | void AutoThreadEffect::setMode(byte mode) 57 | { 58 | if (mode >= 0 && mode < MAX_COLOR_MODE_COUNT) 59 | { 60 | activeMode = mode; 61 | init(); 62 | } 63 | } 64 | 65 | void AutoThreadEffect::getArgumentText(char *output) 66 | { 67 | char outstr[LABEL_LENGTH] = ""; 68 | 69 | if (argument == 0) 70 | strcat(outstr, "Forward"); 71 | else 72 | strcat(outstr, "Reverse"); 73 | 74 | strncpy(output, outstr, sizeof(outstr)); 75 | } 76 | 77 | void AutoThreadEffect::getName(char *programName) 78 | { 79 | strncpy(programName, name, sizeof(name)); 80 | } 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /TikiCannon/Visual Micro/.TikiCannon.vsarduino.h: -------------------------------------------------------------------------------- 1 | #ifndef _VSARDUINO_H_ 2 | #define _VSARDUINO_H_ 3 | //Board = Arduino Uno 4 | #define __AVR_ATmega328P__ 5 | #define ARDUINO 105 6 | #define __AVR__ 7 | #define F_CPU 16000000L 8 | #define __cplusplus 9 | #define __attribute__(x) 10 | #define __inline__ 11 | #define __asm__(x) 12 | #define __extension__ 13 | #define __ATTR_PURE__ 14 | #define __ATTR_CONST__ 15 | #define __inline__ 16 | #define __asm__ 17 | #define __volatile__ 18 | #define __builtin_va_list 19 | #define __builtin_va_start 20 | #define __builtin_va_end 21 | #define __DOXYGEN__ 22 | #define prog_void 23 | #define PGM_VOID_P int 24 | #define NOINLINE __attribute__((noinline)) 25 | 26 | typedef unsigned char byte; 27 | extern "C" void __cxa_pure_virtual() {;} 28 | 29 | // 30 | // 31 | void setProgram(byte program); 32 | uint8_t readButtons(); 33 | void changeProgram(); 34 | void changeMode(); 35 | 36 | #include "c:\Program Files (x86)\arduino-1.0.5\hardware\arduino\variants\standard\pins_arduino.h" 37 | #include "c:\Program Files (x86)\arduino-1.0.5\hardware\arduino\cores\arduino\arduino.h" 38 | #include "D:\Home\Documents\Arduino\TikiCannon\TikiCannon.ino" 39 | #include "D:\Home\Documents\Arduino\TikiCannon\CannonBallEffect.cpp" 40 | #include "D:\Home\Documents\Arduino\TikiCannon\CannonBallEffect.h" 41 | #include "D:\Home\Documents\Arduino\TikiCannon\Constants.h" 42 | #include "D:\Home\Documents\Arduino\TikiCannon\IProgram.h" 43 | #include "D:\Home\Documents\Arduino\TikiCannon\RainbowEffect.cpp" 44 | #include "D:\Home\Documents\Arduino\TikiCannon\RainbowEffect.h" 45 | #include "D:\Home\Documents\Arduino\TikiCannon\RunningColorEffect.cpp" 46 | #include "D:\Home\Documents\Arduino\TikiCannon\RunningColorEffect.h" 47 | #include "D:\Home\Documents\Arduino\TikiCannon\SolidColorEffect.cpp" 48 | #include "D:\Home\Documents\Arduino\TikiCannon\SolidColorEffect.h" 49 | #include "D:\Home\Documents\Arduino\TikiCannon\TestColorEffect.cpp" 50 | #include "D:\Home\Documents\Arduino\TikiCannon\TestColorEffect.h" 51 | #endif 52 | -------------------------------------------------------------------------------- /TikiTank/TestColorEffect.cpp: -------------------------------------------------------------------------------- 1 | #include "TestColorEffect.h" 2 | 3 | /** 4 | Constructor 5 | 6 | @param programName name of the program that will appear on the display 7 | @param ledStrip pointer to LED strip controlling class 8 | */ 9 | TestColorEffect::TestColorEffect(char programName[], LPD8806 *ledStrip) 10 | { 11 | strncpy(name, programName, sizeof(name)); 12 | strip = ledStrip; 13 | 14 | strcpy(colors[0].name, "Black"); colors[0].color = strip->Color(0, 0, 0); 15 | strcpy(colors[1].name, "Red"); colors[1].color = strip->Color(127, 0, 0); 16 | strcpy(colors[2].name, "Yellow"); colors[2].color = strip->Color(127, 127, 0); 17 | strcpy(colors[3].name, "Green"); colors[3].color = strip->Color(0, 127, 0); 18 | strcpy(colors[4].name, "Aqua"); colors[4].color = strip->Color(0, 127, 127); 19 | strcpy(colors[5].name, "Blue"); colors[5].color = strip->Color(0, 0, 127); 20 | strcpy(colors[6].name, "Purple"); colors[6].color = strip->Color(63, 0, 63); 21 | strcpy(colors[7].name, "Pink"); colors[7].color = strip->Color(127, 10, 73); 22 | strcpy(colors[8].name, "White"); colors[8].color = strip->Color(127, 127, 127); 23 | 24 | argument = 0; 25 | } 26 | 27 | void TestColorEffect::init() 28 | { 29 | for(int j=0; j < strip->numPixels()-1; j++ ) { 30 | strip->setPixelColor(j, colors[argument].color); 31 | } 32 | } 33 | 34 | void TestColorEffect::step() 35 | { 36 | strip->show(); 37 | delay(10); 38 | } 39 | 40 | void TestColorEffect::setArgument(short arg) 41 | { 42 | argument = arg; 43 | // sanity check 44 | if (argument < 0) 45 | argument = 0; 46 | else if (argument >= MAX_SOLID_COLOR_COUNT) 47 | argument = MAX_SOLID_COLOR_COUNT-1; 48 | 49 | init(); 50 | } 51 | 52 | void TestColorEffect::getArgumentText(char *output) 53 | { 54 | char outstr[LABEL_LENGTH] = ""; 55 | strcat(outstr, colors[argument].name); 56 | strncpy(output, outstr, sizeof(outstr)); 57 | } 58 | 59 | void TestColorEffect::getName(char *programName) 60 | { 61 | strncpy(programName, name, sizeof(name)); 62 | } 63 | -------------------------------------------------------------------------------- /TikiTank/View.cpp: -------------------------------------------------------------------------------- 1 | #include "View.h" 2 | 3 | /** 4 | Constructor 5 | */ 6 | View::View() 7 | { 8 | backlightColor = TEAL; 9 | } 10 | 11 | /** 12 | Initialization of the LCD display 13 | */ 14 | void View::init() 15 | { 16 | lcd = Adafruit_RGBLCDShield(); 17 | lcd.clear(); 18 | lcd.begin(16, 2); 19 | lcd.setBacklight(backlightColor); 20 | lcd.print("Starting..."); 21 | } 22 | 23 | /** 24 | Read status of the buttons 25 | 26 | @result bit field with state of each button 27 | */ 28 | uint8_t View::readLCDButtons() 29 | { 30 | return lcd.readButtons(); 31 | } 32 | 33 | /** 34 | Display given string as an active menu item 35 | 36 | @param name Caption of the menu item 37 | */ 38 | void View::setMenuItem(char *name) 39 | { 40 | strncpy(menuItem, name, sizeof(menuItem)); 41 | updateMenu(); 42 | } 43 | 44 | /** 45 | Display given string as an active program 46 | 47 | @param name Program name 48 | */ 49 | void View::setProgram(char *name) 50 | { 51 | strncpy(programName, name, sizeof(programName)); 52 | lcd.clear(); 53 | updateMenu(); 54 | updateStatusBar(); 55 | } 56 | 57 | /** 58 | Display given string as an argument 59 | 60 | @param arg argument value 61 | */ 62 | void View::setArgument(char *arg) 63 | { 64 | strncpy(argStr, arg, sizeof(argStr)); 65 | updateStatusBar(); 66 | } 67 | 68 | /** 69 | Blink the display to show error or warning 70 | */ 71 | void View::errorBlink() 72 | { 73 | lcd.setBacklight(YELLOW); 74 | delay(50); 75 | lcd.setBacklight(backlightColor); 76 | } 77 | 78 | /** 79 | Redraw menu items 80 | */ 81 | void View::updateMenu() 82 | { 83 | lcd.setCursor(0,1); 84 | lcd.print("[ "); 85 | lcd.print(menuItem); 86 | for(int i=0; i < (13 - strlen(menuItem)); i++) 87 | lcd.print(" "); 88 | lcd.print("]"); 89 | } 90 | 91 | /** 92 | Redraw statu bar with active program and argument 93 | */ 94 | void View::updateStatusBar() 95 | { 96 | lcd.setCursor(0,0); 97 | lcd.print(programName); 98 | 99 | lcd.setCursor(10, 0); 100 | lcd.print(" "); 101 | lcd.setCursor(16 - strlen(argStr), 0); 102 | lcd.print(argStr); 103 | } 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /TikiTank/RainbowEffect.cpp: -------------------------------------------------------------------------------- 1 | #include "RainbowEffect.h" 2 | 3 | /** 4 | Constructor 5 | 6 | @param programName name of the program that will appear on the display 7 | @param ledStrip pointer to LED strip controlling class 8 | */ 9 | RainbowEffect::RainbowEffect(char programName[], LPD8806 *ledStrip) 10 | { 11 | strncpy(name, programName, sizeof(name)); 12 | strip = ledStrip; 13 | } 14 | 15 | void RainbowEffect::init() 16 | { 17 | counter = 0; 18 | } 19 | 20 | void RainbowEffect::step() 21 | { 22 | uint16_t i; 23 | 24 | for (i=0; i < strip->numPixels(); i++) { 25 | // tricky math! we use each pixel as a fraction of the full 384-color 26 | // wheel (thats the i / strip.numPixels() part) 27 | // Then add in j which makes the colors go around per pixel 28 | // the % 384 is to make the wheel cycle around 29 | strip->setPixelColor(strip->numPixels() - i, wheel(((i * 384 / 30) + counter) % 384)); 30 | } 31 | strip->show(); // write all the pixels out 32 | 33 | //cycles of all 384 colors in the wheel 34 | counter = (counter < 384) ? counter+10 : 0; 35 | } 36 | 37 | /* Helper functions */ 38 | 39 | //Input a value 0 to 384 to get a color value. 40 | //The colours are a transition r - g - b - back to r 41 | 42 | uint32_t RainbowEffect::wheel(uint16_t WheelPos) 43 | { 44 | byte r, g, b; 45 | switch(WheelPos / 128) 46 | { 47 | case 0: 48 | r = 127 - WheelPos % 128; // red down 49 | g = WheelPos % 128; // green up 50 | b = 0; // blue off 51 | break; 52 | case 1: 53 | g = 127 - WheelPos % 128; // green down 54 | b = WheelPos % 128; // blue up 55 | r = 0; // red off 56 | break; 57 | case 2: 58 | b = 127 - WheelPos % 128; // blue down 59 | r = WheelPos % 128; // red up 60 | g = 0; // green off 61 | break; 62 | } 63 | return(strip->Color(r,g,b)); 64 | } 65 | 66 | void RainbowEffect::getArgumentText(char *output) 67 | { 68 | char outstr[LABEL_LENGTH] = ""; 69 | strncpy(output, outstr, sizeof(outstr)); 70 | } 71 | 72 | void RainbowEffect::getName(char *programName) 73 | { 74 | strncpy(programName, name, sizeof(name)); 75 | } 76 | -------------------------------------------------------------------------------- /TikiTank/Visual Micro/.TikiTank.vsarduino.h: -------------------------------------------------------------------------------- 1 | #ifndef _VSARDUINO_H_ 2 | #define _VSARDUINO_H_ 3 | //Board = Arduino Uno 4 | #define __AVR_ATmega328P__ 5 | #define ARDUINO 105 6 | #define __AVR__ 7 | #define F_CPU 16000000L 8 | #define __cplusplus 9 | #define __attribute__(x) 10 | #define __inline__ 11 | #define __asm__(x) 12 | #define __extension__ 13 | #define __ATTR_PURE__ 14 | #define __ATTR_CONST__ 15 | #define __inline__ 16 | #define __asm__ 17 | #define __volatile__ 18 | #define __builtin_va_list 19 | #define __builtin_va_start 20 | #define __builtin_va_end 21 | #define __DOXYGEN__ 22 | #define prog_void 23 | #define PGM_VOID_P int 24 | #define NOINLINE __attribute__((noinline)) 25 | 26 | typedef unsigned char byte; 27 | extern "C" void __cxa_pure_virtual() {;} 28 | 29 | // 30 | // 31 | 32 | #include "c:\Program Files (x86)\arduino-1.0.5\hardware\arduino\variants\standard\pins_arduino.h" 33 | #include "c:\Program Files (x86)\arduino-1.0.5\hardware\arduino\cores\arduino\arduino.h" 34 | #include "D:\Home\Documents\Arduino\TikiTank\TikiTank.ino" 35 | #include "D:\Home\Documents\Arduino\TikiTank\AutoThreadEffect.cpp" 36 | #include "D:\Home\Documents\Arduino\TikiTank\AutoThreadEffect.h" 37 | #include "D:\Home\Documents\Arduino\TikiTank\Constants.h" 38 | #include "D:\Home\Documents\Arduino\TikiTank\Controller.cpp" 39 | #include "D:\Home\Documents\Arduino\TikiTank\Controller.h" 40 | #include "D:\Home\Documents\Arduino\TikiTank\EffectRotator.cpp" 41 | #include "D:\Home\Documents\Arduino\TikiTank\EffectRotator.h" 42 | #include "D:\Home\Documents\Arduino\TikiTank\IProgram.h" 43 | #include "D:\Home\Documents\Arduino\TikiTank\RainbowEffect.cpp" 44 | #include "D:\Home\Documents\Arduino\TikiTank\RainbowEffect.h" 45 | #include "D:\Home\Documents\Arduino\TikiTank\SolidColorEffect.cpp" 46 | #include "D:\Home\Documents\Arduino\TikiTank\SolidColorEffect.h" 47 | #include "D:\Home\Documents\Arduino\TikiTank\StrobeEffect.cpp" 48 | #include "D:\Home\Documents\Arduino\TikiTank\StrobeEffect.h" 49 | #include "D:\Home\Documents\Arduino\TikiTank\TestColorEffect.cpp" 50 | #include "D:\Home\Documents\Arduino\TikiTank\TestColorEffect.h" 51 | #include "D:\Home\Documents\Arduino\TikiTank\ThreadEffect.cpp" 52 | #include "D:\Home\Documents\Arduino\TikiTank\ThreadEffect.h" 53 | #include "D:\Home\Documents\Arduino\TikiTank\View.cpp" 54 | #include "D:\Home\Documents\Arduino\TikiTank\View.h" 55 | #endif 56 | -------------------------------------------------------------------------------- /TikiCannon/TikiCannon.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | Header Files 41 | 42 | 43 | Header Files 44 | 45 | 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | Source Files 58 | 59 | 60 | Source Files 61 | 62 | 63 | -------------------------------------------------------------------------------- /TikiSpeedSensor/Visual Micro/Configuration.Debug.vmps.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TikiTank/ThreadEffect.cpp: -------------------------------------------------------------------------------- 1 | #include "ThreadEffect.h" 2 | 3 | /** 4 | Constructor 5 | 6 | @param programName name of the program that will appear on the display 7 | @param minArg minimum thread roration speed (negative number represents opossite direction) 8 | @param maxArg maximum thread rotation speed 9 | @param ledStrip pointer to LED strip controlling class 10 | @param clrs pointer to array of colors for color modes 11 | */ 12 | ThreadEffect::ThreadEffect(char programName[], int minArg, int maxArg, LPD8806 *ledStrip, uint32_t *clrs) 13 | { 14 | strncpy(name, programName, sizeof(name)); 15 | strip = ledStrip; 16 | colors = clrs; 17 | 18 | argMin = minArg; 19 | argMax = maxArg; 20 | 21 | activeMode = 0; 22 | setArgument(0); 23 | } 24 | 25 | void ThreadEffect::init() 26 | { 27 | int32_t shortColor, longColor; 28 | 29 | // mode 0 30 | shortColor = colors[activeMode]; 31 | longColor = strip->Color(0, 0, 0); 32 | 33 | // draw the tank thread pattern 34 | strip->drawThread(shortColor, longColor); 35 | 36 | strip->show(); 37 | } 38 | 39 | void ThreadEffect::step() 40 | { 41 | if (direction == DIRECTION_FORWARD) 42 | strip->rotateRight(); 43 | else if (direction == DIRECTION_BACKWARD) 44 | strip->rotateLeft(); 45 | 46 | if (direction != DIRECTION_STOP) 47 | { 48 | strip->show(); 49 | delay(pause); 50 | } 51 | } 52 | 53 | void ThreadEffect::setArgument(short arg) 54 | { 55 | argument = arg; 56 | if (argument == 0) 57 | { 58 | direction = DIRECTION_STOP; 59 | } 60 | else 61 | { 62 | if (argument > 0) 63 | direction = DIRECTION_FORWARD; 64 | else if (argument < 0) 65 | direction = DIRECTION_BACKWARD; 66 | 67 | pause = 60 / abs(argument); 68 | } 69 | } 70 | 71 | void ThreadEffect::setMode(byte mode) 72 | { 73 | if (mode >= 0 && mode < MAX_COLOR_MODE_COUNT) 74 | { 75 | activeMode = mode; 76 | init(); 77 | } 78 | } 79 | 80 | void ThreadEffect::getArgumentText(char *output) 81 | { 82 | char buf[8 * sizeof(int) + 1]; // Assumes 8-bit chars plus zero byte. 83 | char *str = &buf[sizeof(buf) - 1]; 84 | short n = abs(argument); 85 | 86 | *str = '\0'; 87 | 88 | do { 89 | int m = n; 90 | n /= 10; 91 | char c = m - 10 * n; 92 | *--str = c < 10 ? c + '0' : c + 'A' - 10; 93 | } while(n); 94 | 95 | char outstr[LABEL_LENGTH] = ""; 96 | if (argument < 0) 97 | strcat(outstr, "-"); 98 | 99 | strcat(outstr, str); 100 | strcat(outstr, " mph"); 101 | strncpy(output, outstr, sizeof(outstr)); 102 | } 103 | 104 | void ThreadEffect::getName(char *programName) 105 | { 106 | strncpy(programName, name, sizeof(name)); 107 | } 108 | 109 | -------------------------------------------------------------------------------- /TikiSpeedSensor/Visual Micro/Upload.vmps.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /TikiSpeedSensor/Visual Micro/Compile.vmps.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /TikiTank/TikiTank.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * Tiki Tank 1.0 3 | * http://www.tikitank.com/ 4 | * 5 | * This is the firmware for the main CPU that controls tank threads. 6 | * 7 | * Intended CPU: Teensy++ 2.0 8 | * 9 | */ 10 | #include "AutoThreadEffect.h" 11 | #include "EffectRotator.h" 12 | #include "RainbowEffect.h" 13 | #include "TestColorEffect.h" 14 | #include "StrobeEffect.h" 15 | #include "Constants.h" 16 | #include 17 | #include "SPI.h" 18 | #include 19 | #include 20 | #include 21 | #include "Controller.h" 22 | #include "View.h" 23 | #include "ThreadEffect.h" 24 | #include "SolidColorEffect.h" 25 | 26 | // Length of the LED strip for thread 27 | const int stripLength = (5 * 32)*3; 28 | // Number of programs (effects) 29 | const int programCount = 7; 30 | // Idle effect 31 | const byte idleEffect = 3; 32 | // Idle timeout 33 | const int idleTimeout = 60000; 34 | 35 | 36 | // Main array with programs (effects) 37 | IProgram *programs[programCount]; 38 | uint32_t colors[MAX_COLOR_MODE_COUNT]; 39 | 40 | LPD8806 strip = LPD8806(stripLength); 41 | AutoThreadEffect autoProgram = AutoThreadEffect("Auto", &strip, colors); 42 | ThreadEffect manualProgram = ThreadEffect("Manual", -10, 10, &strip, colors); 43 | 44 | SolidColorEffect solidColor = SolidColorEffect("Colors", &strip, colors); 45 | RainbowEffect rainbow = RainbowEffect("Rainbow", &strip); 46 | StrobeEffect strobe = StrobeEffect("Strobe", &strip, colors); 47 | 48 | TestColorEffect testColor = TestColorEffect("Test", &strip); 49 | EffectRotator effectRotator = EffectRotator("FX rotate", programs, programCount); 50 | 51 | View view = View(); 52 | Controller controller = Controller(programs, programCount, idleEffect, idleTimeout, &view); 53 | 54 | void setup() { 55 | strip.begin(); 56 | 57 | programs[0] = &autoProgram; 58 | programs[1] = &manualProgram; 59 | programs[2] = &effectRotator; 60 | programs[3] = &rainbow; 61 | programs[4] = &solidColor; 62 | programs[5] = &strobe; 63 | programs[6] = &testColor; 64 | 65 | colors[0] = strip.Color(127, 127, 127); // White 66 | colors[1] = strip.Color(127, 10, 73); // Pink 67 | colors[2] = strip.Color(63, 0, 63); // Purple 68 | colors[3] = strip.Color(0, 0, 127); // Blue 69 | colors[4] = strip.Color(0, 127, 127); // Aqua 70 | colors[5] = strip.Color(0, 127, 0); // Green 71 | colors[6] = strip.Color(127, 127, 0); // Yellow 72 | colors[7] = strip.Color(127, 0, 0); // Red 73 | colors[8] = strip.Color(64, 0, 0); // Dark red 74 | 75 | view.init(); 76 | 77 | // Wait for SensorDuino to initializem because the MOSI and CLK of Teensy are connected 78 | // Initialization sequence of SensorDuino sends some crap on SPI, causing the lights to be confused 79 | delay(4000); 80 | 81 | controller.init(); 82 | } 83 | 84 | void loop() 85 | { 86 | controller.processEvents(); 87 | } 88 | 89 | 90 | -------------------------------------------------------------------------------- /TikiSpeedSensor/TikiSpeedSensor.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * Tiki Tank Speed Sensor 1.0 3 | * http://www.tikitank.com/ 4 | * 5 | * This is the firmware for the speed sensor CPU that reads the HAL sensor values 6 | * 7 | * Intended CPU: ATMega 328 8 | * 9 | */ 10 | 11 | // Pin where the HAL sensor comparator is connected 12 | const int sensorPin = 3; 13 | // Pin for status LED pin 14 | const int ledPin = 7; 15 | // Pin for the analog input (speed coeficient) 16 | const int potPin = A2; 17 | // Timeout interval in milliseconds 18 | const int timeout = 1300; 19 | // Interval for sending data out to main CPU (milliseconds) 20 | const int sendFrequency = 150; 21 | 22 | // Shortest time between pulses (to prevent glitches and bouncing) 23 | const int minimumTickLength = 90; 24 | 25 | #define TICK_NONE 0 26 | #define TICK_FIRST 1 27 | #define TICK_REGULAR 2 28 | 29 | int coef = 330; 30 | volatile int outputInterval =0; 31 | volatile unsigned long tickTime = 0; 32 | volatile unsigned long watchdog = 0; 33 | unsigned long sendTimer = 0; 34 | volatile byte ticking = TICK_NONE; 35 | volatile short delta = 0; 36 | volatile short lastDelta = 0; 37 | volatile short avg = 0; 38 | volatile short deviation = 0; 39 | 40 | void setup() 41 | { 42 | Serial.begin(9600); 43 | pinMode(ledPin, OUTPUT); 44 | pinMode(sensorPin, INPUT); 45 | 46 | Serial.write((uint8_t)0); 47 | attachInterrupt(1, interruptHandler, RISING); 48 | } 49 | 50 | void loop() 51 | { 52 | // Reflectt sensot status to LED. This is visual control when adjusting the sensor sensitivity 53 | digitalWrite(ledPin, digitalRead(sensorPin)); 54 | 55 | // Read coeficient value from the analog input 56 | coef = map(analogRead(potPin), 0, 1023, 900, 1100); 57 | 58 | // Timeout check 59 | if ((millis() - watchdog) > timeout) 60 | { 61 | ticking = TICK_NONE; 62 | outputInterval = 0; // delta = lastDelta = 0; 63 | } 64 | 65 | // Send data out every "sendFrequency" 66 | if ((millis() - sendTimer) > sendFrequency) 67 | { 68 | Serial.write((uint8_t)outputInterval); 69 | sendTimer = millis(); 70 | } 71 | } 72 | 73 | void interruptHandler() 74 | { 75 | // First pulse => start measuring the time 76 | if (ticking == TICK_NONE) 77 | { 78 | tickTime = watchdog = millis(); 79 | ticking = TICK_FIRST; 80 | } 81 | // every other pulse do the measurement 82 | else 83 | { 84 | delta = millis() - tickTime; 85 | 86 | // if it's a first tick make a new last delta 87 | lastDelta = (lastDelta == 0) ? delta : lastDelta; 88 | avg = (delta+lastDelta)/2; 89 | deviation = delta * 0.25; 90 | 91 | // Interval must have a minimum length 92 | if (delta > minimumTickLength) 93 | { 94 | // Interval must be reasonably close to the previous interval 95 | if (abs(delta-avg) <= deviation || ticking == TICK_FIRST) 96 | 97 | tickTime = watchdog = millis(); 98 | lastDelta = delta; 99 | 100 | // This speed calculation formula is based on distance between LEDs on the strip 101 | outputInterval = ((float)delta / (float)coef) * 60; 102 | 103 | ticking = TICK_REGULAR; 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /TikiTank/TikiTank.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | Header Files 41 | 42 | 43 | Header Files 44 | 45 | 46 | Header Files 47 | 48 | 49 | Header Files 50 | 51 | 52 | Header Files 53 | 54 | 55 | Header Files 56 | 57 | 58 | 59 | 60 | Source Files 61 | 62 | 63 | Source Files 64 | 65 | 66 | Source Files 67 | 68 | 69 | Source Files 70 | 71 | 72 | Source Files 73 | 74 | 75 | Source Files 76 | 77 | 78 | Source Files 79 | 80 | 81 | Source Files 82 | 83 | 84 | Source Files 85 | 86 | 87 | -------------------------------------------------------------------------------- /TikiCannon/Visual Micro/Configuration.Debug.vmps.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TikiCannon/Visual Micro/Compile.vmps.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /TikiCannon/Visual Micro/Upload.vmps.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | -------------------------------------------------------------------------------- /TikiCannon/TikiCannon.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * Tiki Tank Cannon 1.0 3 | * http://www.tikitank.com/ 4 | * 5 | * This is the firmware for the CPU that controls tank cannon 6 | * 7 | * Intended CPU: ATMega 328 8 | * 9 | */ 10 | #include "RunningColorEffect.h" 11 | #include "CannonBallEffect.h" 12 | #include "RainbowEffect.h" 13 | #include "TestColorEffect.h" 14 | #include "SolidColorEffect.h" 15 | #include "SPI.h" 16 | #include 17 | #include "IProgram.h" 18 | 19 | // Number of LEDs in the LED strip 20 | const int stripLength = 77; 21 | 22 | // PIN for program change button 23 | const int programButton = 5; 24 | // PIN for mode change button 25 | const int modeButton = 6; 26 | // PIN for trigger button 27 | const int triggerButton = 7; 28 | 29 | uint32_t colors[MAX_COLOR_MODE_COUNT]; 30 | LPD8806 strip = LPD8806(stripLength); 31 | IProgram* mainProgram; 32 | 33 | byte activeProgram; 34 | byte activeMode; 35 | bool buttonsPressed; 36 | 37 | 38 | void setup() 39 | { 40 | pinMode(programButton, INPUT); 41 | pinMode(modeButton, INPUT); 42 | pinMode(triggerButton, INPUT); 43 | 44 | strip.begin(); 45 | 46 | activeProgram = 0; 47 | activeMode = 0; 48 | buttonsPressed = false; 49 | 50 | // Color modes 51 | colors[0] = strip.Color(127, 127, 127); // White 52 | colors[1] = strip.Color(127, 10, 73); // Pink 53 | colors[2] = strip.Color(63, 0, 63); // Purple 54 | colors[3] = strip.Color(0, 0, 127); // Blue 55 | colors[4] = strip.Color(0, 127, 127); // Aqua 56 | colors[5] = strip.Color(0, 127, 0); // Green 57 | colors[6] = strip.Color(127, 127, 0); // Yellow 58 | colors[7] = strip.Color(127, 0, 0); // Red 59 | colors[8] = strip.Color(64, 0, 0); // Dark red 60 | 61 | setProgram(activeProgram); 62 | } 63 | 64 | void loop() 65 | { 66 | // Step the effect 67 | mainProgram->step(); 68 | 69 | // Evaluate button state 70 | uint8_t buttons = readButtons(); 71 | 72 | if (buttons && !buttonsPressed) 73 | { 74 | if (buttons & BUTTON_PROGRAM) { 75 | changeProgram(); 76 | } 77 | else if (buttons & BUTTON_MODE) 78 | { 79 | changeMode(); 80 | } 81 | else if (buttons & BUTTON_TRIGGER) 82 | { 83 | // Do the trigger effect 84 | CannonBallEffect* ball = new CannonBallEffect(&strip); 85 | ball->init(); 86 | ball->step(); 87 | free(ball); 88 | // mainProgram->init(); 89 | } 90 | buttonsPressed = true; 91 | } 92 | else if (!buttons) 93 | { 94 | buttonsPressed = false; 95 | } 96 | } 97 | 98 | /** 99 | Instantiate appropriate effect class based on argument 100 | 101 | @param program program to instantiate 102 | */ 103 | void setProgram(byte program) 104 | { 105 | free(mainProgram); 106 | 107 | switch (program) 108 | { 109 | case 1: 110 | mainProgram = new RunningColorEffect(&strip, colors, false); 111 | break; 112 | case 2: 113 | mainProgram = new RunningColorEffect(&strip, colors, true); 114 | break; 115 | case 3: 116 | mainProgram = new TestColorEffect(&strip, colors); 117 | break; 118 | case 4: 119 | mainProgram = new SolidColorEffect(&strip, colors); 120 | break; 121 | default: 122 | activeProgram = 0; 123 | mainProgram = new RainbowEffect(&strip); 124 | break; 125 | } 126 | 127 | mainProgram->init(); 128 | } 129 | 130 | /** 131 | Read button state 132 | 133 | @result bitfield with the button states 134 | */ 135 | uint8_t readButtons() 136 | { 137 | uint8_t buttons = 0; 138 | buttons |= (digitalRead(programButton) == LOW) ? BUTTON_PROGRAM : 0; 139 | buttons |= (digitalRead(modeButton) == LOW) ? BUTTON_MODE : 0; 140 | buttons |= (digitalRead(triggerButton) == LOW) ? BUTTON_TRIGGER : 0; 141 | 142 | return buttons; 143 | } 144 | 145 | void changeProgram() 146 | { 147 | activeProgram++; 148 | setProgram(activeProgram); 149 | } 150 | 151 | void changeMode() 152 | { 153 | activeMode++; 154 | if (activeMode >= mainProgram->getModeCount()) 155 | { 156 | activeMode = 0; 157 | } 158 | 159 | mainProgram->setMode(activeMode); 160 | } 161 | 162 | -------------------------------------------------------------------------------- /TikiCannon/TikiCannon.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {0779EE18-868D-4F1D-94DD-9D40FA6A6644} 15 | TikiCannon 16 | 17 | 18 | 19 | Application 20 | true 21 | v110 22 | MultiByte 23 | 24 | 25 | Application 26 | false 27 | v110 28 | true 29 | MultiByte 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | Level3 45 | Disabled 46 | true 47 | c:\Program Files (x86)\arduino-1.0.5\hardware\arduino\cores\arduino;c:\Program Files (x86)\arduino-1.0.5\hardware\arduino\variants\standard;c:\Program Files (x86)\arduino-1.0.5\libraries\SPI;c:\Program Files (x86)\arduino-1.0.5\libraries\SPI\utility;D:\Home\Documents\Arduino\libraries\LPD8806;D:\Home\Documents\Arduino\libraries\LPD8806\utility;c:\program files (x86)\arduino-1.0.5\hardware\tools\avr\avr\include\;c:\program files (x86)\arduino-1.0.5\hardware\tools\avr\avr\include\avr\;c:\program files (x86)\arduino-1.0.5\hardware\tools\avr\avr\;c:\program files (x86)\arduino-1.0.5\hardware\tools\avr\lib\gcc\avr\4.3.2\include\;%(AdditionalIncludeDirectories) 48 | D:\Home\Documents\Arduino\TikiCannon\Visual Micro\.TikiCannon.vsarduino.h;%(ForcedIncludeFiles) 49 | true 50 | __AVR_ATmega328P__;ARDUINO=105;__AVR__;F_CPU=16000000L;__cplusplus;%(PreprocessorDefinitions) 51 | 52 | 53 | true 54 | 55 | 56 | 57 | 58 | Level3 59 | MaxSpeed 60 | true 61 | true 62 | true 63 | 64 | 65 | true 66 | true 67 | true 68 | 69 | 70 | 71 | 72 | CppCode 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | CppCode 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /TikiTank/Controller.cpp: -------------------------------------------------------------------------------- 1 | #include "Controller.h" 2 | 3 | /** 4 | Constructor 5 | 6 | @param pprograms[] pointer to array of programs 7 | @param prgCount count of programs in the array 8 | @param idleIndex index of the program to be run when system is in idle 9 | @param idleTout system idle timeout 10 | */ 11 | Controller::Controller(IProgram *pprograms[], byte prgCount, byte idleIndex, long idleTout, View *pview) 12 | { 13 | Uart = HardwareSerial(); 14 | programs = pprograms; 15 | view = pview; 16 | programCount = prgCount; 17 | idleTimeout = idleTout; 18 | idleProgram = idleIndex; 19 | 20 | menuPosition = 0; 21 | activeProgram = 0; 22 | activeMode = 0; 23 | programArg = 0; 24 | buttonsPressed = false; 25 | state = STATE_RUNNING; 26 | } 27 | 28 | /** 29 | Initialization of inputs and outputs 30 | */ 31 | void Controller::init() 32 | { 33 | Uart.begin(9600); 34 | setProgram(activeProgram); 35 | setMenuItem(menuPosition); 36 | } 37 | 38 | /** 39 | Process inputs and change outputs. 40 | 41 | Reads data from sensor on the serial port and pass it on for processing 42 | */ 43 | void Controller::processEvents() 44 | { 45 | // Data to be read from serial port 46 | byte serialData = 0; 47 | 48 | // Read serial data 49 | if (Uart.available() > 0) 50 | { 51 | serialData = Uart.read(); 52 | // clear other data in buffer so we always have fresh one 53 | Uart.clear(); 54 | } 55 | 56 | processEvents(serialData); 57 | } 58 | 59 | /** 60 | Process all events. 61 | 62 | Process speed sensor values, buttons and chnage effect appropriatelly 63 | 64 | @param serialData data from speed sensor 65 | */ 66 | void Controller::processEvents(byte serialData) 67 | { 68 | // If it's interrupt driven program, make sure you check timeout and step the right program 69 | if (programs[activeProgram]->isInterruptDriven()) 70 | { 71 | // Step regular program based on the speed in serial data 72 | if (state == STATE_RUNNING && serialData > 0) 73 | { 74 | programs[activeProgram]->step(); 75 | delay(serialData); 76 | tickTimeout = millis(); 77 | } 78 | 79 | // Initiatie idle program if the idle timeout is reached 80 | if (state == STATE_RUNNING && (millis() - tickTimeout) > idleTimeout) 81 | { 82 | state = STATE_IDLE; 83 | programs[idleProgram]->init(); 84 | } 85 | 86 | // Step idle program instead of normal program 87 | if (state == STATE_IDLE) 88 | { 89 | programs[idleProgram]->step(); 90 | } 91 | 92 | // Resume standard program if IDLE program is interrupted by serial data 93 | if (state == STATE_IDLE && serialData > 0) 94 | { 95 | programs[activeProgram]->init(); 96 | state = STATE_RUNNING; 97 | } 98 | 99 | } 100 | // otherwise step current program 101 | else 102 | { 103 | programs[activeProgram]->step(); 104 | } 105 | 106 | processButtons(); 107 | } 108 | 109 | /** 110 | Read buttons state and make necessary apply changes to the UI 111 | 112 | */ 113 | void Controller::processButtons() 114 | { 115 | uint8_t buttons = view->readLCDButtons(); 116 | 117 | if (buttons && !buttonsPressed) 118 | { 119 | // LEFT and RIGHT scroll through programs 120 | if (buttons & BUTTON_RIGHT) { 121 | if (menuPosition < programCount - 1) { 122 | menuPosition++; 123 | } 124 | else 125 | { 126 | menuPosition = 0; 127 | view->errorBlink(); 128 | } 129 | setMenuItem(menuPosition); 130 | } 131 | else if (buttons & BUTTON_LEFT) { 132 | if (menuPosition > 0) { 133 | menuPosition--; 134 | } 135 | else 136 | { 137 | menuPosition = programCount-1; 138 | view->errorBlink(); 139 | } 140 | setMenuItem(menuPosition); 141 | } 142 | // UP and DOWN changes active programs argument 143 | else if (buttons & BUTTON_UP) { 144 | if (programArg < argMax) 145 | { 146 | programArg++; 147 | setArgument(programArg); 148 | } 149 | else 150 | view->errorBlink(); 151 | } 152 | else if (buttons & BUTTON_DOWN) { 153 | if (programArg > argMin) 154 | { 155 | programArg--; 156 | setArgument(programArg); 157 | } 158 | else 159 | view->errorBlink(); 160 | } 161 | // Select activate new program or changes mode on existing one 162 | else if (buttons & BUTTON_SELECT) { 163 | if (menuPosition == activeProgram) 164 | changeMode(); 165 | else 166 | setProgram(menuPosition); 167 | } 168 | 169 | // This is to enforce "key press" instead of "key down" event 170 | buttonsPressed = true; 171 | } 172 | else if (!buttons) 173 | { 174 | buttonsPressed = false; 175 | } 176 | } 177 | 178 | /** 179 | Makes given program active 180 | 181 | @param program index of the program to be set active 182 | */ 183 | void Controller::setProgram(byte program) 184 | { 185 | // change program and set default argument 186 | activeProgram = program; 187 | programArg = 0; 188 | // Cancel IDLE mode if exists 189 | state = STATE_RUNNING; 190 | 191 | // get min and max args for input sanity check 192 | argMax = programs[activeProgram]->getArgumentMax(); 193 | argMin = programs[activeProgram]->getArgumentMin(); 194 | programs[activeProgram]->init(); 195 | 196 | // Display program name on the screen 197 | char name[LABEL_LENGTH]; 198 | programs[activeProgram]->getName(name); 199 | setArgument(programArg); 200 | view->setProgram(name); 201 | } 202 | 203 | /** 204 | Change mode of the active program 205 | 206 | Roates through the mode if the program is capable of it 207 | */ 208 | void Controller::changeMode() 209 | { 210 | activeMode++; 211 | if (activeMode >= programs[activeProgram]->getModeCount()) 212 | { 213 | activeMode = 0; 214 | } 215 | 216 | programs[activeProgram]->setMode(activeMode); 217 | } 218 | 219 | /** 220 | Display given program name as a menut item 221 | 222 | @param index program index 223 | */ 224 | void Controller::setMenuItem(byte index) 225 | { 226 | char name[LABEL_LENGTH]; 227 | programs[index]->getName(name); 228 | view->setMenuItem(name); 229 | } 230 | 231 | /** 232 | Set argument for active program 233 | 234 | @param arg argument value 235 | */ 236 | void Controller::setArgument(int arg) 237 | { 238 | // set the argument 239 | programArg = arg; 240 | programs[activeProgram]->setArgument(arg); 241 | 242 | // Get human textual meaning for argument and dislay it 243 | char name[LABEL_LENGTH]; 244 | programs[activeProgram]->getArgumentText(name); 245 | view->setArgument(name); 246 | } 247 | -------------------------------------------------------------------------------- /TikiSpeedSensor/TikiSpeedSensor.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {4C2A8C1D-DD92-4F85-ACC2-2C391886EAEF} 15 | TikiSpeedSensor 16 | 17 | 18 | 19 | Application 20 | true 21 | v110 22 | MultiByte 23 | 24 | 25 | Application 26 | false 27 | v110 28 | true 29 | MultiByte 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | Level3 45 | Disabled 46 | true 47 | c:\Program Files (x86)\arduino-1.0.5\hardware\arduino\cores\arduino;c:\Program Files (x86)\arduino-1.0.5\hardware\arduino\variants\standard;c:\program files (x86)\arduino-1.0.5\hardware\tools\avr\avr\include\;c:\program files (x86)\arduino-1.0.5\hardware\tools\avr\avr\include\avr\;c:\program files (x86)\arduino-1.0.5\hardware\tools\avr\avr\;c:\program files (x86)\arduino-1.0.5\hardware\tools\avr\lib\gcc\avr\4.3.2\include\;%(AdditionalIncludeDirectories) 48 | D:\Home\Documents\Arduino\TikiSpeedSensor\Visual Micro\.TikiSpeedSensor.vsarduino.h;%(ForcedIncludeFiles) 49 | true 50 | __AVR_ATmega328P__;ARDUINO=105;__AVR__;F_CPU=16000000L;__cplusplus;%(PreprocessorDefinitions) 51 | 52 | 53 | true 54 | 55 | 56 | 57 | 58 | Level3 59 | MaxSpeed 60 | true 61 | true 62 | true 63 | 64 | 65 | true 66 | true 67 | true 68 | 69 | 70 | 71 | 72 | CppCode 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /TikiTank/Visual Micro/Configuration.Debug.vmps.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /TikiTank/Visual Micro/Compile.vmps.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /TikiTank/Visual Micro/Upload.vmps.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /TikiTank/TikiTank.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {C3574ADD-879F-4082-9C1F-8C433CB597B7} 15 | TikiTank 16 | 17 | 18 | 19 | Application 20 | true 21 | v110 22 | MultiByte 23 | 24 | 25 | Application 26 | false 27 | v110 28 | true 29 | MultiByte 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | Level3 45 | Disabled 46 | true 47 | c:\Program Files (x86)\arduino-1.0.5\hardware\arduino\cores\arduino;c:\Program Files (x86)\arduino-1.0.5\hardware\arduino\variants\standard;c:\Program Files (x86)\arduino-1.0.5\libraries\Wire;c:\Program Files (x86)\arduino-1.0.5\libraries\Wire\utility;c:\Program Files (x86)\arduino-1.0.5\libraries\SPI;c:\Program Files (x86)\arduino-1.0.5\libraries\SPI\utility;D:\Home\Documents\Arduino\libraries\Adafruit_RGB_LCD;D:\Home\Documents\Arduino\libraries\Adafruit_RGB_LCD\utility;D:\Home\Documents\Arduino\libraries\LPD8806;D:\Home\Documents\Arduino\libraries\LPD8806\utility;c:\program files (x86)\arduino-1.0.5\hardware\tools\avr\avr\include\;c:\program files (x86)\arduino-1.0.5\hardware\tools\avr\avr\include\avr\;c:\program files (x86)\arduino-1.0.5\hardware\tools\avr\avr\;c:\program files (x86)\arduino-1.0.5\hardware\tools\avr\lib\gcc\avr\4.3.2\include\;%(AdditionalIncludeDirectories) 48 | D:\Home\Documents\Arduino\TikiTank\Visual Micro\.TikiTank.vsarduino.h;%(ForcedIncludeFiles) 49 | true 50 | __AVR_ATmega328P__;ARDUINO=105;__AVR__;F_CPU=16000000L;__cplusplus;%(PreprocessorDefinitions) 51 | 52 | 53 | true 54 | 55 | 56 | 57 | 58 | Level3 59 | MaxSpeed 60 | true 61 | true 62 | true 63 | 64 | 65 | true 66 | true 67 | true 68 | 69 | 70 | 71 | 72 | CppCode 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | --------------------------------------------------------------------------------