├── .gitattributes ├── .gitignore ├── ArduinoKemper.sln ├── KemperRemoteDIYArduino ├── Display_ER_RA8875.h ├── Display_ER_RA8875.ino ├── KemperRemoteDIYArduino.ino ├── KemperRemoteDIYArduino.vcxproj ├── KemperRemoteDIYArduino.vcxproj.filters └── __vm │ ├── .KemperRemoteDIYArduino.vsarduino.h │ ├── .TestKemper.vsarduino.h │ ├── Compile.vmps.xml │ ├── Configuration.Debug.vmps.xml │ ├── Configuration.Release.vmps.xml │ └── Upload.vmps.xml ├── KemperRemoteDIYWin ├── KemperRemoteDIYWin.cpp ├── KemperRemoteDIYWin.h ├── KemperRemoteDIYWin.vcxproj ├── KemperRemoteDIYWin.vcxproj.filters ├── MidiWrapper.cpp ├── MidiWrapper.h ├── RtMidi.cpp ├── RtMidi.h ├── SerialDisplaySerializer.cpp ├── SerialDisplaySerializer.h ├── WindowsSerial.cpp ├── WindowsSerial.h ├── inttypes.h └── mocks │ ├── Arduino.cpp │ ├── Arduino.h │ ├── EEPROM.cpp │ ├── EEPROM.h │ ├── KemperMock.cpp │ ├── KemperMock.h │ └── TypesMock.h ├── README.md ├── Simulator ├── KemperRemoteDIYWin.exe ├── README.md ├── app.js ├── images │ ├── board.jpg │ └── switch.png ├── index.html ├── package.json ├── promt.bat ├── scripts │ ├── jquery-1.11.3.min.js │ ├── knockout-3.3.0.js │ └── site.js ├── style.css └── tools │ ├── const-convert.js │ ├── consts.js │ ├── consts.txt │ └── updateCode.bat └── libraries ├── ER-TFTM043-3 ├── Examples │ ├── TouchScreenCalibration │ │ ├── TouchScreenCalibration.ino │ │ └── _desktop.ini │ ├── _desktop.ini │ ├── basicTextFunctions │ │ ├── _desktop.ini │ │ └── basicTextFunctions.ino │ ├── bubbles │ │ ├── _desktop.ini │ │ └── bubbles.ino │ ├── clock │ │ ├── _desktop.ini │ │ └── clock.ino │ ├── drawingTests │ │ ├── _desktop.ini │ │ └── drawingTests.ino │ ├── easyPaint │ │ ├── _desktop.ini │ │ └── easyPaint.ino │ ├── extFontRom │ │ ├── _desktop.ini │ │ └── extFontRom.ino │ ├── graphicAdaTest │ │ ├── _desktop.ini │ │ └── graphicAdaTest.ino │ ├── horizontalVU_usingLayers │ │ ├── _desktop.ini │ │ └── horizontalVU_usingLayers.ino │ ├── mandelbrot │ │ ├── _desktop.ini │ │ └── mandelbrot.ino │ ├── moodBackground │ │ ├── _desktop.ini │ │ └── moodBackground.ino │ ├── scroll │ │ ├── _desktop.ini │ │ └── scroll.ino │ └── treedee │ │ ├── _desktop.ini │ │ └── treedee.ino ├── RA8875.cpp ├── RA8875.h ├── _desktop.ini ├── _utility │ ├── RA8875Calibration.h │ ├── RA8875Registers.h │ └── _desktop.ini └── keywords.txt ├── Kemper ├── AbstractDisplay.cpp ├── AbstractDisplay.h ├── AbstractDisplaySerializer.h ├── AbstractKemper.cpp ├── AbstractKemper.h ├── Display_ER_RA8875.h ├── ExpressionPedal.cpp ├── ExpressionPedal.h ├── Kemper.cpp ├── Kemper.h ├── KemperRemote.cpp ├── KemperRemote.h ├── KemperRemoteDisplay.cpp ├── KemperRemoteDisplay.h ├── Kemper_namespace.h ├── Stomp.cpp ├── Stomp.h ├── Stomp_consts.h ├── Utils.cpp ├── Utils.h ├── VirtualDisplay.cpp ├── VirtualDisplay.h ├── VirtualDisplaySerializer.cpp └── VirtualDisplaySerializer.h ├── MIDI ├── MIDI.cpp ├── MIDI.h ├── MIDI.hpp ├── examples │ ├── MIDI_Basic_IO │ │ └── MIDI_Basic_IO.ino │ ├── MIDI_Bench │ │ └── MIDI_Bench.ino │ ├── MIDI_Callbacks │ │ └── MIDI_Callbacks.ino │ ├── MIDI_DualMerger │ │ └── MIDI_DualMerger.ino │ ├── MIDI_Input │ │ └── MIDI_Input.ino │ └── MIDI_SimpleSynth │ │ ├── MIDI_SimpleSynth.ino │ │ ├── noteList.cpp │ │ ├── noteList.h │ │ └── pitches.h ├── keywords.txt ├── midi_Defs.h ├── midi_Message.h ├── midi_Namespace.h └── midi_Settings.h ├── MemoryFree ├── MemoryFree.cpp └── MemoryFree.h ├── MultiButton ├── MultiButton.cpp ├── MultiButton.cpp.d ├── MultiButton.cpp.o └── MultiButton.h └── Tlc5940 ├── Doxyfile ├── Tlc5940.cpp ├── Tlc5940.h ├── changelog.txt ├── examples ├── BasicAnimations │ ├── AnimationCreator.class │ ├── AnimationCreator.java │ ├── Arduino.png │ ├── BasicAnimations.pde │ └── ani_arduino.h ├── BasicUse │ └── BasicUse.pde ├── CircularLightBuffer │ └── CircularLightBuffer.pde ├── FadeScope │ └── FadeScope.pde ├── Fades │ └── Fades.pde ├── Servos │ └── Servos.pde └── UsingProgmem │ └── UsingProgmem.pde ├── gpl.txt ├── keywords.txt ├── pinouts ├── ATmega_8.h ├── ATmega_xx4.h ├── ATmega_xx8.h ├── Arduino_Mega.h ├── Teensy_xxU4.h ├── Teensypp_xxx6.h └── chip_includes.h ├── tlc_animations.h ├── tlc_config.h ├── tlc_fades.h ├── tlc_progmem_utils.h ├── tlc_servos.h └── tlc_shifts.h /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | # DNX 42 | project.lock.json 43 | artifacts/ 44 | 45 | *_i.c 46 | *_p.c 47 | *_i.h 48 | *.ilk 49 | *.meta 50 | *.obj 51 | *.pch 52 | *.pdb 53 | *.pgc 54 | *.pgd 55 | *.rsp 56 | *.sbr 57 | *.tlb 58 | *.tli 59 | *.tlh 60 | *.tmp 61 | *.tmp_proj 62 | *.log 63 | *.vspscc 64 | *.vssscc 65 | .builds 66 | *.pidb 67 | *.svclog 68 | *.scc 69 | 70 | # Chutzpah Test files 71 | _Chutzpah* 72 | 73 | # Visual C++ cache files 74 | ipch/ 75 | *.aps 76 | *.ncb 77 | *.opensdf 78 | *.sdf 79 | *.cachefile 80 | 81 | # Visual Studio profiler 82 | *.psess 83 | *.vsp 84 | *.vspx 85 | 86 | # TFS 2012 Local Workspace 87 | $tf/ 88 | 89 | # Guidance Automation Toolkit 90 | *.gpState 91 | 92 | # ReSharper is a .NET coding add-in 93 | _ReSharper*/ 94 | *.[Rr]e[Ss]harper 95 | *.DotSettings.user 96 | 97 | # JustCode is a .NET coding add-in 98 | .JustCode 99 | 100 | # TeamCity is a build add-in 101 | _TeamCity* 102 | 103 | # DotCover is a Code Coverage Tool 104 | *.dotCover 105 | 106 | # NCrunch 107 | _NCrunch_* 108 | .*crunch*.local.xml 109 | 110 | # MightyMoose 111 | *.mm.* 112 | AutoTest.Net/ 113 | 114 | # Web workbench (sass) 115 | .sass-cache/ 116 | 117 | # Installshield output folder 118 | [Ee]xpress/ 119 | 120 | # DocProject is a documentation generator add-in 121 | DocProject/buildhelp/ 122 | DocProject/Help/*.HxT 123 | DocProject/Help/*.HxC 124 | DocProject/Help/*.hhc 125 | DocProject/Help/*.hhk 126 | DocProject/Help/*.hhp 127 | DocProject/Help/Html2 128 | DocProject/Help/html 129 | 130 | # Click-Once directory 131 | publish/ 132 | 133 | # Publish Web Output 134 | *.[Pp]ublish.xml 135 | *.azurePubxml 136 | ## TODO: Comment the next line if you want to checkin your 137 | ## web deploy settings but do note that will include unencrypted 138 | ## passwords 139 | #*.pubxml 140 | 141 | *.publishproj 142 | 143 | # NuGet Packages 144 | *.nupkg 145 | # The packages folder can be ignored because of Package Restore 146 | **/packages/* 147 | # except build/, which is used as an MSBuild target. 148 | !**/packages/build/ 149 | # Uncomment if necessary however generally it will be regenerated when needed 150 | #!**/packages/repositories.config 151 | 152 | # Windows Azure Build Output 153 | csx/ 154 | *.build.csdef 155 | 156 | # Windows Store app package directory 157 | AppPackages/ 158 | 159 | # Visual Studio cache files 160 | # files ending in .cache can be ignored 161 | *.[Cc]ache 162 | # but keep track of directories ending in .cache 163 | !*.[Cc]ache/ 164 | 165 | # Others 166 | ClientBin/ 167 | [Ss]tyle[Cc]op.* 168 | ~$* 169 | *~ 170 | *.dbmdl 171 | *.dbproj.schemaview 172 | *.pfx 173 | *.publishsettings 174 | node_modules/ 175 | orleans.codegen.cs 176 | 177 | # RIA/Silverlight projects 178 | Generated_Code/ 179 | 180 | # Backup & report files from converting an old project file 181 | # to a newer Visual Studio version. Backup files are not needed, 182 | # because we have git ;-) 183 | _UpgradeReport_Files/ 184 | Backup*/ 185 | UpgradeLog*.XML 186 | UpgradeLog*.htm 187 | 188 | # SQL Server files 189 | *.mdf 190 | *.ldf 191 | 192 | # Business Intelligence projects 193 | *.rdl.data 194 | *.bim.layout 195 | *.bim_*.settings 196 | 197 | # Microsoft Fakes 198 | FakesAssemblies/ 199 | 200 | # Node.js Tools for Visual Studio 201 | .ntvs_analysis.dat 202 | 203 | # Visual Studio 6 build log 204 | *.plg 205 | 206 | # Visual Studio 6 workspace options file 207 | *.opt 208 | 209 | # LightSwitch generated files 210 | GeneratedArtifacts/ 211 | _Pvt_Extensions/ 212 | ModelManifest.xml 213 | 214 | # Arduino files 215 | *.cpp.d 216 | *.cpp.o 217 | 218 | # Test projects 219 | Test*/ 220 | /Simulator/eeprom.bin 221 | /Simulator/eeprom - Copy.bin 222 | /Simulator 223 | -------------------------------------------------------------------------------- /ArduinoKemper.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KemperRemoteDIYArduino", "KemperRemoteDIYArduino\KemperRemoteDIYArduino.vcxproj", "{A25CAAE7-36A7-40A4-9B9F-86F2267B307A}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KemperRemoteDIYWin", "KemperRemoteDIYWin\KemperRemoteDIYWin.vcxproj", "{E54C8EE7-2D72-4414-819A-D944E7397C97}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Simulator", "Simulator", "{AD265E03-D9CD-4852-9967-6EE0FE554C00}" 11 | ProjectSection(SolutionItems) = preProject 12 | Simulator\app.js = Simulator\app.js 13 | Simulator\index.html = Simulator\index.html 14 | Simulator\README.md = Simulator\README.md 15 | Simulator\scripts\site.js = Simulator\scripts\site.js 16 | Simulator\style.css = Simulator\style.css 17 | EndProjectSection 18 | EndProject 19 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Misc", "Misc", "{A9E3C58E-EFE6-4D21-A31C-E02B3AFD75E2}" 20 | ProjectSection(SolutionItems) = preProject 21 | README.md = README.md 22 | EndProjectSection 23 | EndProject 24 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{A7CB9971-9729-40FC-9467-1DCA5E0B39CF}" 25 | ProjectSection(SolutionItems) = preProject 26 | Simulator\tools\const-convert.js = Simulator\tools\const-convert.js 27 | Simulator\tools\consts.js = Simulator\tools\consts.js 28 | EndProjectSection 29 | EndProject 30 | Global 31 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 32 | Debug|Any CPU = Debug|Any CPU 33 | Debug|Mixed Platforms = Debug|Mixed Platforms 34 | Debug|Win32 = Debug|Win32 35 | Debug|x64 = Debug|x64 36 | Debug|x86 = Debug|x86 37 | Release|Any CPU = Release|Any CPU 38 | Release|Mixed Platforms = Release|Mixed Platforms 39 | Release|Win32 = Release|Win32 40 | Release|x64 = Release|x64 41 | Release|x86 = Release|x86 42 | EndGlobalSection 43 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 44 | {A25CAAE7-36A7-40A4-9B9F-86F2267B307A}.Debug|Any CPU.ActiveCfg = Debug|Win32 45 | {A25CAAE7-36A7-40A4-9B9F-86F2267B307A}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 46 | {A25CAAE7-36A7-40A4-9B9F-86F2267B307A}.Debug|Mixed Platforms.Build.0 = Debug|Win32 47 | {A25CAAE7-36A7-40A4-9B9F-86F2267B307A}.Debug|Win32.ActiveCfg = Debug|Win32 48 | {A25CAAE7-36A7-40A4-9B9F-86F2267B307A}.Debug|Win32.Build.0 = Debug|Win32 49 | {A25CAAE7-36A7-40A4-9B9F-86F2267B307A}.Debug|x64.ActiveCfg = Debug|Win32 50 | {A25CAAE7-36A7-40A4-9B9F-86F2267B307A}.Debug|x86.ActiveCfg = Debug|Win32 51 | {A25CAAE7-36A7-40A4-9B9F-86F2267B307A}.Release|Any CPU.ActiveCfg = Release|Win32 52 | {A25CAAE7-36A7-40A4-9B9F-86F2267B307A}.Release|Mixed Platforms.ActiveCfg = Release|Win32 53 | {A25CAAE7-36A7-40A4-9B9F-86F2267B307A}.Release|Mixed Platforms.Build.0 = Release|Win32 54 | {A25CAAE7-36A7-40A4-9B9F-86F2267B307A}.Release|Win32.ActiveCfg = Release|Win32 55 | {A25CAAE7-36A7-40A4-9B9F-86F2267B307A}.Release|Win32.Build.0 = Release|Win32 56 | {A25CAAE7-36A7-40A4-9B9F-86F2267B307A}.Release|x64.ActiveCfg = Release|Win32 57 | {A25CAAE7-36A7-40A4-9B9F-86F2267B307A}.Release|x86.ActiveCfg = Release|Win32 58 | {E54C8EE7-2D72-4414-819A-D944E7397C97}.Debug|Any CPU.ActiveCfg = Debug|Win32 59 | {E54C8EE7-2D72-4414-819A-D944E7397C97}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 60 | {E54C8EE7-2D72-4414-819A-D944E7397C97}.Debug|Mixed Platforms.Build.0 = Debug|Win32 61 | {E54C8EE7-2D72-4414-819A-D944E7397C97}.Debug|Win32.ActiveCfg = Debug|Win32 62 | {E54C8EE7-2D72-4414-819A-D944E7397C97}.Debug|Win32.Build.0 = Debug|Win32 63 | {E54C8EE7-2D72-4414-819A-D944E7397C97}.Debug|x64.ActiveCfg = Debug|Win32 64 | {E54C8EE7-2D72-4414-819A-D944E7397C97}.Debug|x86.ActiveCfg = Debug|Win32 65 | {E54C8EE7-2D72-4414-819A-D944E7397C97}.Release|Any CPU.ActiveCfg = Release|Win32 66 | {E54C8EE7-2D72-4414-819A-D944E7397C97}.Release|Mixed Platforms.ActiveCfg = Release|Win32 67 | {E54C8EE7-2D72-4414-819A-D944E7397C97}.Release|Mixed Platforms.Build.0 = Release|Win32 68 | {E54C8EE7-2D72-4414-819A-D944E7397C97}.Release|Win32.ActiveCfg = Release|Win32 69 | {E54C8EE7-2D72-4414-819A-D944E7397C97}.Release|Win32.Build.0 = Release|Win32 70 | {E54C8EE7-2D72-4414-819A-D944E7397C97}.Release|x64.ActiveCfg = Release|Win32 71 | {E54C8EE7-2D72-4414-819A-D944E7397C97}.Release|x86.ActiveCfg = Release|Win32 72 | EndGlobalSection 73 | GlobalSection(SolutionProperties) = preSolution 74 | HideSolutionNode = FALSE 75 | EndGlobalSection 76 | GlobalSection(NestedProjects) = preSolution 77 | {A7CB9971-9729-40FC-9467-1DCA5E0B39CF} = {AD265E03-D9CD-4852-9967-6EE0FE554C00} 78 | EndGlobalSection 79 | EndGlobal 80 | -------------------------------------------------------------------------------- /KemperRemoteDIYArduino/Display_ER_RA8875.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _DISPLAY_ER_RA8875_H 3 | #define _DISPLAY_ER_RA8875_H 4 | 5 | #include "AbstractDisplay.h" 6 | 7 | #include "RA8875.h" 8 | 9 | #define RA8875_INT 23 10 | #define RA8875_CS 22 11 | 12 | #define RA8875_RESET 24 13 | 14 | class Display_ER_RA8875 : public AbstractDisplay { 15 | private: 16 | RA8875 tft; 17 | RA8875modes mode; 18 | uint16_t transparentColor; 19 | void changeMode(RA8875modes _mode); 20 | uint16_t getColorLocal(uint16_t color); 21 | public: 22 | Display_ER_RA8875(int _width, int _height); 23 | void writeTo(int layer); 24 | void setTransparentColor(uint16_t color); 25 | void layerEffect(int layerEffect); 26 | void clearRect(int16_t x, int16_t y, int16_t w, int16_t h); 27 | 28 | void begin(); 29 | 30 | void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); 31 | void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); 32 | void fillRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t radius, uint16_t color); 33 | void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); 34 | 35 | //void drawText(int16_t x, int16_t y, int16_t size, const char* text, int16_t len, uint16_t color, int16_t rotation); 36 | //void drawText(int16_t x, int16_t y, int16_t size, const char* str, int16_t len, uint16_t color, int16_t rotation, int letterCount); 37 | void drawText(int16_t x, int16_t y, int16_t w, int16_t h, TextAlignHorizontal horAlign, TextAlignVertical verAlign, int16_t size, const char* text, int16_t len, uint16_t color); 38 | 39 | void rectHelper (int16_t x, int16_t y, int16_t x2, int16_t y2, uint16_t color, bool filled); 40 | 41 | }; 42 | 43 | #endif -------------------------------------------------------------------------------- /KemperRemoteDIYArduino/KemperRemoteDIYArduino.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include "MIDI.h" 9 | #include "RA8875.h" 10 | 11 | #include "Kemper_Namespace.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "Display_ER_RA8875.h" 17 | #include 18 | #include "MultiButton.h" 19 | 20 | #include "Tlc5940.h" 21 | 22 | #define ENABLE_VIRTUAL_DISPLAY 23 | 24 | MultiButton buttons; 25 | 26 | bool lastValues[MAX_BUTTON_COUNT]; 27 | 28 | int rigNo = 1; 29 | 30 | #define LED 13 31 | 32 | #define TUNER_LOW 2 33 | #define TUNER_OK 3 34 | #define TUNER_HIGH 4 35 | 36 | USING_NAMESPACE_KEMPER 37 | 38 | Kemper kemper; 39 | KemperRemote kemperRemote(&kemper); 40 | 41 | byte lastLeds[LED_COUNT * 3]; 42 | 43 | #ifdef ENABLE_VIRTUAL_DISPLAY 44 | VirtualDisplaySerializer displaySerializer(&Serial); 45 | VirtualDisplay displayProvider(&displaySerializer, 480, 272); 46 | KemperRemoteDisplay display(&kemper, &kemperRemote, &displayProvider); 47 | #endif 48 | 49 | Display_ER_RA8875 displayProvider2(480, 272); 50 | KemperRemoteDisplay display2(&kemper, &kemperRemote, &displayProvider2); 51 | 52 | void setup() 53 | { 54 | pinMode(LED, OUTPUT); 55 | Serial.begin(921600); 56 | kemper.begin(); 57 | 58 | displayProvider2.begin(); 59 | 60 | #if !defined(KEMPER_DEBUG) && defined(ENABLE_VIRTUAL_DISPLAY) 61 | display.welcome(); 62 | #endif 63 | display2.welcome(); 64 | 65 | buttons.attach(14, 4, 5, 6, 7); 66 | Tlc.init(); 67 | } 68 | 69 | void loop() 70 | { 71 | static unsigned long reportTime = 0; 72 | static unsigned long ledTime = 0; 73 | static unsigned long tlcLedTime = 0; 74 | 75 | kemper.read(); 76 | kemperRemote.read(); 77 | 78 | if (Serial.available()) { 79 | int mode = Serial.read(); 80 | if (mode == 1) { // button press 81 | while (!Serial.available()) { 82 | } 83 | int sw = Serial.read() - 1; 84 | while (!Serial.available()) { 85 | } 86 | int pressed = Serial.read(); 87 | 88 | if (pressed) 89 | kemperRemote.onSwitchDown(sw); 90 | else 91 | kemperRemote.onSwitchUp(sw); 92 | } 93 | if (mode == 2) { // expression pedal 94 | while (!Serial.available()) { 95 | } 96 | int expId = Serial.read(); 97 | while (!Serial.available()) { 98 | } 99 | int expValue = Serial.read(); 100 | if (expId > 0 && expValue >= 0 && expId <= EXPRESSION_PEDAL_COUNT) { 101 | kemperRemote.expPedals[expId - 1].simValue = expValue<<2; 102 | } 103 | } 104 | } 105 | 106 | buttons.update(); 107 | for (int i = 0; i < buttons.buttonCount; i++) { 108 | if (buttons.values[i] != lastValues[i]) { 109 | lastValues[i] = buttons.values[i]; 110 | if (buttons.values[i]) { 111 | kemperRemote.onSwitchDown(i); 112 | } 113 | else { 114 | kemperRemote.onSwitchUp(i); 115 | } 116 | } 117 | } 118 | 119 | 120 | #if !defined(KEMPER_DEBUG) && defined(ENABLE_VIRTUAL_DISPLAY) 121 | if (millis() - ledTime > 50) { 122 | bool isChanged = false; 123 | for (int i = 0; i < LED_COUNT * 3; i++) 124 | { 125 | if (kemperRemote.leds[i] != lastLeds[i]) { 126 | isChanged = true; 127 | lastLeds[i] = kemperRemote.leds[i]; 128 | } 129 | } 130 | if (isChanged) 131 | { 132 | Serial.write(0xF0); 133 | for (int i = 0; i < LED_COUNT * 3; i++) { 134 | Serial.write(kemperRemote.leds[i]); 135 | } 136 | Serial.write(0xFF); 137 | Serial.flush(); 138 | } 139 | ledTime = millis(); 140 | } 141 | #endif 142 | 143 | if (millis() - tlcLedTime > 50) { 144 | int ledShift = 3; 145 | for (int i=0;i 5000 && true) { 179 | debug (F("Free memory / alive time = ")); 180 | debug(freeMemory ()); 181 | debug((int)(millis() / 1000)); 182 | memoryDebugTime = millis(); 183 | } 184 | #endif 185 | } 186 | 187 | -------------------------------------------------------------------------------- /KemperRemoteDIYArduino/__vm/.KemperRemoteDIYArduino.vsarduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | Editor: http://www.visualmicro.com 3 | visual micro and the arduino ide ignore this code during compilation. this code is automatically maintained by visualmicro, manual changes to this file will be overwritten 4 | the contents of the Visual Micro sketch sub folder can be deleted prior to publishing a project 5 | all non-arduino files created by visual micro and all visual studio project or solution files can be freely deleted and are not required to compile a sketch (do not delete your own code!). 6 | note: debugger breakpoints are stored in '.sln' or '.asln' files, knowledge of last uploaded breakpoints is stored in the upload.vmps.xml file. Both files are required to continue a previous debug session without needing to compile and upload again 7 | 8 | Hardware: Arduino Mega w/ ATmega2560 (Mega 2560), Platform=avr, Package=arduino 9 | */ 10 | 11 | #ifndef _VSARDUINO_H_ 12 | #define _VSARDUINO_H_ 13 | #define __AVR_ATmega2560__ 14 | #define F_CPU 16000000L 15 | #define ARDUINO 165 16 | #define ARDUINO_AVR_MEGA2560 17 | #define ARDUINO_ARCH_AVR 18 | #define __cplusplus 19 | #define __inline__ 20 | #define __asm__(x) 21 | #define __extension__ 22 | //#define __ATTR_PURE__ 23 | //#define __ATTR_CONST__ 24 | #define __inline__ 25 | //#define __asm__ 26 | #define __volatile__ 27 | #define GCC_VERSION 40801 28 | #define volatile(va_arg) 29 | #define _CONST 30 | typedef void *__builtin_va_list; 31 | #define __builtin_va_start 32 | #define __builtin_va_end 33 | //#define __DOXYGEN__ 34 | #define __attribute__(x) 35 | #define NOINLINE __attribute__((noinline)) 36 | #define prog_void 37 | #define PGM_VOID_P int 38 | #ifndef __builtin_constant_p 39 | #define __builtin_constant_p __attribute__((__const__)) 40 | #endif 41 | #ifndef __builtin_strlen 42 | #define __builtin_strlen __attribute__((__const__)) 43 | #endif 44 | #define NEW_H 45 | /* 46 | #ifndef __ATTR_CONST__ 47 | #define __ATTR_CONST__ __attribute__((__const__)) 48 | #endif 49 | 50 | #ifndef __ATTR_MALLOC__ 51 | #define __ATTR_MALLOC__ __attribute__((__malloc__)) 52 | #endif 53 | 54 | #ifndef __ATTR_NORETURN__ 55 | #define __ATTR_NORETURN__ __attribute__((__noreturn__)) 56 | #endif 57 | 58 | #ifndef __ATTR_PURE__ 59 | #define __ATTR_PURE__ __attribute__((__pure__)) 60 | #endif 61 | */ 62 | typedef unsigned char byte; 63 | extern "C" void __cxa_pure_virtual() {;} 64 | 65 | 66 | 67 | #include 68 | #include 69 | #undef F 70 | #define F(string_literal) ((const PROGMEM char *)(string_literal)) 71 | #undef PSTR 72 | #define PSTR(string_literal) ((const PROGMEM char *)(string_literal)) 73 | #undef cli 74 | #define cli() 75 | #define pgm_read_byte(address_short) 76 | #define pgm_read_word(address_short) 77 | #define pgm_read_word2(address_short) 78 | #define digitalPinToPort(P) 79 | #define digitalPinToBitMask(P) 80 | #define digitalPinToTimer(P) 81 | #define analogInPinToBit(P) 82 | #define portOutputRegister(P) 83 | #define portInputRegister(P) 84 | #define portModeRegister(P) 85 | #include 86 | #include 87 | #include 88 | #endif 89 | -------------------------------------------------------------------------------- /KemperRemoteDIYArduino/__vm/.TestKemper.vsarduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | Editor: http://www.visualmicro.com 3 | visual micro and the arduino ide ignore this code during compilation. this code is automatically maintained by visualmicro, manual changes to this file will be overwritten 4 | the contents of the Visual Micro sketch sub folder can be deleted prior to publishing a project 5 | all non-arduino files created by visual micro and all visual studio project or solution files can be freely deleted and are not required to compile a sketch (do not delete your own code!). 6 | note: debugger breakpoints are stored in '.sln' or '.asln' files, knowledge of last uploaded breakpoints is stored in the upload.vmps.xml file. Both files are required to continue a previous debug session without needing to compile and upload again 7 | 8 | Hardware: Arduino Mega w/ ATmega2560 (Mega 2560), Platform=avr, Package=arduino 9 | */ 10 | 11 | #ifndef _VSARDUINO_H_ 12 | #define _VSARDUINO_H_ 13 | #define __AVR_ATmega2560__ 14 | #define F_CPU 16000000L 15 | #define ARDUINO 164 16 | #define ARDUINO_AVR_MEGA2560 17 | #define ARDUINO_ARCH_AVR 18 | #define __cplusplus 19 | #define __inline__ 20 | #define __asm__(x) 21 | #define __extension__ 22 | //#define __ATTR_PURE__ 23 | //#define __ATTR_CONST__ 24 | #define __inline__ 25 | //#define __asm__ 26 | #define __volatile__ 27 | #define GCC_VERSION 40801 28 | #define volatile(va_arg) 29 | #define _CONST 30 | typedef void *__builtin_va_list; 31 | #define __builtin_va_start 32 | #define __builtin_va_end 33 | //#define __DOXYGEN__ 34 | #define __attribute__(x) 35 | #define NOINLINE __attribute__((noinline)) 36 | #define prog_void 37 | #define PGM_VOID_P int 38 | #ifndef __builtin_constant_p 39 | #define __builtin_constant_p __attribute__((__const__)) 40 | #endif 41 | #ifndef __builtin_strlen 42 | #define __builtin_strlen __attribute__((__const__)) 43 | #endif 44 | #define NEW_H 45 | /* 46 | #ifndef __ATTR_CONST__ 47 | #define __ATTR_CONST__ __attribute__((__const__)) 48 | #endif 49 | 50 | #ifndef __ATTR_MALLOC__ 51 | #define __ATTR_MALLOC__ __attribute__((__malloc__)) 52 | #endif 53 | 54 | #ifndef __ATTR_NORETURN__ 55 | #define __ATTR_NORETURN__ __attribute__((__noreturn__)) 56 | #endif 57 | 58 | #ifndef __ATTR_PURE__ 59 | #define __ATTR_PURE__ __attribute__((__pure__)) 60 | #endif 61 | */ 62 | typedef unsigned char byte; 63 | extern "C" void __cxa_pure_virtual() {;} 64 | 65 | 66 | 67 | #include 68 | #include 69 | #undef F 70 | #define F(string_literal) ((const PROGMEM char *)(string_literal)) 71 | #undef PSTR 72 | #define PSTR(string_literal) ((const PROGMEM char *)(string_literal)) 73 | #undef cli 74 | #define cli() 75 | #define pgm_read_byte(address_short) 76 | #define pgm_read_word(address_short) 77 | #define pgm_read_word2(address_short) 78 | #define digitalPinToPort(P) 79 | #define digitalPinToBitMask(P) 80 | #define digitalPinToTimer(P) 81 | #define analogInPinToBit(P) 82 | #define portOutputRegister(P) 83 | #define portInputRegister(P) 84 | #define portModeRegister(P) 85 | 86 | // 87 | // 88 | 89 | #include 90 | #endif 91 | -------------------------------------------------------------------------------- /KemperRemoteDIYWin/KemperRemoteDIYWin.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "KemperRemoteDIYWin.h" 3 | 4 | #include 5 | #include 6 | #include "KemperRemoteDisplay.h" 7 | 8 | #include "VirtualDisplaySerializer.h" 9 | #include "SerialDisplaySerializer.h" 10 | 11 | 12 | 13 | #include 14 | #include 15 | #include "RtMidi.h" 16 | 17 | 18 | USING_NAMESPACE_KEMPER 19 | 20 | int main(int argc, char**argv) { 21 | 22 | //Sleep(10000); 23 | if (argc < 2) { 24 | printf("USAGE: KemperRemoteDIYWin.exe [] []\n\n"); 25 | printf("mode = 0: Kemper Mock\n"); 26 | printf("mode = 1: Kemper MIDI\n"); 27 | exit(1); 28 | } 29 | int mode = atoi(argv[1]); 30 | 31 | int midiInPort = -1; 32 | int midiOutPort = -1; 33 | 34 | if (mode == 1) { 35 | if (argc < 4) { 36 | printf("ERROR: Missing midi port numbers!!\n\n"); 37 | printf("USAGE: KemperRemoteDIYWin.exe [] []\n\n"); 38 | printf("mode = 0: Kemper Mock\n"); 39 | printf("mode = 1: Kemper MIDI\n"); 40 | exit(1); 41 | } 42 | midiInPort = atoi(argv[2]); 43 | midiOutPort = atoi(argv[3]); 44 | } 45 | 46 | AbstractKemper* kemper; 47 | 48 | if (mode == 0) { 49 | KemperMock kemperMock; 50 | kemper = &kemperMock; 51 | } else { 52 | Kemper kemperReal; 53 | kemperReal.setMidiPorts(midiInPort, midiOutPort); 54 | kemperReal.begin(); 55 | kemper = &kemperReal; 56 | } 57 | kemper->state.mode = MODE_BROWSE; 58 | 59 | //kemper->setRig(2); 60 | 61 | KemperRemote kemperRemote(kemper); 62 | 63 | VirtualDisplaySerializer displaySerializer(&Serial); 64 | VirtualDisplay displayProvider(&displaySerializer, 480, 272); 65 | KemperRemoteDisplay display(kemper, &kemperRemote, &displayProvider); 66 | 67 | //SerialDisplaySerializer serialDisplaySerializer("COM7"); 68 | //VirtualDisplay displayProvider2(&serialDisplaySerializer, 480, 320); 69 | //KemperRemoteDisplay display2(kemper, &kemperRemote, &displayProvider2); 70 | 71 | 72 | //kemperRemote.read(); 73 | //kemper.setRig(2); 74 | char rigName[20] = ""; 75 | 76 | while (true) { 77 | kemper->read(); 78 | kemperRemote.read(); 79 | 80 | if (strcmp(kemper->state.rigName, rigName)) { 81 | memcpy(rigName, kemper->state.rigName, 20); 82 | } 83 | 84 | int p1 = 0; 85 | int p2 = 0; 86 | int p3 = 0; 87 | 88 | p1 = getc(stdin); 89 | if (p1 >= 0) { 90 | 91 | while ((p2 = getc(stdin)) == -1); 92 | while ((p3 = getc(stdin)) == -1); 93 | 94 | int mode = p1; 95 | 96 | if (mode == 1) { 97 | int sw = p2; 98 | if (sw > 0) { 99 | sw--; 100 | int pressed = p3; 101 | if (sw < 100) 102 | { 103 | if (pressed) 104 | kemperRemote.onSwitchDown(sw); 105 | else 106 | kemperRemote.onSwitchUp(sw); 107 | } 108 | else if (sw >= 100 && sw < 200) 109 | { 110 | if (pressed) { 111 | debug("Toggle stomp"); 112 | debug(sw - 100); 113 | kemper->toggleStomp(sw - 100); 114 | } 115 | } 116 | else if (sw >= 200 && sw < 300) 117 | { 118 | if (pressed) { 119 | if (sw == 200) { 120 | if (kemper->state.mode == MODE_BROWSE) { 121 | debug("Perform mode"); 122 | kemper->state.mode = MODE_PERFORM; 123 | kemper->setPerformance(kemper->state.performance, kemper->state.slot); 124 | } 125 | else if (kemper->state.mode == MODE_PERFORM) { 126 | debug("Browse mode"); 127 | kemper->state.mode = MODE_BROWSE; 128 | kemper->setRig(kemper->state.currentRig); 129 | } 130 | } 131 | } 132 | } 133 | } 134 | } 135 | else if (mode == 2) { 136 | int expId = 0; 137 | 138 | expId = p2; 139 | 140 | if (expId>0 && expId <= EXPRESSION_PEDAL_COUNT) 141 | { 142 | int expValue = 0; 143 | expValue = p3; 144 | if (expValue>=0) { 145 | kemperRemote.expPedals[expId-1].simValue = expValue<<2; 146 | } 147 | } 148 | } 149 | } 150 | 151 | fflush(stdout); 152 | 153 | Serial.write(0xF0); 154 | for (int i=0;i 6 | #include "Kemper.h" 7 | #include "KemperMock.h" 8 | #include "KemperRemote.h" -------------------------------------------------------------------------------- /KemperRemoteDIYWin/MidiWrapper.cpp: -------------------------------------------------------------------------------- 1 | #include "MidiWrapper.h" 2 | 3 | #include "midi_Namespace.h" 4 | #include "midi_Defs.h" 5 | 6 | USING_NAMESPACE_MIDI 7 | 8 | MidiInWrapper* pMidiIn; 9 | 10 | MidiType getTypeFromStatusByte(byte inStatus) 11 | { 12 | if ((inStatus < 0x80) || 13 | (inStatus == 0xf4) || 14 | (inStatus == 0xf5) || 15 | (inStatus == 0xf9) || 16 | (inStatus == 0xfD)) 17 | { 18 | // Data bytes and undefined. 19 | return InvalidType; 20 | } 21 | if (inStatus < 0xf0) 22 | { 23 | // Channel message, remove channel nibble. 24 | return MidiType(inStatus & 0xf0); 25 | } 26 | 27 | return MidiType(inStatus); 28 | } 29 | 30 | Channel getChannelFromStatusByte(byte inStatus) 31 | { 32 | return (inStatus & 0x0f) + 1; 33 | } 34 | 35 | 36 | void mycallback( double deltatime, std::vector< unsigned char > *message, void */*userData*/ ) 37 | { 38 | pMidiIn->lastMessage = message; 39 | unsigned int nBytes = message->size(); 40 | unsigned char* data = message->data(); 41 | /* 42 | for ( unsigned int i=0; i 0 ) 45 | std::cout << "stamp = " << deltatime << std::endl; 46 | */ 47 | byte channel = data[0]; 48 | channel = getChannelFromStatusByte(data[0]); 49 | byte type = getTypeFromStatusByte(data[0]); 50 | switch (type) { 51 | case ActiveSensing: if (pMidiIn->mActiveSensingCallback != 0) pMidiIn->mActiveSensingCallback(); break; 52 | case ControlChange: if (pMidiIn->mControlChangeCallback != 0) pMidiIn->mControlChangeCallback(channel, data[1], data[2]); break; 53 | case ProgramChange: if (pMidiIn->mProgramChangeCallback != 0) pMidiIn->mProgramChangeCallback(channel, data[1]); break; 54 | case SystemExclusive: if (pMidiIn->mSystemExclusiveCallback != 0) pMidiIn->mSystemExclusiveCallback(message->data(), message->size()); break; 55 | } 56 | } 57 | 58 | MidiInWrapper::MidiInWrapper() { 59 | mControlChangeCallback = 0; 60 | mProgramChangeCallback = 0; 61 | mSystemExclusiveCallback = 0; 62 | mActiveSensingCallback = 0; 63 | lastMessage = 0; 64 | } 65 | 66 | void MidiInWrapper::begin(byte channel) { 67 | pMidiIn = this; 68 | midiIn.ignoreTypes( false, false, false ); 69 | midiIn.setCallback( &mycallback ); 70 | } 71 | 72 | void MidiInWrapper::read() { 73 | 74 | } 75 | 76 | const byte* MidiInWrapper::getSysExArray() { 77 | if (lastMessage) 78 | return lastMessage->data(); 79 | return 0; 80 | } 81 | 82 | unsigned MidiInWrapper::getSysExArrayLength() { 83 | if (lastMessage) 84 | return lastMessage->size(); 85 | return 0; 86 | } 87 | 88 | void MidiOutWrapper::begin(byte channel) { 89 | } 90 | 91 | void MidiOutWrapper::sendSysEx(unsigned inLength, const byte* inArray, bool inArrayContainsBoundaries) { 92 | //message.clear(); 93 | std::vector message; 94 | if (!inArrayContainsBoundaries) 95 | message.push_back(0xf0); 96 | for (int i=0;i message; 106 | message.push_back(inType); 107 | message.push_back(inData1); 108 | message.push_back(inData2); 109 | midiOut.sendMessage( &message ); 110 | } 111 | -------------------------------------------------------------------------------- /KemperRemoteDIYWin/MidiWrapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Arduino.h" 4 | #include "RtMidi.h" 5 | 6 | class MidiInWrapper 7 | { 8 | private: 9 | public: 10 | std::vector< unsigned char > *lastMessage; 11 | void (*mControlChangeCallback)(byte channel, byte, byte); 12 | void (*mProgramChangeCallback)(byte channel, byte); 13 | void (*mSystemExclusiveCallback)(byte * array, unsigned size); 14 | void (*mActiveSensingCallback)(void); 15 | 16 | MidiInWrapper(); 17 | RtMidiIn midiIn; 18 | void begin(byte channel); 19 | void setHandleSystemExclusive(void (*fptr)(byte * array, unsigned size)) {mSystemExclusiveCallback = fptr;} 20 | void setHandleControlChange(void (*fptr)(byte channel, byte number, byte value)) {mControlChangeCallback = fptr;} 21 | void setHandleProgramChange(void (*fptr)(byte channel, byte number)) {mProgramChangeCallback = fptr;} 22 | void setHandleActiveSensing(void (*fptr)(void)) {mActiveSensingCallback = fptr;} 23 | void read(); 24 | const byte* getSysExArray(); 25 | unsigned getSysExArrayLength(); 26 | }; 27 | 28 | class MidiOutWrapper 29 | { 30 | private: 31 | std::vector message; 32 | public: 33 | RtMidiOut midiOut; 34 | void begin(byte channel); 35 | void sendSysEx(unsigned inLength, const byte* inArray, bool inArrayContainsBoundaries = false); 36 | void send(byte inType, byte inData1, byte inData2, byte inChannel); 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /KemperRemoteDIYWin/SerialDisplaySerializer.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "SerialDisplaySerializer.h" 3 | 4 | SerialDisplaySerializer::SerialDisplaySerializer(char *portName) { 5 | Serial.Connect(portName); 6 | } 7 | 8 | int SerialDisplaySerializer::transferByte(uint8_t a) { 9 | if (a>0xff) { 10 | KEMPER_NAMESPACE::debug("ERROR!!! SPI byte"); 11 | KEMPER_NAMESPACE::debug(a); 12 | } 13 | unsigned char data[2] = {a >> 4, a & 0xf}; 14 | Serial.WriteData(data, 2); 15 | return 0; 16 | } 17 | 18 | int SerialDisplaySerializer::transfer(uint16_t a) { 19 | transferByte((uint8_t)(a>>8)); 20 | transferByte((uint8_t)(a & 0xff)); 21 | return 0; 22 | } 23 | 24 | void SerialDisplaySerializer::start() { 25 | unsigned char data[1] = {0xf2}; 26 | Serial.WriteData(data, 1); 27 | } 28 | 29 | void SerialDisplaySerializer::end() { 30 | unsigned char data[1] = {0xff}; 31 | Serial.WriteData(data, 1); 32 | } 33 | 34 | int SerialDisplaySerializer::transferString(const char *text) { 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /KemperRemoteDIYWin/SerialDisplaySerializer.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "AbstractDisplaySerializer.h" 5 | #include "WindowsSerial.h" 6 | 7 | class SerialDisplaySerializer : public AbstractDisplaySerializer 8 | { 9 | public: 10 | SerialDisplaySerializer(char *portName); 11 | WindowsSerial Serial; 12 | int transferByte(uint8_t a); 13 | int transfer(uint16_t a); 14 | int transferString(const char *text); 15 | 16 | void start(); 17 | void end(); 18 | }; 19 | 20 | -------------------------------------------------------------------------------- /KemperRemoteDIYWin/WindowsSerial.cpp: -------------------------------------------------------------------------------- 1 | #include "WindowsSerial.h" 2 | 3 | void WindowsSerial::Connect(char *portName) 4 | { 5 | //We're not yet connected 6 | this->connected = false; 7 | 8 | //Try to connect to the given port throuh CreateFile 9 | this->hSerial = CreateFile(portName, 10 | GENERIC_READ | GENERIC_WRITE, 11 | 0, 12 | NULL, 13 | OPEN_EXISTING, 14 | FILE_ATTRIBUTE_NORMAL, 15 | NULL); 16 | 17 | //Check if the connection was successfull 18 | if(this->hSerial==INVALID_HANDLE_VALUE) 19 | { 20 | //If not success full display an Error 21 | if(GetLastError()==ERROR_FILE_NOT_FOUND){ 22 | 23 | //Print Error if neccessary 24 | printf("ERROR: Handle was not attached. Reason: %s not available.\n", portName); 25 | 26 | } 27 | else 28 | { 29 | printf("ERROR!!!"); 30 | } 31 | } 32 | else 33 | { 34 | //If connected we try to set the comm parameters 35 | DCB dcbSerialParams = {0}; 36 | 37 | //Try to get the current 38 | if (!GetCommState(this->hSerial, &dcbSerialParams)) 39 | { 40 | //If impossible, show an error 41 | printf("failed to get current serial parameters!"); 42 | } 43 | else 44 | { 45 | //Define serial connection parameters for the arduino board 46 | dcbSerialParams.BaudRate=CBR_115200; //CBR_9600; 47 | dcbSerialParams.ByteSize=8; 48 | dcbSerialParams.StopBits=ONESTOPBIT; 49 | dcbSerialParams.Parity=NOPARITY; 50 | //Setting the DTR to Control_Enable ensures that the Arduino is properly 51 | //reset upon establishing a connection 52 | dcbSerialParams.fDtrControl = DTR_CONTROL_ENABLE; 53 | 54 | //Set the parameters and check for their proper application 55 | if(!SetCommState(hSerial, &dcbSerialParams)) 56 | { 57 | printf("ALERT: Could not set Serial Port parameters"); 58 | } 59 | else 60 | { 61 | //If everything went fine we're connected 62 | this->connected = true; 63 | //Flush any remaining characters in the buffers 64 | PurgeComm(this->hSerial, PURGE_RXCLEAR | PURGE_TXCLEAR); 65 | //We wait 2s as the arduino board will be reseting 66 | Sleep(ARDUINO_WAIT_TIME); 67 | } 68 | } 69 | } 70 | 71 | } 72 | 73 | WindowsSerial::WindowsSerial() 74 | { 75 | this->connected = false; 76 | this->hSerial = 0; 77 | } 78 | 79 | WindowsSerial::~WindowsSerial() 80 | { 81 | //Check if we are connected before trying to disconnect 82 | if(this->connected) 83 | { 84 | //We're no longer connected 85 | this->connected = false; 86 | //Close the serial handler 87 | CloseHandle(this->hSerial); 88 | } 89 | } 90 | 91 | int WindowsSerial::ReadData(unsigned char *buffer, unsigned int nbChar) 92 | { 93 | //Number of bytes we'll have read 94 | DWORD bytesRead; 95 | //Number of bytes we'll really ask to read 96 | unsigned int toRead; 97 | 98 | //Use the ClearCommError function to get status info on the Serial port 99 | ClearCommError(this->hSerial, &this->errors, &this->status); 100 | 101 | //Check if there is something to read 102 | if(this->status.cbInQue>0) 103 | { 104 | //If there is we check if there is enough data to read the required number 105 | //of characters, if not we'll read only the available characters to prevent 106 | //locking of the application. 107 | if(this->status.cbInQue>nbChar) 108 | { 109 | toRead = nbChar; 110 | } 111 | else 112 | { 113 | toRead = this->status.cbInQue; 114 | } 115 | 116 | //Try to read the require number of chars, and return the number of read bytes on success 117 | if(ReadFile(this->hSerial, buffer, toRead, &bytesRead, NULL) && bytesRead != 0) 118 | { 119 | return bytesRead; 120 | } 121 | 122 | } 123 | 124 | //If nothing has been read, or that an error was detected return -1 125 | return -1; 126 | 127 | } 128 | 129 | 130 | bool WindowsSerial::WriteData(unsigned char *buffer, unsigned int nbChar) 131 | { 132 | DWORD bytesSend; 133 | 134 | //Try to write the buffer on the Serial port 135 | if(!WriteFile(this->hSerial, (void *)buffer, nbChar, &bytesSend, 0)) 136 | { 137 | //In case it don't work get comm error and return false 138 | ClearCommError(this->hSerial, &this->errors, &this->status); 139 | 140 | return false; 141 | } 142 | else { 143 | //FlushFileBuffers(this->hSerial); 144 | return true; 145 | } 146 | } 147 | 148 | bool WindowsSerial::IsConnected() 149 | { 150 | //Simply return the connection status 151 | return this->connected; 152 | } 153 | -------------------------------------------------------------------------------- /KemperRemoteDIYWin/WindowsSerial.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define ARDUINO_WAIT_TIME 2000 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | class WindowsSerial 10 | { 11 | private: 12 | //Serial comm handler 13 | HANDLE hSerial; 14 | //Connection status 15 | bool connected; 16 | //Get various information about the connection 17 | COMSTAT status; 18 | //Keep track of last error 19 | DWORD errors; 20 | 21 | public: 22 | //Initialize Serial communication with the given COM port 23 | WindowsSerial(); 24 | //Close the connection 25 | ~WindowsSerial(); 26 | void Connect(char *portName); 27 | //Read data in a buffer, if nbChar is greater than the 28 | //maximum number of bytes available, it will return only the 29 | //bytes available. The function return -1 when nothing could 30 | //be read, the number of bytes actually read. 31 | int ReadData(unsigned char *buffer, unsigned int nbChar); 32 | //Writes data from a buffer through the Serial connection 33 | //return true on success. 34 | bool WriteData(unsigned char *buffer, unsigned int nbChar); 35 | //Check if we are actually connected 36 | bool IsConnected(); 37 | 38 | 39 | }; 40 | -------------------------------------------------------------------------------- /KemperRemoteDIYWin/inttypes.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/basarane/kemper-arduino-library/1e5e416610921f6aa660a6cfafa02a7d5fe2a1ba/KemperRemoteDIYWin/inttypes.h -------------------------------------------------------------------------------- /KemperRemoteDIYWin/mocks/Arduino.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "Arduino.h" 4 | 5 | #include 6 | 7 | unsigned long millis() { 8 | static struct timeb start; 9 | if (start.time == 0) 10 | ftime(&start); 11 | struct timeb end; 12 | ftime(&end); 13 | return (int)((int) (1000.0 * (end.time - start.time) + (end.millitm - start.millitm))); 14 | } 15 | 16 | void HardwareSerial::write(byte a) { 17 | fwrite(&a,sizeof(byte),1,stdout); 18 | } 19 | 20 | void HardwareSerial::print(const char* s) { 21 | fputs(s,stdout); 22 | } 23 | 24 | void HardwareSerial::print(int s) { 25 | printf("%d", s); 26 | } 27 | 28 | void HardwareSerial::println(const char* s) { 29 | print(s); 30 | printf("\n"); 31 | } 32 | 33 | void HardwareSerial::println(int s) { 34 | print(s); 35 | printf("\n"); 36 | } 37 | 38 | void HardwareSerial::flush() { 39 | fflush(stdout); 40 | } 41 | 42 | HardwareSerial Serial; 43 | 44 | int analogRead(int pin) { 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /KemperRemoteDIYWin/mocks/Arduino.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | typedef unsigned char byte; 5 | 6 | #define min(a,b) ((a)<(b)?(a):(b)) 7 | #define max(a,b) ((a)>(b)?(a):(b)) 8 | //#define abs(x) ((x)>0?(x):-(x)) 9 | #define PROGMEM 10 | 11 | #define PI 3.1415926535897932384626433832795 12 | 13 | #define memcpy_P memcpy 14 | #define strcpy_P strcpy 15 | #define pgm_read_word_near(a) (int)(*(a)) 16 | #define pgm_read_byte_near(a) (byte)(*(a)) 17 | #define pgm_read_float_near(a) (float)(*(a)) 18 | 19 | #define __FlashStringHelper char 20 | 21 | #define F(x) x 22 | 23 | unsigned long millis(); 24 | 25 | #include 26 | #include "TypesMock.h" 27 | //#include "wstring.h" 28 | #include 29 | #include "WindowsSerial.h" 30 | 31 | class HardwareSerial 32 | { 33 | public: 34 | void write(byte a); 35 | void print(const char *s); 36 | void print(int s); 37 | void println(const char *s); 38 | void println(int s); 39 | void flush(); 40 | }; 41 | 42 | extern HardwareSerial Serial; 43 | int analogRead(int pin); -------------------------------------------------------------------------------- /KemperRemoteDIYWin/mocks/EEPROM.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "EEPROM.h" 3 | 4 | //C_EEPROM::C_EEPROM() { 5 | // memset(_data, -1, sizeof(_data)); 6 | //} 7 | // 8 | //template< typename T > void C_EEPROM::put(int address, T data) { 9 | // memcpy(_data + address, &data, sizeof(T)); 10 | //} 11 | // 12 | //template< typename T > void C_EEPROM::get(int address, T data) { 13 | // memcpy(&data, _data + address, sizeof(T)); 14 | //} 15 | // 16 | //C_EEPROM EEPROM; -------------------------------------------------------------------------------- /KemperRemoteDIYWin/mocks/EEPROM.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Arduino.h" 5 | 6 | #define WINDOWS_EEPROM_SIZE 4096 7 | // 8 | //class C_EEPROM 9 | //{ 10 | //private: 11 | // byte _data[4096]; 12 | //public: 13 | // C_EEPROM(); 14 | // template< typename T > void put(int address, T data); 15 | // template< typename T > void get(int address, T data); 16 | //}; 17 | // 18 | //extern C_EEPROM EEPROM; 19 | 20 | class EEPROMClass { 21 | private: 22 | uint8_t eepromBuffer[WINDOWS_EEPROM_SIZE]; 23 | public: 24 | EEPROMClass() { 25 | memset(eepromBuffer, -1, sizeof(eepromBuffer)); 26 | FILE *file = fopen("eeprom.bin", "rb"); 27 | if (file) { 28 | fread(eepromBuffer, sizeof(eepromBuffer), 1, file); 29 | fclose(file); 30 | } 31 | } 32 | 33 | template< typename T > T &get(int idx, T &t) { 34 | uint8_t *ptr = (uint8_t*)&t; 35 | int len = sizeof(T); 36 | memcpy(ptr, eepromBuffer + idx, len); 37 | return t; 38 | } 39 | 40 | template< typename T > const T &put(int idx, const T &t) { 41 | const uint8_t *ptr = (const uint8_t*)&t; 42 | int len = sizeof(T); 43 | memcpy(eepromBuffer + idx, ptr, len); 44 | 45 | FILE *file = fopen("eeprom.bin", "wb"); 46 | fwrite(eepromBuffer, sizeof(eepromBuffer), 1, file); 47 | fclose(file); 48 | 49 | return t; 50 | } 51 | }; 52 | 53 | // 54 | //} 55 | // 56 | //template< typename T > void C_EEPROM::get(int address, T data) { 57 | // memcpy(&data, _data + address, sizeof(T)); 58 | 59 | 60 | static EEPROMClass EEPROM; 61 | 62 | -------------------------------------------------------------------------------- /KemperRemoteDIYWin/mocks/KemperMock.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Kemper.h 3 | * Project Arduino Kemper MIDI Library 4 | * @brief Kemper MIDI Library for the Arduino 5 | * @version 1.0 6 | * @author Ersin Basaran 7 | * @date 16/07/15 8 | * @license GPL v3.0 9 | */ 10 | #pragma once 11 | 12 | #include "Arduino.h" 13 | 14 | #include "Kemper_namespace.h" 15 | #include "AbstractKemper.h" 16 | #include "Stomp.h" 17 | #include 18 | #include 19 | 20 | 21 | BEGIN_KEMPER_NAMESPACE 22 | 23 | class KemperMock : public AbstractKemper 24 | { 25 | private: 26 | int lastMode; 27 | StompState defaultStompStates[2][RIG_COUNT*5][8]; 28 | int defaultStompParameters[KEMPER_STOMP_COUNT][128]; 29 | 30 | public: 31 | 32 | KemperMock(); 33 | 34 | void read(); 35 | 36 | void tunerOn(); 37 | void tunerOff(); 38 | void tapOn(); 39 | void tapOff(); 40 | 41 | void sendControlChange(byte data1, byte data2); 42 | void toggleStomp(byte idx); 43 | void setPerformance(int idx, int slot = 0); 44 | void setRig(byte rig); 45 | 46 | void getStompParameter(int stompIdx, int paramNumber); 47 | void setStompParam(int stompIdx, byte number, int val); 48 | 49 | }; 50 | 51 | 52 | 53 | END_KEMPER_NAMESPACE 54 | 55 | -------------------------------------------------------------------------------- /KemperRemoteDIYWin/mocks/TypesMock.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | /* 5 | typedef char int8_t; 6 | typedef int int32_t; 7 | */ 8 | typedef short int16_t; 9 | typedef unsigned char uint8_t; 10 | typedef unsigned short uint16_t; 11 | typedef unsigned int uint32_t; 12 | -------------------------------------------------------------------------------- /Simulator/KemperRemoteDIYWin.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/basarane/kemper-arduino-library/1e5e416610921f6aa660a6cfafa02a7d5fe2a1ba/Simulator/KemperRemoteDIYWin.exe -------------------------------------------------------------------------------- /Simulator/README.md: -------------------------------------------------------------------------------- 1 | # Simulator 2 | 3 | 4 | -------------------------------------------------------------------------------- /Simulator/images/board.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/basarane/kemper-arduino-library/1e5e416610921f6aa660a6cfafa02a7d5fe2a1ba/Simulator/images/board.jpg -------------------------------------------------------------------------------- /Simulator/images/switch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/basarane/kemper-arduino-library/1e5e416610921f6aa660a6cfafa02a7d5fe2a1ba/Simulator/images/switch.png -------------------------------------------------------------------------------- /Simulator/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 21 | 22 | 23 | 24 |
25 |
26 |
27 | 28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | Exp 1: | 42 | Exp 2: | 43 | Exp 3: | 44 | Exp 4: | 45 |
46 |
47 |
48 |
49 |
50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /Simulator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Simulator", 3 | "version": "0.0.0", 4 | "description": "Arduino Kemper Library Simulator", 5 | "main": "app.js", 6 | "author": { 7 | "name": "Ersin Basaran", 8 | "email": "ersin@komputer.com.tr" 9 | }, 10 | "dependencies": { 11 | "express": "^4.13.1", 12 | "serialport": "^1.7.4", 13 | "socket.io": "^1.3.5" 14 | }, 15 | "devDependencies": {} 16 | } 17 | -------------------------------------------------------------------------------- /Simulator/promt.bat: -------------------------------------------------------------------------------- 1 | cmd 2 | -------------------------------------------------------------------------------- /Simulator/tools/updateCode.bat: -------------------------------------------------------------------------------- 1 | node const-convert.js > ../../libraries/kemper/Stomp_consts.h -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/TouchScreenCalibration/_desktop.ini: -------------------------------------------------------------------------------- 1 | 2015/2/13 -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/_desktop.ini: -------------------------------------------------------------------------------- 1 | 2015/2/13 -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/basicTextFunctions/_desktop.ini: -------------------------------------------------------------------------------- 1 | 2015/2/13 -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/basicTextFunctions/basicTextFunctions.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Basic Text Functions 3 | Tested and worked with: 4 | Teensy3,Teensy3.1,Arduino UNO,Arduino YUN,Arduino Leonardo,Stellaris 5 | Works with Arduino 1.0.6 IDE, Arduino 1.5.8 IDE, Energia 0013 IDE 6 | ---------------> http://www.buydisplay.com 7 | */ 8 | #include 9 | #include 10 | 11 | //Arduino DUE,Arduino mega2560 12 | #define RA8875_INT 23 13 | #define RA8875_CS 22 14 | 15 | #define RA8875_RESET 24 16 | 17 | //#if defined(NEEDS_SET_MODULE)//Energia, this case is for stellaris/tiva 18 | 19 | //RA8875 tft = RA8875(3);//select SPI module 3 20 | /* 21 | for module 3 (stellaris) 22 | SCLK: PD_0 23 | MOSI: PD_3 24 | MISO: PD_2 25 | SS: PD_1 26 | */ 27 | //#else 28 | 29 | RA8875 tft = RA8875(RA8875_CS,RA8875_RESET); 30 | 31 | //#endif 32 | 33 | void setup() 34 | { 35 | Serial.begin(9600); 36 | //while (!Serial) {;} 37 | Serial.println("RA8875 start"); 38 | //initialization routine 39 | tft.begin(RA8875_480x272); 40 | 41 | //following it's already by begin function but 42 | //if you like another background color.... 43 | tft.fillScreen(RA8875_BLACK);//fill screen black 44 | 45 | //RA8875 it's capable to draw graphic but also Text 46 | //here we switch to TEXT mode 47 | tft.changeMode(TEXT); 48 | //now set a text color, background transparent 49 | tft.setTextColor(RA8875_WHITE); 50 | //use the classic print an println command 51 | tft.print("Hello World"); 52 | //by default the text location is set to 0,0 53 | //now set it at 50,20 pixels and different color 54 | tft.setCursor(50,20);//set cursor work in pixel!!! 55 | //this time we not using transparent background 56 | tft.setTextColor(RA8875_RED,RA8875_GREEN); 57 | tft.print("Hello World"); 58 | //by default we using the internal font 59 | //so some manipulation it's possible 60 | tft.setFontScale(1);//font x2 61 | tft.setTextColor(RA8875_RED); 62 | tft.print("www.buydisplay.com"); 63 | //You notice that font location has been 64 | //automatically increased by chip, unfortunatly not 65 | //tracked by library but we can use a command for that... 66 | uint16_t currentX,currentY; 67 | tft.getCursor(¤tX,¤tY); 68 | //now we have the location, lets draw a white pixel 69 | tft.changeMode(GRAPHIC);//first we swith in graphic mode 70 | tft.drawPixel(currentX,currentY,RA8875_WHITE); 71 | //did you see the white dot? 72 | tft.changeMode(TEXT);//go back to text mode 73 | tft.setFontScale(0);//font x1 74 | tft.setCursor(0,50); 75 | tft.setTextColor(RA8875_YELLOW); 76 | tft.println("ABCDEF 1 2 3 4");//this time println! 77 | tft.setFontSpacing(5);//now give 5 pix spacing 78 | tft.println("ABCDEF 1 2 3 4"); 79 | tft.setFontSpacing(0);//reset 80 | tft.setFontRotate(true); 81 | tft.println("ABCDEF 1 2 3 4"); 82 | tft.setFontRotate(false); 83 | tft.setFontScale(2);//font x1 84 | tft.setTextColor(RA8875_BLUE,RA8875_BLACK); 85 | } 86 | 87 | unsigned long i = 0; 88 | 89 | void loop() 90 | { 91 | tft.setCursor(50,100); 92 | if (i > 99) tft.setTextColor(RA8875_CYAN,RA8875_BLACK); 93 | if (i > 999) tft.setTextColor(RA8875_MAGENTA,RA8875_BLACK); 94 | tft.print(i,DEC); 95 | delay(10); 96 | i++; 97 | } 98 | -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/bubbles/_desktop.ini: -------------------------------------------------------------------------------- 1 | 2015/2/13 -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/clock/_desktop.ini: -------------------------------------------------------------------------------- 1 | 2015/2/13 -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/clock/clock.ino: -------------------------------------------------------------------------------- 1 | /* 2 | A really simple analog clock 3 | Tested and worked with: 4 | Teensy3,Teensy3.1,Arduino UNO,Arduino YUN,Arduino Leonardo,Stellaris 5 | Works with Arduino 1.0.6 IDE, Arduino 1.5.8 IDE, Energia 0013 IDE 6 | ---------------> http://www.buydisplay.com 7 | */ 8 | 9 | 10 | #include 11 | #include 12 | 13 | //Arduino DUE,Arduino mega2560 14 | #define RA8875_INT 23 15 | #define RA8875_CS 22 16 | 17 | #define RA8875_RESET 24 18 | 19 | //#if defined(NEEDS_SET_MODULE)//Energia, this case is for stellaris/tiva 20 | //RA8875 tft = RA8875(3);//select SPI module 3 21 | /* 22 | for module 3 (stellaris) 23 | SCLK: PD_0 24 | MOSI: PD_3 25 | MISO: PD_2 26 | SS: PD_1 27 | */ 28 | //#else 29 | 30 | RA8875 tft = RA8875(RA8875_CS,RA8875_RESET); 31 | 32 | //#endif 33 | 34 | 35 | uint16_t ccenterx,ccentery;//center x,y of the clock 36 | const uint16_t cradius = 110;//radius of the clock 37 | const float scosConst = 0.0174532925; 38 | float sx = 0, sy = 1, mx = 1, my = 0, hx = -1, hy = 0; 39 | float sdeg=0, mdeg=0, hdeg=0; 40 | uint16_t osx,osy,omx,omy,ohx,ohy; 41 | uint16_t x0 = 0, x1 = 0, yy0 = 0, yy1 = 0; 42 | uint32_t targetTime = 0;// for next 1 second timeout 43 | uint8_t hh,mm,ss; //containers for current time 44 | 45 | 46 | void drawClockFace(){ 47 | tft.fillCircle(ccenterx, ccentery, cradius, RA8875_BLUE); 48 | tft.fillCircle(ccenterx, ccentery, cradius-4, RA8875_BLACK); 49 | // Draw 12 lines 50 | for(int i = 0; i<360; i+= 30) { 51 | sx = cos((i-90)*scosConst); 52 | sy = sin((i-90)*scosConst); 53 | x0 = sx*(cradius-4)+ccenterx; 54 | yy0 = sy*(cradius-4)+ccentery; 55 | x1 = sx*(cradius-11)+ccenterx; 56 | yy1 = sy*(cradius-11)+ccentery; 57 | tft.drawLine(x0, yy0, x1, yy1, RA8875_BLUE); 58 | } 59 | } 60 | 61 | static uint8_t conv2d(const char* p) { 62 | uint8_t v = 0; 63 | if ('0' <= *p && *p <= '9') v = *p - '0'; 64 | return 10 * v + *++p - '0'; 65 | } 66 | 67 | void setup(void) { 68 | tft.begin(RA8875_480x272); 69 | 70 | tft.setTextColor(RA8875_WHITE, RA8875_BLACK); 71 | ccenterx = tft.width()/2; 72 | ccentery = tft.height()/2; 73 | osx = ccenterx; 74 | osy = ccentery; 75 | omx = ccenterx; 76 | omy = ccentery; 77 | ohx = ccenterx; 78 | ohy = ccentery; 79 | drawClockFace();// Draw clock face 80 | //get current time from compiler 81 | hh = conv2d(__TIME__); 82 | mm = conv2d(__TIME__+3); 83 | ss = conv2d(__TIME__+6); 84 | targetTime = millis() + 1000; 85 | } 86 | 87 | void drawClockHands(uint8_t h,uint8_t m,uint8_t s){ 88 | // Pre-compute hand degrees, x & y coords for a fast screen update 89 | sdeg = s * 6; // 0-59 -> 0-354 90 | mdeg = m * 6 + sdeg * 0.01666667; // 0-59 -> 0-360 - includes seconds 91 | hdeg = h * 30 + mdeg * 0.0833333; // 0-11 -> 0-360 - includes minutes and seconds 92 | hx = cos((hdeg-90)*scosConst); 93 | hy = sin((hdeg-90)*scosConst); 94 | mx = cos((mdeg-90)*scosConst); 95 | my = sin((mdeg-90)*scosConst); 96 | sx = cos((sdeg-90)*scosConst); 97 | sy = sin((sdeg-90)*scosConst); 98 | 99 | // Erase just old hand positions 100 | tft.drawLine(ohx, ohy, ccenterx+1, ccentery+1, RA8875_BLACK); 101 | tft.drawLine(omx, omy, ccenterx+1, ccentery+1, RA8875_BLACK); 102 | tft.drawLine(osx, osy, ccenterx+1, ccentery+1, RA8875_BLACK); 103 | // Draw new hand positions 104 | tft.drawLine(hx*(cradius-28)+ccenterx+1, hy*(cradius-28)+ccentery+1, ccenterx+1, ccentery+1, RA8875_WHITE); 105 | tft.drawLine(mx*(cradius-17)+ccenterx+1, my*(cradius-17)+ccentery+1, ccenterx+1, ccentery+1, RA8875_WHITE); 106 | tft.drawLine(sx*(cradius-14)+ccenterx+1, sy*(cradius-14)+ccentery+1, ccenterx+1, ccentery+1, RA8875_RED); 107 | tft.fillCircle(ccenterx+1, ccentery+1, 3, RA8875_RED); 108 | 109 | // Update old x&y coords 110 | osx = sx*(cradius-14)+ccenterx+1; 111 | osy = sy*(cradius-14)+ccentery+1; 112 | omx = mx*(cradius-17)+ccenterx+1; 113 | omy = my*(cradius-17)+ccentery+1; 114 | ohx = hx*(cradius-28)+ccenterx+1; 115 | ohy = hy*(cradius-28)+ccentery+1; 116 | } 117 | 118 | 119 | 120 | void drawPrintTime(uint16_t x,uint16_t y, uint8_t h,uint8_t m,uint8_t s){ 121 | tft.changeMode(TEXT); 122 | tft.setCursor (0, 0); 123 | tft.print ("www.buydisplay.com"); 124 | tft.setCursor (x, y); 125 | tft.print(__DATE__); 126 | tft.setCursor (x, y-13); 127 | if (hh > 12) { 128 | if (hh < 22) tft.print('0'); 129 | tft.print (hh-12); 130 | } 131 | else { 132 | if (hh < 10) tft.print('0'); 133 | tft.print (hh); 134 | } 135 | tft.print (':'); 136 | if (mm < 10) tft.print('0'); 137 | tft.print (mm); 138 | tft.print (':'); 139 | if (ss < 10) tft.print('0'); 140 | tft.print (ss); 141 | if (hh > 12) { 142 | tft.print(" pm"); 143 | } 144 | else { 145 | tft.print (" am"); 146 | } 147 | tft.changeMode(GRAPHIC); 148 | } 149 | 150 | void loop() { 151 | if (targetTime < millis()) { 152 | targetTime = millis()+1000; 153 | ss++; 154 | if (ss == 60) { 155 | ss = 0; 156 | mm++; 157 | if(mm > 59) { 158 | mm = 0; 159 | hh++; 160 | if (hh > 23) hh = 0; 161 | } 162 | } 163 | drawClockHands(hh,mm,ss); 164 | drawPrintTime(34,151,hh,mm,ss); 165 | } 166 | } 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/drawingTests/_desktop.ini: -------------------------------------------------------------------------------- 1 | 2015/2/13 -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/easyPaint/_desktop.ini: -------------------------------------------------------------------------------- 1 | 2015/2/13 -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/easyPaint/easyPaint.ino: -------------------------------------------------------------------------------- 1 | /* Touch screen super-easy paint! 2 | This version use the new touch screen functions, much easier! 3 | Did you have already calibrated your screen? Better do as soon you can 4 | Open TouchScreenCalibration example and follow instructions. 5 | Tested and worked with: 6 | Teensy3,Teensy3.1,Arduino UNO,Arduino YUN,Arduino Leonardo,Stellaris 7 | Works with Arduino 1.0.6 IDE, Arduino 1.5.8 IDE, Energia 0013 IDE 8 | ---------------> http://www.buydisplay.com 9 | */ 10 | 11 | 12 | #include 13 | #include 14 | 15 | //Arduino DUE,Arduino mega2560 16 | #define RA8875_INT 23 17 | #define RA8875_CS 22 18 | 19 | #define RA8875_RESET 24 20 | 21 | //#if defined(NEEDS_SET_MODULE)//Energia, this case is for stellaris/tiva 22 | 23 | //RA8875 tft = RA8875(3);//select SPI module 3 24 | /* 25 | for module 3 (stellaris) 26 | SCLK: PD_0 27 | MOSI: PD_3 28 | MISO: PD_2 29 | SS: PD_1 30 | */ 31 | //#else 32 | 33 | RA8875 tft = RA8875(RA8875_CS,RA8875_RESET);//Teensy3/arduino's 34 | 35 | //#endif 36 | 37 | uint16_t tx, ty; 38 | 39 | 40 | void interface(){ 41 | tft.fillRect(10,10,40,40,RA8875_WHITE); 42 | tft.fillRect(10+(40*1)+(10*1),10,40,40,RA8875_BLUE); 43 | tft.fillRect(10+(40*2)+(10*2),10,40,40,RA8875_RED); 44 | tft.fillRect(10+(40*3)+(10*3),10,40,40,RA8875_GREEN); 45 | tft.fillRect(10+(40*4)+(10*4),10,40,40,RA8875_CYAN); 46 | tft.fillRect(10+(40*5)+(10*5),10,40,40,RA8875_MAGENTA); 47 | tft.fillRect(10+(40*6)+(10*6),10,40,40,RA8875_YELLOW); 48 | tft.drawRect(10+(40*7)+(10*7),10,40,40,RA8875_WHITE); 49 | } 50 | 51 | void setup() 52 | { 53 | Serial.begin(9600); 54 | //while (!Serial) {;} 55 | Serial.println("RA8875 start"); 56 | 57 | tft.begin(RA8875_480x272); 58 | 59 | tft.touchBegin(RA8875_INT);//enable Touch support! 60 | interface(); 61 | } 62 | 63 | uint16_t choosenColor = 0; 64 | 65 | void loop() 66 | { tft.changeMode(TEXT); 67 | tft.setTextColor(RA8875_WHITE); 68 | tft.setCursor (600, 0); 69 | tft.print ("www.buydisplay.com"); 70 | tft.changeMode(GRAPHIC); 71 | 72 | if (tft.touchDetect()){//easy! 73 | tft.touchReadPixel(&tx, &ty);//read directly in pixel! 74 | tx=800-tx;ty=480-ty; 75 | if (ty >= 0 && ty <= 55){ //interface area 76 | if ((tx > 10 && tx < (10+40))){ 77 | choosenColor = RA8875_WHITE; 78 | interface(); 79 | tft.fillRect(10,10,40,40,RA8875_BLACK); 80 | tft.fillCircle(tft.width()-10,10,5,choosenColor); 81 | } 82 | else if ((tx > 10+(40*1)+(10*1) && tx < 10+(40*2)+(10*1))){ 83 | choosenColor = RA8875_BLUE; 84 | interface(); 85 | tft.fillRect(10+(40*1)+(10*1),10,40,40,RA8875_BLACK); 86 | tft.fillCircle(tft.width()-10,10,5,choosenColor); 87 | } 88 | else if ((tx > 10+(40*2)+(10*2) && tx < 10+(40*3)+(10*2))){ 89 | choosenColor = RA8875_RED; 90 | interface(); 91 | tft.fillRect(10+(40*2)+(10*2),10,40,40,RA8875_BLACK); 92 | tft.fillCircle(tft.width()-10,10,5,choosenColor); 93 | } 94 | else if ((tx > 10+(40*3)+(10*3) && tx < 10+(40*4)+(10*3))){ 95 | choosenColor = RA8875_GREEN; 96 | interface(); 97 | tft.fillRect(10+(40*3)+(10*3),10,40,40,RA8875_BLACK); 98 | tft.fillCircle(tft.width()-10,10,5,choosenColor); 99 | } 100 | else if ((tx > 10+(40*4)+(10*4) && tx < 10+(40*5)+(10*4))){ 101 | choosenColor = RA8875_CYAN; 102 | interface(); 103 | tft.fillRect(10+(40*4)+(10*4),10,40,40,RA8875_BLACK); 104 | tft.fillCircle(tft.width()-10,10,5,choosenColor); 105 | } 106 | else if ((tx > 10+(40*5)+(10*5) && tx < 10+(40*6)+(10*5))){ 107 | choosenColor = RA8875_MAGENTA; 108 | interface(); 109 | tft.fillRect(10+(40*5)+(10*5),10,40,40,RA8875_BLACK); 110 | tft.fillCircle(tft.width()-10,10,5,choosenColor); 111 | } 112 | else if ((tx > 10+(40*6)+(10*6) && tx < 10+(40*7)+(10*6))){ 113 | choosenColor = RA8875_YELLOW; 114 | interface(); 115 | tft.fillRect(10+(40*6)+(10*6),10,40,40,RA8875_BLACK); 116 | tft.fillCircle(tft.width()-10,10,5,choosenColor); 117 | } 118 | else if ((tx > 10+(40*7)+(10*7) && tx < 10+(40*8)+(10*7))){ 119 | choosenColor = 0; 120 | interface(); 121 | tft.fillRect(0,52,tft.width()-1,tft.height()-53,RA8875_BLACK); 122 | tft.fillCircle(tft.width()-10,10,5,RA8875_BLACK); 123 | } 124 | } else { //paint 125 | //if (choosenColor != 0) tft.fillCircle(tx,ty,1,choosenColor); 126 | if (choosenColor != 0) tft.drawPixel(tx,ty,choosenColor); 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/extFontRom/_desktop.ini: -------------------------------------------------------------------------------- 1 | 2015/2/13 -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/extFontRom/extFontRom.ino: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | An example of how use an external ROM chip with RA8875, this time 3 | the ER3303_1 (same as GT23L24T3Y or GT30H24T3Y), an unified chinese 4 | font rom. 5 | In short: 6 | 7 | 1) use setExternalFontRom to set ROM and it's correct encoding 8 | 2) use setFont(EXT) to use the external font 9 | 3) to switch back to internal font ROM, use setFont(INT) 10 | 11 | Library can handle the following Font ROM: 12 | GT21L16T1W, GT21H16T1W, GT23L16U2W, GT30H24T3Y, GT23L24T3Y, GT23L24M1Z, 13 | GT23L32S4W, GT30H32S4W, ER3303_1 14 | Each font ROM has it's encoding so follow font rom datasheet! 15 | 16 | Tested and worked with: 17 | Teensy3,Teensy3.1,Arduino UNO,Arduino YUN,Arduino Leonardo,Stellaris 18 | Works with Arduino 1.0.6 IDE, Arduino 1.5.8 IDE, Energia 0013 IDE 19 | ---------------> http://www.buydisplay.com 20 | ******************************************************************/ 21 | 22 | #include 23 | #include 24 | 25 | //Arduino DUE,Arduino mega2560 26 | #define RA8875_INT 23 27 | #define RA8875_CS 22 28 | 29 | #define RA8875_RESET 24 30 | 31 | //#if defined(NEEDS_SET_MODULE)//Energia, this case is for stellaris/tiva 32 | 33 | //RA8875 tft = RA8875(3);//select SPI module 3 34 | /* 35 | for module 3 (stellaris) 36 | SCLK: PD_0 37 | MOSI: PD_3 38 | MISO: PD_2 39 | SS: PD_1 40 | */ 41 | //#else 42 | 43 | RA8875 tft = RA8875(RA8875_CS,RA8875_RESET);//Teensy3/arduino's 44 | 45 | //#endif 46 | 47 | uint16_t tx, ty; 48 | 49 | void setup() 50 | { 51 | Serial.begin(9600); 52 | //while (!Serial) {;} 53 | Serial.println("RA8875 start"); 54 | tft.begin(RA8875_480x272); 55 | 56 | tft.changeMode(TEXT); 57 | tft.setTextColor(RA8875_WHITE); 58 | //now set the external rom font ER3303_1 an unified chinese font chip, 59 | //it contains also some ASCII char and use GB12345 encoding. 60 | //It's important to read your font chip datasheet or you will 61 | //get from nothing ti garbage on screen! 62 | tft.setExternalFontRom(ER3303_1,GB12345); 63 | //switch to external rom 64 | tft.setFont(EXT); 65 | //now write some chinese.... 66 | //note that when using ext font chip the size will be X24 67 | //since most of font maps are 24x24. 68 | tft.print("ÉîÛÚÐñÈÕ¶«·½¿Æ¼¼ÓÐÏÞ¹«Ë¾"); // 69 | //the X16 sixe of ROM ER3303_1 can also use ASCII... 70 | tft.setFontSize(X16);//switch to X16 71 | tft.setTextColor(RA8875_RED); 72 | tft.setCursor(0,50); 73 | tft.println("ABCD 1234567890"); //I will use println this time! 74 | //switch to internal rom 75 | tft.setFont(INT); 76 | tft.setTextColor(RA8875_GREEN); 77 | tft.println("www.buydisplay.com"); 78 | //not bad neh? you can use different encodings without use 79 | //any MCU memory, just add an hardware font chip and istruct library. 80 | tft.setFont(EXT); 81 | //you can switching back on the fly to EXT 82 | tft.print("ÉîÛÚÐñÈÕ¶«·½¿Æ¼¼ÓÐÏÞ¹«Ë¾"); 83 | //voilà 84 | } 85 | 86 | void loop() 87 | { 88 | } 89 | -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/graphicAdaTest/_desktop.ini: -------------------------------------------------------------------------------- 1 | 2015/2/13 -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/horizontalVU_usingLayers/_desktop.ini: -------------------------------------------------------------------------------- 1 | 2015/2/13 -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/horizontalVU_usingLayers/horizontalVU_usingLayers.ino: -------------------------------------------------------------------------------- 1 | /* 2 | An old school example of how to use layers and graphic boolean operation 3 | for fast display several vu meter bars. 4 | The Colored bars are created once all together, they are masked by an AND 5 | operation by 2 different rectangles, one white act as passTrough from the origin point to the value, 6 | another black rectangle starting from the value to the end of the colored bar. 7 | As result the operation it's really fast even on a slow SPI. 8 | Created by Max MC Costa for s.u.m.o.t.o.y 9 | 10 | BEWARE! If you have an 800x480 or 640x480 display this example --> DO NOT WORK! <-- 11 | Why? It's a limitation of RA8875 chip, at these resolutions no layers! Cannot be solved, 12 | even working at 256 colors (bleah!) there's still limitations! so...peace of mind... 13 | 14 | Tested and worked with: 15 | Teensy3,Teensy3.1,Arduino UNO,Arduino YUN,Arduino Leonardo,Stellaris 16 | Works with Arduino 1.0.6 IDE, Arduino 1.5.8 IDE, Energia 0013 IDE 17 | ---------------> http://www.buydisplay.com 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | //Arduino DUE,Arduino mega2560 24 | #define RA8875_INT 23 25 | #define RA8875_CS 22 26 | 27 | #define RA8875_RESET 24 28 | 29 | //#if defined(NEEDS_SET_MODULE)//Energia, this case is for stellaris/tiva 30 | 31 | //RA8875 tft = RA8875(3);//select SPI module 3 32 | /* 33 | for module 3 (stellaris) 34 | SCLK: PD_0 35 | MOSI: PD_3 36 | MISO: PD_2 37 | SS: PD_1 38 | */ 39 | //#else 40 | 41 | RA8875 tft = RA8875(RA8875_CS,RA8875_RESET);//Teensy3/arduino's 42 | 43 | //#endif 44 | 45 | 46 | uint8_t segW = 2; 47 | uint8_t barH = 15; 48 | 49 | //this draw the masking bar(s) 50 | void drawHbarVal(uint16_t originX,uint16_t originY,uint8_t segments,uint8_t maxVal){ 51 | //tft.fillRect(originX+segW*(2*segments-1)+2,originY+2,segW,barH-4,RA8875_WHITE);//single dot 52 | tft.fillRect(originX+2,originY+2,segW*(2*segments-1),barH-4,RA8875_WHITE); 53 | tft.fillRect(originX+2+segW*(2*segments-1),originY+2,(2+segW*(2*maxVal-1))-(segW*(2*segments-1)+2),barH-4,RA8875_BLACK); 54 | tft.drawRect(originX,originY,segW*(2*maxVal-1)+4,barH,tft.Color565(255,255,255)); 55 | } 56 | 57 | //draw the colored bar 58 | void drawHbar(uint16_t originX,uint16_t originY,uint8_t segments,uint8_t maxVal){ 59 | uint16_t spacer = 0; 60 | uint8_t div = maxVal/4; 61 | uint8_t rc,gc,bc; 62 | for (uint8_t i=0;i 0) spacer = segW*(2*i); 64 | rc = map(i,0,maxVal,100,255); 65 | gc = map(i,maxVal,0,100,255); 66 | if (i >= div && i <= div*2){ 67 | bc = map(i,0,div*2,0,180); 68 | } 69 | else if (i >= div*2 && i <= div*3){ 70 | bc = map(i,div*2,div*3,180,0); 71 | } 72 | else { 73 | bc = 0; 74 | } 75 | tft.fillRect(originX+spacer+2,originY+2,segW,barH-4,tft.Color565(bc,gc,rc)); 76 | } 77 | tft.drawRect(originX,originY,segW*(2*maxVal-1)+4,barH,tft.Color565(100,100,100)); 78 | } 79 | 80 | 81 | 82 | void setup() 83 | { 84 | Serial.begin(9600); 85 | //while (!Serial) {;} 86 | Serial.println("RA8875 start"); 87 | 88 | tft.begin(RA8875_480x272); 89 | tft.useLayers(true);//turn on layers 90 | tft.writeTo(L1);//write colored bars to layer 1 91 | //create ONCE all colored bars 92 | drawHbar(10,10,100,100); 93 | drawHbar(10,30,50,50); 94 | drawHbar(10,50,80,80); 95 | drawHbar(10,70,80,80); 96 | drawHbar(10,90,80,80); 97 | drawHbar(10,110,80,80); 98 | drawHbar(10,130,80,80); 99 | drawHbar(10,150,80,80); 100 | drawHbar(10,170,80,80); 101 | drawHbar(10,190,80,80); 102 | drawHbar(10,210,80,80); 103 | drawHbar(10,230,80,80); 104 | tft.writeTo(L2);//from this point we write on layer 2 105 | tft.layerEffect(AND);//apply AND effect between layer 1 and 2 106 | } 107 | 108 | void loop() 109 | { tft.changeMode(TEXT); 110 | tft.setTextColor(RA8875_WHITE,RA8875_RED); 111 | tft.setCursor (0, 400); 112 | tft.print ("www.buydisplay.com"); 113 | tft.changeMode(GRAPHIC); 114 | //now draw the masking bars on layer 2 115 | for (int i=0;i<=100;i++){ 116 | drawHbarVal(10,10,i,100); 117 | drawHbarVal(10,30,random(0,50),50); 118 | drawHbarVal(10,50,random(0,80),80); 119 | drawHbarVal(10,70,random(0,80),80); 120 | drawHbarVal(10,90,random(0,80),80); 121 | drawHbarVal(10,110,random(0,80),80); 122 | drawHbarVal(10,130,random(0,80),80); 123 | drawHbarVal(10,150,random(0,80),80); 124 | drawHbarVal(10,170,random(0,80),80); 125 | drawHbarVal(10,190,random(0,80),80); 126 | drawHbarVal(10,210,random(0,80),80); 127 | drawHbarVal(10,230,random(0,80),80); 128 | delay(50); 129 | } 130 | for (int i=100;i>=0;i--){ 131 | drawHbarVal(10,10,i,100); 132 | drawHbarVal(10,30,random(0,50),50); 133 | drawHbarVal(10,50,random(0,80),80); 134 | drawHbarVal(10,70,random(0,80),80); 135 | drawHbarVal(10,90,random(0,80),80); 136 | drawHbarVal(10,110,random(0,80),80); 137 | drawHbarVal(10,130,random(0,80),80); 138 | drawHbarVal(10,150,random(0,80),80); 139 | drawHbarVal(10,170,random(0,80),80); 140 | drawHbarVal(10,190,random(0,80),80); 141 | drawHbarVal(10,210,random(0,80),80); 142 | drawHbarVal(10,230,random(0,80),80); 143 | delay(50); 144 | } 145 | 146 | } 147 | 148 | -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/mandelbrot/_desktop.ini: -------------------------------------------------------------------------------- 1 | 2015/2/13 -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/mandelbrot/mandelbrot.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Another example adapted from ugfx http://ugfx.org 3 | ---------------> http://www.buydisplay.com 4 | This actually shows a problem of RA8875 library, writing 5 | one pixel it's fast but write many single pixels in the same time 6 | not and speed suffer. 7 | It shoul be a workaround that I'm actually study, this will fix 8 | also loading big images from SD memory card and so on. 9 | Tested and worked with: 10 | Teensy3,Teensy3.1,Arduino UNO,Arduino YUN,Arduino Leonardo,Stellaris 11 | Works with Arduino 1.0.6 IDE, Arduino 1.5.8 IDE, Energia 0013 IDE 12 | */ 13 | #include 14 | #include 15 | 16 | 17 | //Arduino DUE,Arduino mega2560 18 | #define RA8875_INT 23 19 | #define RA8875_CS 22 20 | 21 | #define RA8875_RESET 24 22 | 23 | //#if defined(NEEDS_SET_MODULE)//Energia, this case is for stellaris/tiva 24 | 25 | //RA8875 tft = RA8875(3);//select SPI module 3 26 | /* 27 | for module 3 (stellaris) 28 | SCLK: PD_0 29 | MOSI: PD_3 30 | MISO: PD_2 31 | SS: PD_1 32 | */ 33 | //#else 34 | 35 | RA8875 tft = RA8875(RA8875_CS,RA8875_RESET); 36 | 37 | //#endif 38 | 39 | const int MAX = 256; 40 | float cx, cy; 41 | float zoom = 1.0f; 42 | 43 | 44 | void mandelbrot(float x1, float y1, float x2, float y2) { 45 | unsigned int i,j; 46 | uint16_t iter; 47 | uint16_t color; 48 | 49 | float sy = y2 - y1; 50 | float sx = x2 - x1; 51 | 52 | for(i = 0; i < tft.width(); i++) { 53 | for(j = 0; j < tft.height(); j++) { 54 | float cy = j * sy / tft.height() + y1; 55 | float cx = i * sx / tft.width() + x1; 56 | float x = 0.0f, y = 0.0f, xx = 0.0f, yy = 0.0f; 57 | for(iter=0; iter <= MAX && (xx + yy) < 4.0f; iter++) { 58 | xx = x * x; 59 | yy = y * y; 60 | y = 2.0f * x * y + cy; 61 | x = xx - yy + cx; 62 | } 63 | color = ((iter<<7 & 0xF8) << 8) | ((iter<<4 & 0xFC) << 3) | (iter >> 3); 64 | tft.drawPixel(i, j, color); 65 | } 66 | } 67 | } 68 | 69 | void setup() 70 | { 71 | Serial.begin(9600); 72 | //while (!Serial) {;} 73 | Serial.println("RA8875 start"); 74 | 75 | /* Initialise the display using 'RA8875_480x272' or 'RA8875_800x480' */ 76 | tft.begin(RA8875_480x272); 77 | 78 | cx = -0.086f; 79 | cy = 0.85f; 80 | } 81 | 82 | 83 | void loop() 84 | { tft.changeMode(TEXT); 85 | tft.setTextColor(RA8875_WHITE); 86 | tft.setCursor (0, 0); 87 | tft.print ("www.buydisplay.com"); 88 | tft.changeMode(GRAPHIC); 89 | mandelbrot(-2.0f*zoom+cx, -1.5f*zoom+cy, 2.0f*zoom+cx, 1.5f*zoom+cy); 90 | zoom *= 0.7f; 91 | if(zoom <= 0.00001f) 92 | zoom = 1.0f; 93 | } 94 | -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/moodBackground/_desktop.ini: -------------------------------------------------------------------------------- 1 | 2015/2/13 -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/moodBackground/moodBackground.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Modulate background color 3 | Tested and worked with: 4 | Teensy3,Teensy3.1,Arduino UNO,Arduino YUN,Arduino Leonardo,Stellaris 5 | Works with Arduino 1.0.6 IDE, Arduino 1.5.8 IDE, Energia 0013 IDE 6 | ---------------> http://www.buydisplay.com 7 | */ 8 | #include 9 | #include 10 | 11 | //Arduino DUE,Arduino mega2560 12 | #define RA8875_INT 23 13 | #define RA8875_CS 22 14 | 15 | #define RA8875_RESET 24 16 | 17 | //#if defined(NEEDS_SET_MODULE)//Energia, this case is for stellaris/tiva 18 | 19 | //RA8875 tft = RA8875(3);//select SPI module 3 20 | /* 21 | for module 3 (stellaris) 22 | SCLK: PD_0 23 | MOSI: PD_3 24 | MISO: PD_2 25 | SS: PD_1 26 | */ 27 | //#else 28 | 29 | RA8875 tft = RA8875(RA8875_CS,RA8875_RESET);//Teensy3/arduino's 30 | 31 | //#endif 32 | 33 | 34 | float angle; 35 | 36 | void setup() 37 | { 38 | tft.begin(RA8875_480x272); 39 | 40 | } 41 | 42 | // Translate a hue "angle" -120 to 120 degrees (ie -2PI/3 to 2PI/3) to 43 | // a 6-bit R channel value 44 | // 45 | // This is very slow on a microcontroller, not a great example! 46 | inline int angle_to_channel(float a) { 47 | if (a < -PI) a += 2*PI; 48 | if (a < -2*PI/3 || a > 2*PI/3) return 0; 49 | float f_channel = cos(a*3/4); // remap 120-degree 0-1.0 to 90 ?? 50 | return ceil(f_channel * 255);//63 51 | } 52 | 53 | void loop() { 54 | tft.changeMode(TEXT); 55 | tft.setTextColor(RA8875_WHITE); 56 | tft.setCursor (0, 0); 57 | tft.print ("www.buydisplay.com"); 58 | tft.changeMode(GRAPHIC); 59 | uint16_t clr = (((angle_to_channel(angle-4*PI/3)>>1) & 0xF8) << 8) | (((angle_to_channel(angle-2*PI/3)) & 0xFC) << 3) | ((angle_to_channel(angle)>>1) >> 3); 60 | tft.fillScreen(clr); 61 | 62 | angle += 0.01; 63 | if(angle > PI) 64 | angle -= 2*PI; 65 | } 66 | -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/scroll/_desktop.ini: -------------------------------------------------------------------------------- 1 | 2015/2/13 -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/scroll/scroll.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Basic Scroll example 3 | Tested and worked with: 4 | Teensy3,Teensy3.1,Arduino UNO,Arduino YUN,Arduino Leonardo,Stellaris 5 | Works with Arduino 1.0.6 IDE, Arduino 1.5.8 IDE, Energia 0013 IDE 6 | ---------------> http://www.buydisplay.com 7 | */ 8 | 9 | 10 | #include 11 | #include 12 | 13 | //Arduino DUE,Arduino mega2560 14 | #define RA8875_INT 23 15 | #define RA8875_CS 22 16 | 17 | #define RA8875_RESET 24 18 | 19 | //#if defined(NEEDS_SET_MODULE)//Energia, this case is for stellaris/tiva 20 | 21 | //RA8875 tft = RA8875(3);//select SPI module 3 22 | /* 23 | for module 3 (stellaris) 24 | SCLK: PD_0 25 | MOSI: PD_3 26 | MISO: PD_2 27 | SS: PD_1 28 | */ 29 | //#else 30 | 31 | RA8875 tft = RA8875(RA8875_CS,RA8875_RESET);//Teensy3/arduino's 32 | 33 | //#endif 34 | 35 | 36 | void setup() 37 | { 38 | Serial.begin(9600); 39 | //while (!Serial) {;} 40 | Serial.println("RA8875 start"); 41 | //initialization routine 42 | tft.begin(RA8875_480x272); 43 | 44 | //following it's already by begin function but 45 | //if you like another background color.... 46 | tft.fillScreen(RA8875_BLACK);//fill screen black 47 | 48 | //RA8875 it's capable to draw graphic but also Text 49 | //here we switch to TEXT mode 50 | tft.changeMode(TEXT); 51 | //now set a text color, background transparent 52 | tft.setTextColor(RA8875_WHITE); 53 | //use the classic print an println command 54 | tft.print("www.buydisplay.com"); 55 | //by default the text location is set to 0,0 56 | //now set it at 50,20 pixels and different color 57 | tft.setCursor(50,20);//set cursor work in pixel!!! 58 | //this time we not using transparent background 59 | tft.setTextColor(RA8875_RED,RA8875_GREEN); 60 | tft.print("www.buydisplay.com"); 61 | //by default we using the internal font 62 | //so some manipulation it's possible 63 | tft.setFontScale(1);//font x2 64 | tft.setTextColor(RA8875_RED); 65 | tft.print("Hello World"); 66 | //You notice that font location has been 67 | //automatically increased by chip, unfortunatly not 68 | //tracked by library but we can use a command for that... 69 | uint16_t currentX,currentY; 70 | tft.getCursor(¤tX,¤tY); 71 | //now we have the location, lets draw a white pixel 72 | tft.changeMode(GRAPHIC);//first we swith in graphic mode 73 | tft.drawPixel(currentX,currentY,RA8875_WHITE); 74 | //did you see the white dot? 75 | tft.changeMode(TEXT);//go back to text mode 76 | tft.setFontScale(0);//font x1 77 | tft.setCursor(0,50); 78 | tft.setTextColor(RA8875_YELLOW); 79 | tft.println("ABCDEF 1 2 3 4");//this time println! 80 | tft.setFontSpacing(5);//now give 5 pix spacing 81 | tft.println("ABCDEF 1 2 3 4"); 82 | tft.setFontSpacing(0);//reset 83 | tft.setFontRotate(true); 84 | tft.println("www.buydisplay.com"); 85 | tft.setFontRotate(false); 86 | tft.setFontScale(2);//font x1 87 | tft.setTextColor(RA8875_BLUE,RA8875_BLACK); 88 | } 89 | 90 | uint16_t i = 0; 91 | 92 | void loop() 93 | { 94 | tft.setScrollWindow(0,320,0,60); //Specifies scrolling activity area 95 | i=0; 96 | while(i++<60){ 97 | delay(10); 98 | tft.scroll(i,i); 99 | } //Note: scroll offset value must be less than scroll setting range 100 | while(i-->0){ 101 | delay(10); 102 | tft.scroll(i,i); 103 | } 104 | while(i++<60){ 105 | delay(10); 106 | tft.scroll(i,i); 107 | } 108 | while(i-->0){ 109 | delay(10); 110 | tft.scroll(i,i); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/treedee/_desktop.ini: -------------------------------------------------------------------------------- 1 | 2015/2/13 -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/Examples/treedee/treedee.ino: -------------------------------------------------------------------------------- 1 | /* A 3d rotating cube 2 | Tested and worked with: 3 | Teensy3,Teensy3.1,Arduino UNO,Arduino YUN,Arduino Leonardo,Stellaris 4 | Works with Arduino 1.0.6 IDE, Arduino 1.5.8 IDE, Energia 0013 IDE 5 | ---------------> http://www.buydisplay.com 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | //Arduino DUE 12 | #define RA8875_INT 23 13 | #define RA8875_CS 22 14 | 15 | #define RA8875_RESET 24 16 | 17 | //#if defined(NEEDS_SET_MODULE)//Energia, this case is for stellaris/tiva 18 | 19 | //RA8875 tft = RA8875(3);//select SPI module 3 20 | /* 21 | for module 3 (stellaris) 22 | SCLK: PD_0 23 | MOSI: PD_3 24 | MISO: PD_2 25 | SS: PD_1 26 | */ 27 | //#else 28 | 29 | RA8875 tft = RA8875(RA8875_CS,RA8875_RESET);//Teensy3/arduino's 30 | 31 | //#endif 32 | 33 | 34 | 35 | float sin_d[] = { 36 | 0,0.17,0.34,0.5,0.64,0.77,0.87,0.94,0.98,1,0.98,0.94, 37 | 0.87,0.77,0.64,0.5,0.34,0.17,0,-0.17,-0.34,-0.5,-0.64, 38 | -0.77,-0.87,-0.94,-0.98,-1,-0.98,-0.94,-0.87,-0.77, 39 | -0.64,-0.5,-0.34,-0.17 }; 40 | float cos_d[] = { 41 | 1,0.98,0.94,0.87,0.77,0.64,0.5,0.34,0.17,0,-0.17,-0.34, 42 | -0.5,-0.64,-0.77,-0.87,-0.94,-0.98,-1,-0.98,-0.94,-0.87, 43 | -0.77,-0.64,-0.5,-0.34,-0.17,0,0.17,0.34,0.5,0.64,0.77, 44 | 0.87,0.94,0.98}; 45 | float d = 30; 46 | float px[] = { 47 | -d, d, d, -d, -d, d, d, -d }; 48 | float py[] = { 49 | -d, -d, d, d, -d, -d, d, d }; 50 | float pz[] = { 51 | -d, -d, -d, -d, d, d, d, d }; 52 | 53 | float p2x[] = { 54 | 0,0,0,0,0,0,0,0}; 55 | float p2y[] = { 56 | 0,0,0,0,0,0,0,0}; 57 | 58 | int r[] = { 59 | 0,0,0}; 60 | 61 | void setup() { 62 | Serial.begin(9600); 63 | Serial.println("RA8875 start"); 64 | 65 | tft.begin(RA8875_480x272); 66 | 67 | } 68 | 69 | uint16_t ccolor = RA8875_GREEN; 70 | uint8_t ch = 0; 71 | 72 | void loop(){ 73 | tft.fillScreen(RA8875_BLACK); 74 | r[0]=r[0]+1; 75 | r[1]=r[1]+1; 76 | if (r[0] == 36) r[0] = 0; 77 | if (r[1] == 36) r[1] = 0; 78 | if (r[2] == 36) r[2] = 0; 79 | for (int i=0;i<8;i++) 80 | { 81 | float px2 = px[i]; 82 | float py2 = cos_d[r[0]]*py[i] - sin_d[r[0]]*pz[i]; 83 | float pz2 = sin_d[r[0]]*py[i] + cos_d[r[0]]*pz[i]; 84 | 85 | float px3 = cos_d[r[1]]*px2 + sin_d[r[1]]*pz2; 86 | float py3 = py2; 87 | float pz3 = -sin_d[r[1]]*px2 + cos_d[r[1]]*pz2; 88 | 89 | float ax = cos_d[r[2]]*px3 - sin_d[r[2]]*py3; 90 | float ay = sin_d[r[2]]*px3 + cos_d[r[2]]*py3; 91 | float az = pz3-190; 92 | 93 | p2x[i] = ((tft.width())/2)+ax*500/az; 94 | p2y[i] = ((tft.height())/2)+ay*500/az; 95 | } 96 | for (int i=0;i<3;i++) { 97 | tft.drawLine(p2x[i],p2y[i],p2x[i+1],p2y[i+1],ccolor); 98 | tft.drawLine(p2x[i+4],p2y[i+4],p2x[i+5],p2y[i+5],ccolor); 99 | tft.drawLine(p2x[i],p2y[i],p2x[i+4],p2y[i+4],ccolor); 100 | } 101 | tft.drawLine(p2x[3],p2y[3],p2x[0],p2y[0],ccolor); 102 | tft.drawLine(p2x[7],p2y[7],p2x[4],p2y[4],ccolor); 103 | tft.drawLine(p2x[3],p2y[3],p2x[7],p2y[7],ccolor); 104 | #if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__SAM3X8E__) 105 | delay(40); 106 | #else 107 | delay(10); 108 | #endif 109 | if (ch >=20){ 110 | ch = 0; 111 | ccolor = random(RA8875_BLUE,RA8875_WHITE); 112 | } 113 | else { 114 | ch++; 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/_desktop.ini: -------------------------------------------------------------------------------- 1 | 2015/2/13 -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/_utility/RA8875Calibration.h: -------------------------------------------------------------------------------- 1 | #ifndef _RA8875CAL_H_ 2 | #define _RA8875CAL_H_ 3 | 4 | /* TOUCH SCREEN AXIS INVERSION +++++++++++++++++++++++++++++++++++++++ 5 | Some chinese product have both axis inverted (EastRising), 6 | you can uncomment INVERTETOUCH_Y or INVERTETOUCH_X or both 7 | if your display fall in that case! */ 8 | #define INVERTETOUCH_Y 9 | #define INVERTETOUCH_X 10 | /* TOUCH SCREEN IN PIXELS ++++++++++++++++++++++++++++++++++++++++++++ 11 | Normally Touch Screen return ADC values (0...1024) but decomment 12 | the following it will return values in pixels */ 13 | //#define TOUCHINPIXELS 14 | 15 | /* Calibration Data --------------------------------*/ 16 | /* ------------- TOUCH SCREEN CALIBRATION (how to) ----------- 17 | Touch Screen are not all the same and needs a calibration, you will see 18 | yourself by load touchPaint.ino example, try to paint all over the screen! 19 | If you have space on one or more side you prolly need to calibrate values 20 | ---- perform calibration ---- 21 | To perform the touch screen calibration, load libTouchSCalibration.ino and open serial terminal: 22 | (you have to put data inside RA8875/_utility/RA8875Calibration.h) 23 | 1) the lowest value of x by touch the top/left angle of your tft, put value in TOUCSRCAL_XLOW 24 | 2) you can get the lowest value of y in the same time, put value in TOUCSRCAL_YLOW 25 | 3) the highest value of x by touching the lower/bottom corner of your tft, put the value in TOUCSRCAL_XHIGH 26 | 4) in the same manner you get the max value of y, put that value in TOUCSRCAL_XHIGH 27 | */ 28 | #define TOUCSRCAL_XLOW 0//115 29 | #define TOUCSRCAL_YLOW 0//39 30 | #define TOUCSRCAL_XHIGH 0//926 31 | #define TOUCSRCAL_YHIGH 0//950 32 | 33 | 34 | #endif -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/_utility/_desktop.ini: -------------------------------------------------------------------------------- 1 | 2015/2/13 -------------------------------------------------------------------------------- /libraries/ER-TFTM043-3/keywords.txt: -------------------------------------------------------------------------------- 1 | 2 | ####################################### 3 | # Syntax Coloring Map for RA8875 4 | ####################################### 5 | 6 | ####################################### 7 | # Datatypes (KEYWORD1) 8 | ####################################### 9 | 10 | RA8875 KEYWORD1 11 | 12 | ####################################### 13 | # Methods and Functions (KEYWORD2) 14 | ####################################### 15 | displayOn KEYWORD2 16 | sleep KEYWORD2 17 | brightness KEYWORD2 18 | changeMode KEYWORD2 19 | setActiveWindow KEYWORD2 20 | setForegroundColor KEYWORD2 21 | setBackgroundColor KEYWORD2 22 | setTrasparentColor KEYWORD2 23 | showCursor KEYWORD2 24 | setCursorBlinkRate KEYWORD2 25 | setIntFontCoding KEYWORD2 26 | setXY KEYWORD2 27 | pushPixels KEYWORD2 28 | fillRect KEYWORD2 29 | drawPixel KEYWORD2 30 | drawFastVLine KEYWORD2 31 | drawFastHLine KEYWORD2 32 | fillScreen KEYWORD2 33 | drawLine KEYWORD2 34 | drawRect KEYWORD2 35 | fillRect KEYWORD2 36 | drawCircle KEYWORD2 37 | fillCircle KEYWORD2 38 | drawTriangle KEYWORD2 39 | fillTriangle KEYWORD2 40 | drawEllipse KEYWORD2 41 | fillEllipse KEYWORD2 42 | drawCurve KEYWORD2 43 | fillCurve KEYWORD2 44 | drawRoundRect KEYWORD2 45 | fillRoundRect KEYWORD2 46 | touchBegin KEYWORD2 47 | touchEnable KEYWORD2 48 | touchDetect KEYWORD2 49 | touchReadRaw KEYWORD2 50 | touchReadPixel KEYWORD2 51 | touchCalibrated KEYWORD2 52 | readStatus KEYWORD2 53 | begin KEYWORD2 54 | setCursor KEYWORD2 55 | setTextColor KEYWORD2 56 | setFontSize KEYWORD2 57 | setFontScale KEYWORD2 58 | setFontSpacing KEYWORD2 59 | setExternalFontRom KEYWORD2 60 | setExtFontFamily KEYWORD2 61 | setFontFullAlign KEYWORD2 62 | setFontRotate KEYWORD2 63 | setFontInterline KEYWORD2 64 | uploadUserChar KEYWORD2 65 | showUserChar KEYWORD2 66 | setGraphicCursor KEYWORD2 67 | showGraphicCursor KEYWORD2 68 | getCursor KEYWORD2 69 | width KEYWORD2 70 | height KEYWORD2 71 | setScrollWindow KEYWORD2 72 | scroll KEYWORD2 73 | drawFlashImage KEYWORD2 74 | useLayers KEYWORD2 75 | scanDirection KEYWORD2 76 | writeTo KEYWORD2 77 | layerEffect KEYWORD2 78 | layerTransparency KEYWORD2 79 | writeCommand KEYWORD2 80 | writeData16 KEYWORD2 81 | setX KEYWORD2 82 | setY KEYWORD2 83 | 84 | 85 | ####################################### 86 | # Constants (LITERAL1) 87 | ####################################### 88 | 89 | RA8875_320x240 LITERAL1 90 | RA8875_480x272 LITERAL1 91 | RA8875_800x480 LITERAL1 92 | RA8875_640x480 LITERAL1 93 | Adafruit_480x272 LITERAL1 94 | Adafruit_800x480 LITERAL1 95 | GRAPHIC LITERAL1 96 | TEXT LITERAL1 97 | INT LITERAL1 98 | EXT LITERAL1 99 | ISO_IEC_8859_1 LITERAL1 100 | ISO_IEC_8859_2 LITERAL1 101 | ISO_IEC_8859_3 LITERAL1 102 | ISO_IEC_8859_4 LITERAL1 103 | GT21L16T1W LITERAL1 104 | GT21H16T1W LITERAL1 105 | GT23L16U2W LITERAL1 106 | GT30H24T3Y LITERAL1 107 | GT23L24T3Y LITERAL1 108 | GT23L24M1Z LITERAL1 109 | GT23L32S4W LITERAL1 110 | GT30H32S4W LITERAL1 111 | ER3303_1 LITERAL1 112 | GB2312 LITERAL1 113 | GB12345 LITERAL1 114 | BIG5 LITERAL1 115 | UNICODE LITERAL1 116 | ASCII LITERAL1 117 | UNIJIS LITERAL1 118 | JIS0208 LITERAL1 119 | LATIN LITERAL1 120 | STANDARD LITERAL1 121 | ARIAL LITERAL1 122 | ROMAN LITERAL1 123 | BOLD LITERAL1 124 | LAYER1 LITERAL1 125 | LAYER2 LITERAL1 126 | TRANSPARENT LITERAL1 127 | LIGHTEN LITERAL1 128 | OR LITERAL1 129 | AND LITERAL1 130 | FLOATING LITERAL1 131 | L1 LITERAL1 132 | L2 LITERAL1 133 | CGRAM LITERAL1 134 | PATTERN LITERAL1 135 | CURSOR LITERAL1 136 | NEEDS_SET_MODULE LITERAL1 137 | -------------------------------------------------------------------------------- /libraries/Kemper/AbstractDisplay.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "AbstractDisplay.h" 3 | 4 | USING_NAMESPACE_KEMPER 5 | 6 | /* 7 | void AbstractDisplay::drawText(int16_t x, int16_t y, int16_t size, const char* str, int16_t len, uint16_t color, int16_t rotation, int letterCount) 8 | { 9 | int t = 0; 10 | char* text = textHolder; 11 | strcpy(text, str); 12 | int lastSpace = -1; 13 | int i=0; 14 | int line = 0; 15 | int lineHeight = size; 16 | char* textp = text; 17 | while (iletterCount && lastSpace>=0) { 23 | textp[lastSpace] = 0; 24 | drawText(x -sin(PI*rotation / 18000.0)* line*lineHeight, y + cos(PI*rotation / 18000.0)* line*lineHeight, size, text, strlen(text), color, rotation); 25 | line++; 26 | text = textp + lastSpace+1; 27 | t = i-lastSpace; 28 | lastSpace = -1; 29 | } 30 | t++; 31 | i++; 32 | } 33 | drawText(x-sin(PI*rotation / 18000.0)* line*lineHeight, y + cos(PI*rotation / 18000.0)* line*lineHeight , size, text, strlen(text), color, rotation); 34 | } 35 | */ -------------------------------------------------------------------------------- /libraries/Kemper/AbstractDisplay.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ABSTRACT_DISPLAY_H 3 | #define _ABSTRACT_DISPLAY_H 4 | 5 | #include "Utils.h" 6 | 7 | USING_NAMESPACE_KEMPER 8 | 9 | enum TextAlignVertical {TextAlignTop, TextAlignMiddle, TextAlignBottom}; 10 | enum TextAlignHorizontal {TextAlignLeft, TextAlignCenter, TextAlignRight}; 11 | 12 | class AbstractDisplay 13 | { 14 | private: 15 | char textHolder[128]; 16 | 17 | public: 18 | int width; 19 | int height; 20 | bool supportsLayers; 21 | virtual void writeTo(int layer) {}; 22 | virtual void setTransparentColor(uint16_t color) {}; 23 | virtual void layerEffect(int layerEffect) {}; 24 | virtual void clearRect(int16_t x, int16_t y, int16_t w, int16_t h) {}; 25 | virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) = 0; 26 | virtual void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color) = 0; 27 | virtual void fillRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t radius, uint16_t color) = 0; 28 | virtual void drawText(int16_t x, int16_t y, int16_t w, int16_t h, TextAlignHorizontal horAlign, TextAlignVertical verAlign, int16_t size, const char* text, int16_t len, uint16_t color) = 0; 29 | //virtual void drawText(int16_t x, int16_t y, int16_t size, const char* text, int16_t len, uint16_t color, int16_t rotation) = 0; 30 | //void drawText(int16_t x, int16_t y, int16_t size, const char* str, int16_t len, uint16_t color, int16_t rotation, int letterCount); 31 | }; 32 | 33 | #endif -------------------------------------------------------------------------------- /libraries/Kemper/AbstractDisplaySerializer.h: -------------------------------------------------------------------------------- 1 | #ifndef _ABSTRACT_DISPLAY_SERIALIZER_H 2 | #define _ABSTRACT_DISPLAY_SERIALIZER_H 3 | 4 | #include "Arduino.h" 5 | #include "Utils.h" 6 | #include "AbstractDisplaySerializer.h" 7 | 8 | class AbstractDisplaySerializer 9 | { 10 | public: 11 | virtual int transferByte(uint8_t a) = 0; 12 | virtual int transfer(uint16_t a) = 0; 13 | virtual int transferString(const char *text) = 0; 14 | 15 | virtual void start() = 0; 16 | virtual void end() = 0; 17 | }; 18 | 19 | #endif -------------------------------------------------------------------------------- /libraries/Kemper/AbstractKemper.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Kemper.h 3 | * Project Arduino Kemper MIDI Library 4 | * @brief Kemper MIDI Library for the Arduino 5 | * @version 1.0 6 | * @author Ersin Basaran 7 | * @date 16/07/15 8 | * @license GPL v3.0 9 | */ 10 | #ifndef _ABSTRACT_KEMPER_H 11 | #define _ABSTRACT_KEMPER_H 12 | 13 | #include "Arduino.h" 14 | 15 | #include "Kemper_namespace.h" 16 | #include "Stomp.h" 17 | 18 | BEGIN_KEMPER_NAMESPACE 19 | 20 | #define KEMPER_MIDI_CHANNEL 1 21 | 22 | #define RIG_COUNT 100 23 | #define KEMPER_STOMP_COUNT 8 24 | 25 | #define MODE_NONE 0 26 | #define MODE_TUNER 1 27 | #define MODE_BROWSE 2 28 | #define MODE_PERFORM 3 29 | #define MODE_PROFILE 4 30 | 31 | const byte CC_WAH = 1; 32 | const byte CC_PITCH = 4; 33 | const byte CC_VOLUME = 7; 34 | const byte CC_DELAY_MIX = 68; 35 | const byte CC_DELAY_FEEDBACK = 69; 36 | const byte CC_REVERB_MIX = 70; 37 | const byte CC_REVERB_TIME = 71; 38 | const byte CC_GAIN = 72; 39 | const byte CC_MONITOR_VOLUME = 73; 40 | 41 | 42 | #define LOOPER_STATE_EMPTY 0 43 | #define LOOPER_STATE_RECORDING 1 44 | #define LOOPER_STATE_RECORDING_UNDO 2 45 | #define LOOPER_STATE_PLAYBACK 3 46 | #define LOOPER_STATE_OVERDUB 4 47 | #define LOOPER_STATE_STOPPED 5 48 | #define LOOPER_STATE_ERASED 6 49 | 50 | struct LooperState 51 | { 52 | int state; 53 | bool isHalfTime; 54 | bool isReversed; 55 | unsigned long recordPressTime; 56 | unsigned long erasePressTime; 57 | byte erasePressCount; 58 | bool atLestOneLayer; 59 | }; 60 | 61 | struct KemperState 62 | { 63 | StompState stomps[KEMPER_STOMP_COUNT]; 64 | int key; 65 | int tune; 66 | bool tempoLed; 67 | bool tempoEnabled; 68 | int tempo; 69 | char rigName[20]; 70 | byte currentRig; 71 | byte mode; 72 | 73 | byte bank; 74 | byte program; 75 | byte performance; 76 | byte slot; 77 | bool senseReceived; 78 | 79 | LooperState looperState; 80 | 81 | unsigned int parameterState; 82 | 83 | char performanceNames[6][20]; 84 | }; 85 | 86 | class AbstractKemper 87 | { 88 | public: 89 | AbstractKemper(); 90 | 91 | KemperState state; 92 | PartialParameter parameter; 93 | //int AllParameters[KEMPER_STOMP_COUNT][MAX_KEMPER_PARAM_LENGTH][2]; 94 | unsigned long lastStompParamTime; 95 | int lastStompParam[3]; 96 | 97 | void loadPartialParam(int stompIdx); 98 | void movePartialParam(int paramOffset, int optionOffset); 99 | void setPartialParamValue(float value); 100 | virtual void getStompParameter(int stompIdx, int paramNumber) = 0; 101 | 102 | virtual void read() = 0; 103 | 104 | virtual void tunerOn() = 0; 105 | virtual void tunerOff() = 0; 106 | virtual void tapOn() = 0; 107 | virtual void tapOff() = 0; 108 | 109 | virtual void looperRecordPlayDown(); 110 | virtual void looperRecordPlayUp(); 111 | virtual void looperReverseDown(); 112 | virtual void looperReverseUp(); 113 | virtual void looperHalfTimeDown(); 114 | virtual void looperHalfTimeUp(); 115 | virtual void looperUndoDown(); 116 | virtual void looperUndoUp(); 117 | virtual void looperStopEraseDown(); 118 | virtual void looperStopEraseUp(); 119 | virtual void looperTriggerDown(); 120 | virtual void looperTriggerUp(); 121 | 122 | virtual void sendControlChange(byte data1, byte data2) = 0; 123 | virtual void setStompParam(int stompIdx, byte number, int val) = 0; 124 | virtual void toggleStomp(byte idx) = 0; 125 | virtual void setPerformance(int idx, int slot = 0) = 0; 126 | virtual void setRig(byte rig) = 0; 127 | }; 128 | 129 | 130 | 131 | END_KEMPER_NAMESPACE 132 | 133 | #endif -------------------------------------------------------------------------------- /libraries/Kemper/Display_ER_RA8875.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/basarane/kemper-arduino-library/1e5e416610921f6aa660a6cfafa02a7d5fe2a1ba/libraries/Kemper/Display_ER_RA8875.h -------------------------------------------------------------------------------- /libraries/Kemper/ExpressionPedal.cpp: -------------------------------------------------------------------------------- 1 | #include "ExpressionPedal.h" 2 | 3 | USING_NAMESPACE_KEMPER 4 | 5 | 6 | void ExpressionPedal::begin(int _pin) 7 | { 8 | pin = _pin; 9 | minValue = 1024; 10 | maxValue = -1; 11 | lastValuesIndex = 0; 12 | mode = CC_VOLUME; 13 | simValue = -1; 14 | //pinMode(pin, INPUT_PULLUP); 15 | } 16 | 17 | int ExpressionPedal::read() 18 | { 19 | if (millis() - lastRead > 3 + (pin%4)) // analog read'lerde faz farki olsun diye 20 | { 21 | int raw = analogRead(pin); 22 | if (simValue >= 0) 23 | raw = simValue; 24 | value = raw; 25 | if (value > EXPRESSION_PEDAL_THRESHOLD) { 26 | lastValues[lastValuesIndex] = value; 27 | lastValuesIndex = (lastValuesIndex+1)%EXPRESSION_PEDAL_HISTORY_LENGTH; 28 | } 29 | lastRead = millis(); 30 | } 31 | return value; 32 | } 33 | 34 | void ExpressionPedal::calibrate() { 35 | if (value>=EXPRESSION_PEDAL_THRESHOLD) { 36 | int minV = -1; 37 | int maxV = 1024; 38 | for (int i=0;i EXPRESSION_PEDAL_THRESHOLD) 41 | { 42 | minV = max(minV, lastValues[i]); 43 | maxV = min(maxV, lastValues[i]); 44 | } 45 | } 46 | minValue = min(minValue, minV + EXPRESSION_PEDAL_CALIBRATE_MARGIN); 47 | maxValue = max(maxValue, maxV - EXPRESSION_PEDAL_CALIBRATE_MARGIN); 48 | } 49 | } 50 | 51 | int ExpressionPedal::calibratedValue() { 52 | float val = 0; 53 | if (maxValue > minValue) 54 | { 55 | val = 1024.0*(value - minValue) / (maxValue - minValue); 56 | val = max(val, 0); 57 | val = min(val, 1023); 58 | } 59 | return (int)val; 60 | } 61 | 62 | bool ExpressionPedal::isCalibrated() { 63 | return minValue 6 | 7 | #include "Utils.h" 8 | #include 9 | 10 | BEGIN_KEMPER_NAMESPACE 11 | 12 | #define EXPRESSION_PEDAL_1_PIN 0 13 | #define EXPRESSION_PEDAL_2_PIN 1 14 | #define EXPRESSION_PEDAL_3_PIN 2 15 | #define EXPRESSION_PEDAL_4_PIN 3 16 | 17 | #define PARAMETER_BUFFER_ALL_SIZE 1024 18 | #define PARAMETER_BUFFER_SIZE 128 19 | 20 | #define SWITCH_RIG_START 0 21 | #define SWITCH_STOMP_START 5 22 | #define SWITCH_STOMP_COUNT 4 23 | #define SWITCH_RIG_COUNT 5 24 | #define SWITCH_TAP 9 25 | #define SWITCH_TUNER 10 26 | #define SWITCH_LOOPER 11 27 | #define SWITCH_UP 12 28 | #define SWITCH_DOWN 13 29 | #define SWITCH_COUNT 14 30 | 31 | #define BROWSE_PAGE_COUNT ((byte)ceil((float)RIG_COUNT/SWITCH_RIG_COUNT)) 32 | 33 | #define REMOTE_PARAMETER_STATE_PARAMETER 0 34 | #define REMOTE_PARAMETER_STATE_EXPRESSION 1 35 | #define REMOTE_PARAMETER_STATE_VALUE 2 36 | 37 | #define REMOTE_STATE_NORMAL 1 38 | #define REMOTE_STATE_STOMP_ASSIGN 2 39 | #define REMOTE_STATE_RIG_ASSIGN 3 40 | #define REMOTE_STATE_LOOPER 4 41 | #define REMOTE_STATE_TEMPO_DETECTION 5 42 | #define REMOTE_STATE_EXPRESSION_CALIBRATE 6 43 | #define REMOTE_STATE_STOMP_PARAMETER 7 44 | #define REMOTE_STATE_STOMP_PARAMETER_LOAD 8 45 | #define REMOTE_STATE_STOMP_PARAMETER_POST_LOAD 9 46 | 47 | #define LED_COUNT 26 48 | 49 | #define PERFORM_SLOT_COUNT 5 50 | 51 | #define EXPRESSION_PEDAL_COUNT 4 52 | 53 | #define EXPRESSION_PEDAL_MODE_PARAMETER -1 54 | 55 | extern int ExpressionPedalModes[4]; 56 | 57 | struct KemperRemoteState 58 | { 59 | int state; 60 | int previousState; 61 | byte currentPage; 62 | byte currentPerformance; 63 | byte currentSlot; 64 | bool isSaved; 65 | int parameterState; 66 | byte* currentParameters; 67 | bool currentParametersChanged; 68 | unsigned long expPedalState; 69 | }; 70 | 71 | 72 | class KemperRemote 73 | { 74 | private: 75 | byte currentRig; 76 | byte stompAssignment[SWITCH_RIG_COUNT][SWITCH_STOMP_COUNT]; 77 | byte stompAssignmentPerform[PERFORM_SLOT_COUNT][SWITCH_STOMP_COUNT]; 78 | 79 | int currentSwitch; 80 | bool switchStates[SWITCH_COUNT]; 81 | unsigned long switchDownStart; 82 | byte saveUpDown; 83 | bool initialStompStates[KEMPER_STOMP_COUNT]; 84 | bool changedStomps[KEMPER_STOMP_COUNT]; 85 | byte rigAssignRig; 86 | 87 | byte rigMap[RIG_COUNT]; 88 | 89 | int lastStompTypes[KEMPER_STOMP_COUNT]; 90 | 91 | int oldStompParameters[KEMPER_STOMP_COUNT][MAX_KEMPER_PARAM_LENGTH][2]; 92 | int newStompParameters[KEMPER_STOMP_COUNT][MAX_KEMPER_PARAM_LENGTH][2]; 93 | byte parameterBuffer[PARAMETER_BUFFER_SIZE]; 94 | int eepromParameterBufferStart; 95 | void updateCurrentParameter(byte perf, byte slot); 96 | 97 | void refreshStompAssignment(); 98 | void checkSwitchDownLong(); 99 | void checkUpDownScroll(); 100 | void checkStompChanges(); 101 | void updateLeds(); 102 | 103 | bool changeExpPedalMode(); 104 | void updateExpPedalModes(); 105 | public: 106 | 107 | ExpressionPedal expPedals[EXPRESSION_PEDAL_COUNT]; 108 | int calibratePedalId; 109 | 110 | byte leds[LED_COUNT * 3]; 111 | byte rigAssignSwitch; 112 | byte currentStompAssignment[SWITCH_STOMP_COUNT]; 113 | KemperRemoteState state; 114 | 115 | AbstractKemper* kemper; 116 | KemperRemote(AbstractKemper* _kemper); 117 | void read(); 118 | 119 | void onSwitchDown(int sw); 120 | void onSwitchUp(int sw); 121 | 122 | void onStompDown(int switchIdx); 123 | void onStompUp(int switchIdx); 124 | void onRigDown(int switchIdx); 125 | void onRigUp(int switchIdx); 126 | 127 | void assignStomps(byte switchId, byte assign); 128 | void assignRig(byte switchId, byte rig); 129 | 130 | byte getRigIndex(byte rig); 131 | 132 | void save(); 133 | }; 134 | 135 | END_KEMPER_NAMESPACE -------------------------------------------------------------------------------- /libraries/Kemper/KemperRemoteDisplay.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "VirtualDisplay.h" 4 | 5 | #include "Kemper_namespace.h" 6 | 7 | #include "AbstractKemper.h" 8 | #include "KemperRemote.h" 9 | #include "AbstractDisplay.h" 10 | 11 | #include "Utils.h" 12 | 13 | BEGIN_KEMPER_NAMESPACE 14 | 15 | class KemperRemoteDisplay { 16 | public: 17 | KemperState lastKemperState; 18 | KemperRemoteState lastKemperRemoteState; 19 | KemperRemoteDisplay(AbstractKemper* _kemper, KemperRemote* _kemperRemote, AbstractDisplay* _display); 20 | AbstractKemper* kemper; 21 | KemperRemote* kemperRemote; 22 | AbstractDisplay* display; 23 | 24 | unsigned long lastTempoTime; 25 | unsigned long lastTunerTime; 26 | unsigned long lastDisplay; 27 | unsigned int writeToLayer; 28 | int firstRun; 29 | 30 | void welcome(); 31 | void draw(); 32 | }; 33 | 34 | END_KEMPER_NAMESPACE -------------------------------------------------------------------------------- /libraries/Kemper/Kemper_namespace.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | 5 | #define KEMPER_NAMESPACE KEMPER 6 | #define BEGIN_KEMPER_NAMESPACE namespace KEMPER_NAMESPACE { 7 | #define END_KEMPER_NAMESPACE } 8 | 9 | #define USING_NAMESPACE_KEMPER using namespace KEMPER_NAMESPACE; 10 | 11 | -------------------------------------------------------------------------------- /libraries/Kemper/Stomp.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #pragma once 4 | 5 | 6 | #include "Arduino.h" 7 | 8 | #include "Kemper_namespace.h" 9 | 10 | BEGIN_KEMPER_NAMESPACE 11 | 12 | struct Color 13 | { 14 | byte r; 15 | byte g; 16 | byte b; 17 | }; 18 | 19 | struct KemperParamOption 20 | { 21 | int value; 22 | char name[20]; 23 | }; 24 | 25 | struct KemperParamValue 26 | { 27 | byte id; 28 | float minValue; 29 | float maxValue; 30 | int maxParam; 31 | char suffix[3]; 32 | bool exponential; 33 | bool special; 34 | }; 35 | 36 | struct PGM_KemperParam 37 | { 38 | int number; 39 | char name[32]; 40 | int optionCount; 41 | const KemperParamOption* const* options; 42 | const KemperParamValue* value; 43 | }; 44 | 45 | struct PGM_StompInfo 46 | { 47 | int type; 48 | Color color; 49 | char name[20]; 50 | int paramCount; 51 | const PGM_KemperParam* const* params; 52 | byte isExpWah; 53 | byte isExpPitch; 54 | }; 55 | 56 | struct KemperParam 57 | { 58 | int number; 59 | char name[32]; 60 | int optionCount; 61 | }; 62 | 63 | struct StompInfo 64 | { 65 | unsigned int PGM_index; 66 | int type; 67 | Color color; 68 | char name[20]; 69 | int paramCount; 70 | byte isExpWah; 71 | byte isExpPitch; 72 | }; 73 | 74 | struct StompState 75 | { 76 | bool active; 77 | bool dirty; 78 | StompInfo info; 79 | }; 80 | 81 | 82 | #define NUMBER_OF_PARAMS_IN_LIST 5 83 | #define NUMBER_OF_OPTIONS_IN_LIST 5 84 | 85 | struct PartialParameter 86 | { 87 | int paramCount; 88 | int currentParam; 89 | int totalParamCount; 90 | int startParamIndex; 91 | 92 | int optionCount; 93 | int currentOption; 94 | int currentValue; 95 | int totalOptionCount; 96 | int startOptionIndex; 97 | bool isActive; 98 | 99 | StompInfo* stompInfo; 100 | int stompIdx; 101 | int stompType; 102 | KemperParam params[NUMBER_OF_PARAMS_IN_LIST]; 103 | KemperParamOption options[NUMBER_OF_PARAMS_IN_LIST]; 104 | KemperParamValue valueType; 105 | }; 106 | 107 | #define AllStompsCount 64 108 | 109 | #define ColorNone {0xCC, 0xCC, 0xCC} 110 | #define ColorWhite {0xFF, 0xFF, 0xFF} 111 | #define ColorOrange {0xFF, 0xA5, 0x00} 112 | #define ColorYellow {0xFF, 0xFF, 0x00} 113 | #define ColorCyan {0x00, 0xFF, 0xFF} 114 | #define ColorBlue {0x00, 0x00, 0xFF} 115 | #define ColorPurple {0x80, 0x00, 0x80} 116 | #define ColorGreen {0x00, 0xFF, 0x00} 117 | #define ColorLightGreen {0xA0, 0xFF, 0xA0} 118 | #define ColorRed {0xFF, 0x00, 0x00} 119 | 120 | 121 | #include "Stomp_consts.h" 122 | 123 | bool loadStompInfo(StompInfo *dst, int stompId, int id); 124 | void loadStompParameters(PartialParameter *parameter, StompInfo *info = 0); 125 | bool updateStompParameterValue(PartialParameter *parameter, int value); 126 | int getOptionValue(PartialParameter *parameter, int optionIndex); 127 | 128 | void testParam(int a, int b); 129 | 130 | 131 | END_KEMPER_NAMESPACE -------------------------------------------------------------------------------- /libraries/Kemper/Utils.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Utils.h" 3 | 4 | 5 | #ifndef ARDUINO 6 | #define ITOA _itoa 7 | #else 8 | #define ITOA itoa 9 | #endif 10 | 11 | #ifdef ARDUINO 12 | 13 | void KEMPER_NAMESPACE::debug(const __FlashStringHelper* str) { 14 | #ifndef KEMPER_DEBUG 15 | Serial.write(0xF1); 16 | Serial.print(str); 17 | Serial.write(0xFF); 18 | Serial.flush(); 19 | #endif 20 | } 21 | 22 | 23 | void KEMPER_NAMESPACE::debug2(const __FlashStringHelper* str) { 24 | #ifdef KEMPER_DEBUG 25 | Serial.println(str); 26 | #endif 27 | } 28 | #endif 29 | 30 | void KEMPER_NAMESPACE::debug(const char* str) { 31 | #ifndef KEMPER_DEBUG 32 | Serial.write(0xF1); 33 | Serial.print(str); 34 | Serial.write(0xFF); 35 | Serial.flush(); 36 | #endif 37 | } 38 | 39 | void KEMPER_NAMESPACE::debug2(const char* str) { 40 | #ifdef KEMPER_DEBUG 41 | Serial.println(str); 42 | #endif 43 | } 44 | 45 | 46 | void KEMPER_NAMESPACE::debug(int x) { 47 | #ifndef KEMPER_DEBUG 48 | Serial.write(0xF1); 49 | Serial.print(x); 50 | Serial.write(0xFF); 51 | Serial.flush(); 52 | #endif 53 | } 54 | 55 | void KEMPER_NAMESPACE::debug(long x) { 56 | #ifndef KEMPER_DEBUG 57 | Serial.write(0xF1); 58 | Serial.print(x); 59 | Serial.write(0xFF); 60 | Serial.flush(); 61 | #endif 62 | } 63 | void KEMPER_NAMESPACE::debug(byte a) { 64 | #ifndef KEMPER_DEBUG 65 | Serial.write(0xF1); 66 | Serial.print(a); 67 | Serial.write(0xFF); 68 | Serial.flush(); 69 | #endif 70 | } 71 | 72 | int KEMPER_NAMESPACE::getColor(byte r, byte g, byte b) { 73 | //return (((int)r>>3)<<11) | (((int)g>>2)<<5) | (b>>3); // 16 bit 74 | return (((int)r>>4)<<10) | (((int)g>>3)<<5) | (b>>3); // 14 bit 75 | } 76 | 77 | char *KEMPER_NAMESPACE::ftoa(char *a, double f, int precision) 78 | { 79 | long p[] = {0,10,100,1000,10000,100000,1000000,10000000,100000000}; 80 | 81 | char *ret = a; 82 | long heiltal = (long)f; 83 | ITOA(heiltal, a, 10); 84 | while (*a != '\0') a++; 85 | *a++ = '.'; 86 | long desimal = abs((long)((f - heiltal) * p[precision])); 87 | ITOA(desimal, a, 10); 88 | return ret; 89 | } 90 | -------------------------------------------------------------------------------- /libraries/Kemper/Utils.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Kemper_namespace.h" 5 | #include "Arduino.h" 6 | 7 | //#define abs(x) ((x)<0?(-(x)):(x)) 8 | //#define KEMPER_DEBUG 9 | 10 | BEGIN_KEMPER_NAMESPACE 11 | 12 | #ifdef ARDUINO 13 | void debug(const __FlashStringHelper* str); 14 | void debug2(const __FlashStringHelper* str); 15 | #endif 16 | 17 | void debug(const char* str); 18 | void debug(long x); 19 | void debug(int x); 20 | void debug(byte a); 21 | void debug2(const char* str); 22 | 23 | int getColor(byte r, byte g, byte b); 24 | 25 | char *ftoa(char *a, double f, int precision); 26 | 27 | END_KEMPER_NAMESPACE -------------------------------------------------------------------------------- /libraries/Kemper/VirtualDisplay.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "VirtualDisplaySerializer.h" 3 | #include "VirtualDisplay.h" 4 | #include 5 | 6 | 7 | VirtualDisplay::VirtualDisplay(AbstractDisplaySerializer* _Serial, int _width, int _height) { 8 | Serializer = _Serial; 9 | width = _width; 10 | height = _height; 11 | } 12 | 13 | void VirtualDisplay::drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) 14 | { 15 | rectHelper(x, y, x+w, y+h, 0, color, false); 16 | } 17 | 18 | void VirtualDisplay::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) 19 | { 20 | rectHelper(x, y, x+w, y+h, 0, color, true); 21 | } 22 | void VirtualDisplay::fillRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t radius, uint16_t color) { 23 | rectHelper(x, y, x+w, y+h, radius, color, true); 24 | } 25 | 26 | void VirtualDisplay::rectHelper(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t radius, uint16_t color, bool filled) 27 | { 28 | //return; 29 | Serializer->start(); 30 | Serializer->transfer((int16_t)1); 31 | Serializer->transfer(x); 32 | Serializer->transfer(y); 33 | Serializer->transfer(w); 34 | Serializer->transfer(h); 35 | Serializer->transfer(radius); 36 | Serializer->transfer(color); 37 | Serializer->transfer(filled?1:0); 38 | Serializer->end(); 39 | } 40 | 41 | void VirtualDisplay::fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color) { 42 | Serializer->start(); 43 | Serializer->transfer((int16_t)3); 44 | Serializer->transfer(x0); 45 | Serializer->transfer(y0); 46 | Serializer->transfer(x1); 47 | Serializer->transfer(y1); 48 | Serializer->transfer(x2); 49 | Serializer->transfer(y2); 50 | Serializer->transfer(color); 51 | Serializer->end(); 52 | } 53 | 54 | 55 | /* 56 | void VirtualDisplay::drawText(int16_t x, int16_t y, int16_t size, const char* text, int16_t len, uint16_t color, int16_t rotation) 57 | { 58 | //return; 59 | Serializer->start(); 60 | Serializer->transfer((int16_t)2); 61 | Serializer->transfer(x); 62 | Serializer->transfer(y); 63 | Serializer->transfer(size); 64 | Serializer->transfer(color); 65 | Serializer->transfer(rotation); 66 | Serializer->transfer(len); 67 | for (int i=0;itransfer(text[i]); 69 | Serializer->end(); 70 | //Serial->transferString(text); 71 | } 72 | */ 73 | void VirtualDisplay::drawText(int16_t x, int16_t y, int16_t w, int16_t h, TextAlignHorizontal horAlign, TextAlignVertical verAlign, int16_t size, const char* text, int16_t len, uint16_t color) { 74 | Serializer->start(); 75 | Serializer->transfer((int16_t)2); 76 | Serializer->transfer(x); 77 | Serializer->transfer(y); 78 | Serializer->transfer(w); 79 | Serializer->transfer(h); 80 | Serializer->transfer((uint16_t)horAlign); 81 | Serializer->transfer((uint16_t)verAlign); 82 | Serializer->transfer(size); 83 | Serializer->transfer(color); 84 | Serializer->transfer(len); 85 | for (int i=0;itransfer(text[i]); 87 | Serializer->end(); 88 | } -------------------------------------------------------------------------------- /libraries/Kemper/VirtualDisplay.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "AbstractDisplay.h" 4 | #include "VirtualDisplaySerializer.h" 5 | 6 | 7 | class VirtualDisplay : public AbstractDisplay { 8 | public: 9 | VirtualDisplay(AbstractDisplaySerializer* _Serial, int _width, int _height); 10 | AbstractDisplaySerializer* Serializer; 11 | 12 | void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); 13 | void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); 14 | void fillRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t radius, uint16_t color); 15 | void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); 16 | 17 | //void drawText(int16_t x, int16_t y, int16_t size, const char* text, int16_t len, uint16_t color, int16_t rotation); 18 | //void drawText(int16_t x, int16_t y, int16_t size, const char* str, int16_t len, uint16_t color, int16_t rotation, int letterCount); 19 | void drawText(int16_t x, int16_t y, int16_t w, int16_t h, TextAlignHorizontal horAlign, TextAlignVertical verAlign, int16_t size, const char* text, int16_t len, uint16_t color); 20 | 21 | void rectHelper (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t radius, uint16_t color, bool filled); 22 | }; 23 | -------------------------------------------------------------------------------- /libraries/Kemper/VirtualDisplaySerializer.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "VirtualDisplaySerializer.h" 3 | 4 | VirtualDisplaySerializer::VirtualDisplaySerializer(HardwareSerial* _Serial) 5 | { 6 | Serial = _Serial; 7 | } 8 | 9 | int VirtualDisplaySerializer::transferByte(uint8_t a) { 10 | if (a>0x7f) { 11 | //KEMPER_NAMESPACE::debug("ERROR!!! SPI byte"); 12 | //KEMPER_NAMESPACE::debug(a); 13 | } 14 | Serial->write(a); 15 | //Serial->write(a >> 4); 16 | //Serial->write(a & 0xf); 17 | return 0; 18 | } 19 | 20 | int VirtualDisplaySerializer::transfer(uint16_t a) { 21 | transferByte((uint8_t)(a>>7)); 22 | transferByte((uint8_t)(a & 0x7f)); 23 | //transferByte((uint8_t)(a>>8)); 24 | //transferByte((uint8_t)(a & 0xff)); 25 | return 0; 26 | } 27 | 28 | int VirtualDisplaySerializer::transfer(uint32_t a) { 29 | transfer((uint16_t)(a>>14)); 30 | transfer((uint16_t)(a & 0x3fff)); 31 | return 0; 32 | } 33 | 34 | int VirtualDisplaySerializer::transferString(const char* text) { 35 | return 0; 36 | } 37 | 38 | void VirtualDisplaySerializer::start() { 39 | Serial->write(0xf2); 40 | } 41 | 42 | void VirtualDisplaySerializer::end() { 43 | Serial->write(0xff); 44 | Serial->flush(); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /libraries/Kemper/VirtualDisplaySerializer.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "AbstractDisplaySerializer.h" 5 | 6 | class VirtualDisplaySerializer : public AbstractDisplaySerializer 7 | { 8 | private: 9 | HardwareSerial* Serial; 10 | public: 11 | VirtualDisplaySerializer(HardwareSerial* _Serial); 12 | int transferByte(uint8_t a); 13 | int transfer(uint16_t a); 14 | int transfer(uint32_t a); 15 | int transferString(const char* text); 16 | 17 | void start(); 18 | void end(); 19 | }; 20 | 21 | -------------------------------------------------------------------------------- /libraries/MIDI/MIDI.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file MIDI.cpp 3 | * Project Arduino MIDI Library 4 | * @brief MIDI Library for the Arduino 5 | * @version 4.2 6 | * @author Francois Best 7 | * @date 24/02/11 8 | * @license GPL v3.0 - Copyright Forty Seven Effects 2014 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #include "MIDI.h" 25 | 26 | // ----------------------------------------------------------------------------- 27 | 28 | BEGIN_MIDI_NAMESPACE 29 | 30 | /*! \brief Encode System Exclusive messages. 31 | SysEx messages are encoded to guarantee transmission of data bytes higher than 32 | 127 without breaking the MIDI protocol. Use this static method to convert the 33 | data you want to send. 34 | \param inData The data to encode. 35 | \param outSysEx The output buffer where to store the encoded message. 36 | \param inLength The lenght of the input buffer. 37 | \return The lenght of the encoded output buffer. 38 | @see decodeSysEx 39 | Code inspired from Ruin & Wesen's SysEx encoder/decoder - http://ruinwesen.com 40 | */ 41 | unsigned encodeSysEx(const byte* inData, byte* outSysEx, unsigned inLength) 42 | { 43 | unsigned outLength = 0; // Num bytes in output array. 44 | byte count = 0; // Num 7bytes in a block. 45 | outSysEx[0] = 0; 46 | 47 | for (unsigned i = 0; i < inLength; ++i) 48 | { 49 | const byte data = inData[i]; 50 | const byte msb = data >> 7; 51 | const byte body = data & 0x7f; 52 | 53 | outSysEx[0] |= (msb << count); 54 | outSysEx[1 + count] = body; 55 | 56 | if (count++ == 6) 57 | { 58 | outSysEx += 8; 59 | outLength += 8; 60 | outSysEx[0] = 0; 61 | count = 0; 62 | } 63 | } 64 | return outLength + count + (count != 0 ? 1 : 0); 65 | } 66 | 67 | /*! \brief Decode System Exclusive messages. 68 | SysEx messages are encoded to guarantee transmission of data bytes higher than 69 | 127 without breaking the MIDI protocol. Use this static method to reassemble 70 | your received message. 71 | \param inSysEx The SysEx data received from MIDI in. 72 | \param outData The output buffer where to store the decrypted message. 73 | \param inLength The lenght of the input buffer. 74 | \return The lenght of the output buffer. 75 | @see encodeSysEx @see getSysExArrayLength 76 | Code inspired from Ruin & Wesen's SysEx encoder/decoder - http://ruinwesen.com 77 | */ 78 | unsigned decodeSysEx(const byte* inSysEx, byte* outData, unsigned inLength) 79 | { 80 | unsigned count = 0; 81 | byte msbStorage = 0; 82 | 83 | for (unsigned i = 0; i < inLength; ++i) 84 | { 85 | if ((i % 8) == 0) 86 | { 87 | msbStorage = inSysEx[i]; 88 | } 89 | else 90 | { 91 | outData[count++] = inSysEx[i] | ((msbStorage & 1) << 7); 92 | msbStorage >>= 1; 93 | } 94 | } 95 | return count; 96 | } 97 | 98 | END_MIDI_NAMESPACE 99 | -------------------------------------------------------------------------------- /libraries/MIDI/examples/MIDI_Basic_IO/MIDI_Basic_IO.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Simple tutorial on how to receive and send MIDI messages. 4 | // Here, when receiving any message on channel 4, the Arduino 5 | // will blink a led and play back a note for 1 second. 6 | 7 | MIDI_CREATE_DEFAULT_INSTANCE(); 8 | 9 | #define LED 13 // LED pin on Arduino Uno 10 | 11 | void setup() 12 | { 13 | pinMode(LED, OUTPUT); 14 | MIDI.begin(4); // Launch MIDI and listen to channel 4 15 | } 16 | 17 | void loop() 18 | { 19 | if (MIDI.read()) // If we have received a message 20 | { 21 | digitalWrite(LED,HIGH); 22 | MIDI.sendNoteOn(42,127,1); // Send a Note (pitch 42, velo 127 on channel 1) 23 | delay(1000); // Wait for a second 24 | MIDI.sendNoteOff(42,0,1); // Stop the note 25 | digitalWrite(LED,LOW); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /libraries/MIDI/examples/MIDI_Bench/MIDI_Bench.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // This program will measure the time needed to receive, parse and process a 4 | // NoteOn message. 5 | // For it to work, please connect RX and TX on the MIDI port: 6 | // Due, Leonardo and other USB-native Arduinos: Serial1 7 | // All other Arduinos: Connect pins 2 and 3. 8 | // The program will then wait for 100 loops and print the results. 9 | 10 | #if defined(ARDUINO_SAM_DUE) || defined(USBCON) 11 | // Print through USB and bench with Hardware serial 12 | MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, midiBench); 13 | #else 14 | #include 15 | SoftwareSerial midiSerial(2,3); 16 | MIDI_CREATE_INSTANCE(SoftwareSerial, midiSerial, midiBench); 17 | #endif 18 | 19 | // ----------------------------------------------------------------------------- 20 | 21 | unsigned long gTime_start = 0; 22 | unsigned long gTime_stop = 0; 23 | unsigned gCounter = 0; 24 | unsigned long gTime_sum = 0; 25 | unsigned long gTime_min = -1; 26 | unsigned long gTime_max = 0; 27 | 28 | // ----------------------------------------------------------------------------- 29 | 30 | void handleNoteOn(byte inChannel, byte inNote, byte inVelocity) 31 | { 32 | gTime_stop = micros(); 33 | 34 | const unsigned long diff = gTime_stop - gTime_start; 35 | gTime_sum += diff; 36 | 37 | if (diff > gTime_max) gTime_max = diff; 38 | if (diff < gTime_min) gTime_min = diff; 39 | 40 | if (gCounter++ >= 1000) 41 | { 42 | const unsigned long average = gTime_sum / (float)gCounter; 43 | 44 | Serial.println("Time to receive NoteOn: "); 45 | 46 | Serial.print("Average: "); 47 | Serial.print(average); 48 | Serial.println(" microsecs"); 49 | 50 | Serial.print("Min: "); 51 | Serial.print(gTime_min); 52 | Serial.println(" microsecs"); 53 | 54 | Serial.print("Max: "); 55 | Serial.print(gTime_max); 56 | Serial.println(" microsecs"); 57 | 58 | gCounter = 0; 59 | gTime_sum = 0; 60 | gTime_max = 0; 61 | gTime_min = -1; 62 | 63 | midiBench.turnThruOff(); 64 | } 65 | } 66 | 67 | // ----------------------------------------------------------------------------- 68 | 69 | void setup() 70 | { 71 | midiBench.setHandleNoteOn(handleNoteOn); 72 | midiBench.begin(); 73 | 74 | while(!Serial); 75 | Serial.begin(115200); 76 | Serial.println("Arduino Ready"); 77 | 78 | midiBench.sendNoteOn(69,127,1); 79 | } 80 | 81 | void loop() 82 | { 83 | gTime_start = micros(); 84 | midiBench.read(); 85 | } 86 | -------------------------------------------------------------------------------- /libraries/MIDI/examples/MIDI_Callbacks/MIDI_Callbacks.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | MIDI_CREATE_DEFAULT_INSTANCE(); 4 | 5 | // ----------------------------------------------------------------------------- 6 | 7 | // This function will be automatically called when a NoteOn is received. 8 | // It must be a void-returning function with the correct parameters, 9 | // see documentation here: 10 | // http://arduinomidilib.fortyseveneffects.com/a00022.html 11 | 12 | void handleNoteOn(byte channel, byte pitch, byte velocity) 13 | { 14 | // Do whatever you want when a note is pressed. 15 | 16 | // Try to keep your callbacks short (no delays ect) 17 | // otherwise it would slow down the loop() and have a bad impact 18 | // on real-time performance. 19 | } 20 | 21 | void handleNoteOff(byte channel, byte pitch, byte velocity) 22 | { 23 | // Do something when the note is released. 24 | // Note that NoteOn messages with 0 velocity are interpreted as NoteOffs. 25 | } 26 | 27 | // ----------------------------------------------------------------------------- 28 | 29 | void setup() 30 | { 31 | // Connect the handleNoteOn function to the library, 32 | // so it is called upon reception of a NoteOn. 33 | MIDI.setHandleNoteOn(handleNoteOn); // Put only the name of the function 34 | 35 | // Do the same for NoteOffs 36 | MIDI.setHandleNoteOff(handleNoteOff); 37 | 38 | // Initiate MIDI communications, listen to all channels 39 | MIDI.begin(MIDI_CHANNEL_OMNI); 40 | } 41 | 42 | void loop() 43 | { 44 | // Call MIDI.read the fastest you can for real-time performance. 45 | MIDI.read(); 46 | 47 | // There is no need to check if there are messages incoming 48 | // if they are bound to a Callback function. 49 | // The attached method will be called automatically 50 | // when the corresponding message has been received. 51 | } 52 | -------------------------------------------------------------------------------- /libraries/MIDI/examples/MIDI_DualMerger/MIDI_DualMerger.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // This example shows how to create two instances of the library to create a merger. 4 | // There are two MIDI couples of IO, A and B, each using thru and merging with the 5 | // input from the other node. The result is the following: 6 | // A out = A in + B in 7 | // B out = B in + A in 8 | 9 | #ifdef ARDUINO_SAM_DUE 10 | MIDI_CREATE_INSTANCE(HardwareSerial, Serial, midiA); 11 | MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, midiB); 12 | #else 13 | #include 14 | SoftwareSerial softSerial(2,3); 15 | MIDI_CREATE_INSTANCE(HardwareSerial, Serial, midiA); 16 | MIDI_CREATE_INSTANCE(SoftwareSerial, softSerial, midiB); 17 | #endif 18 | 19 | void setup() 20 | { 21 | // Initiate MIDI communications, listen to all channels 22 | midiA.begin(MIDI_CHANNEL_OMNI); 23 | midiB.begin(MIDI_CHANNEL_OMNI); 24 | } 25 | 26 | void loop() 27 | { 28 | if (midiA.read()) 29 | { 30 | // Thru on A has already pushed the input message to out A. 31 | // Forward the message to out B as well. 32 | midiB.send(midiA.getType(), 33 | midiA.getData1(), 34 | midiA.getData2(), 35 | midiA.getChannel()); 36 | } 37 | 38 | if (midiB.read()) 39 | { 40 | // Thru on B has already pushed the input message to out B. 41 | // Forward the message to out A as well. 42 | midiA.send(midiB.getType(), 43 | midiB.getData1(), 44 | midiB.getData2(), 45 | midiB.getChannel()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /libraries/MIDI/examples/MIDI_Input/MIDI_Input.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | MIDI_CREATE_DEFAULT_INSTANCE(); 4 | 5 | // ----------------------------------------------------------------------------- 6 | 7 | // This example shows the old way of checking for input messages. 8 | // It's simpler to use the callbacks now, check out the dedicated example. 9 | 10 | #define LED 13 // LED pin on Arduino Uno 11 | 12 | // ----------------------------------------------------------------------------- 13 | 14 | void BlinkLed(byte num) // Basic blink function 15 | { 16 | for (byte i=0;i 2 | #include "noteList.h" 3 | #include "pitches.h" 4 | 5 | MIDI_CREATE_DEFAULT_INSTANCE(); 6 | 7 | #ifdef ARDUINO_SAM_DUE // Due has no tone function (yet), overriden to prevent build errors. 8 | #define tone(...) 9 | #define noTone(...) 10 | #endif 11 | 12 | // This example shows how to make a simple synth out of an Arduino, using the 13 | // tone() function. It also outputs a gate signal for controlling external 14 | // analog synth components (like envelopes). 15 | 16 | static const unsigned sGatePin = 13; 17 | static const unsigned sAudioOutPin = 10; 18 | static const unsigned sMaxNumNotes = 16; 19 | MidiNoteList midiNotes; 20 | 21 | // ----------------------------------------------------------------------------- 22 | 23 | inline void handleGateChanged(bool inGateActive) 24 | { 25 | digitalWrite(sGatePin, inGateActive ? HIGH : LOW); 26 | } 27 | 28 | inline void pulseGate() 29 | { 30 | handleGateChanged(false); 31 | delay(1); 32 | handleGateChanged(true); 33 | } 34 | 35 | // ----------------------------------------------------------------------------- 36 | 37 | void handleNotesChanged(bool isFirstNote = false) 38 | { 39 | if (midiNotes.empty()) 40 | { 41 | handleGateChanged(false); 42 | noTone(sAudioOutPin); 43 | } 44 | else 45 | { 46 | // Possible playing modes: 47 | // Mono Low: use midiNotes.getLow 48 | // Mono High: use midiNotes.getHigh 49 | // Mono Last: use midiNotes.getLast 50 | 51 | byte currentNote = 0; 52 | if (midiNotes.getLast(currentNote)) 53 | { 54 | tone(sAudioOutPin, sNotePitches[currentNote]); 55 | 56 | if (isFirstNote) 57 | { 58 | handleGateChanged(true); 59 | } 60 | else 61 | { 62 | pulseGate(); // Retrigger envelopes. Remove for legato effect. 63 | } 64 | } 65 | } 66 | } 67 | 68 | // ----------------------------------------------------------------------------- 69 | 70 | void handleNoteOn(byte inChannel, byte inNote, byte inVelocity) 71 | { 72 | const bool firstNote = midiNotes.empty(); 73 | midiNotes.add(MidiNote(inNote, inVelocity)); 74 | handleNotesChanged(firstNote); 75 | } 76 | 77 | void handleNoteOff(byte inChannel, byte inNote, byte inVelocity) 78 | { 79 | midiNotes.remove(inNote); 80 | handleNotesChanged(); 81 | } 82 | 83 | // ----------------------------------------------------------------------------- 84 | 85 | void setup() 86 | { 87 | pinMode(sGatePin, OUTPUT); 88 | pinMode(sAudioOutPin, OUTPUT); 89 | MIDI.setHandleNoteOn(handleNoteOn); 90 | MIDI.setHandleNoteOff(handleNoteOff); 91 | MIDI.begin(); 92 | } 93 | 94 | void loop() 95 | { 96 | MIDI.read(); 97 | } 98 | -------------------------------------------------------------------------------- /libraries/MIDI/examples/MIDI_SimpleSynth/noteList.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * \file synth-core_NoteList.h 3 | * \author Francois Best 4 | * \date 24/05/2013 5 | * \license GPL v3.0 - Copyright Forty Seven Effects 2013 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #include "noteList.h" 22 | -------------------------------------------------------------------------------- /libraries/MIDI/examples/MIDI_SimpleSynth/pitches.h: -------------------------------------------------------------------------------- 1 | /************************************************* 2 | * Public Constants 3 | *************************************************/ 4 | #include 5 | 6 | #define NOTE_B0 31 7 | #define NOTE_C1 33 8 | #define NOTE_CS1 35 9 | #define NOTE_D1 37 10 | #define NOTE_DS1 39 11 | #define NOTE_E1 41 12 | #define NOTE_F1 44 13 | #define NOTE_FS1 46 14 | #define NOTE_G1 49 15 | #define NOTE_GS1 52 16 | #define NOTE_A1 55 17 | #define NOTE_AS1 58 18 | #define NOTE_B1 62 19 | #define NOTE_C2 65 20 | #define NOTE_CS2 69 21 | #define NOTE_D2 73 22 | #define NOTE_DS2 78 23 | #define NOTE_E2 82 24 | #define NOTE_F2 87 25 | #define NOTE_FS2 93 26 | #define NOTE_G2 98 27 | #define NOTE_GS2 104 28 | #define NOTE_A2 110 29 | #define NOTE_AS2 117 30 | #define NOTE_B2 123 31 | #define NOTE_C3 131 32 | #define NOTE_CS3 139 33 | #define NOTE_D3 147 34 | #define NOTE_DS3 156 35 | #define NOTE_E3 165 36 | #define NOTE_F3 175 37 | #define NOTE_FS3 185 38 | #define NOTE_G3 196 39 | #define NOTE_GS3 208 40 | #define NOTE_A3 220 41 | #define NOTE_AS3 233 42 | #define NOTE_B3 247 43 | #define NOTE_C4 262 44 | #define NOTE_CS4 277 45 | #define NOTE_D4 294 46 | #define NOTE_DS4 311 47 | #define NOTE_E4 330 48 | #define NOTE_F4 349 49 | #define NOTE_FS4 370 50 | #define NOTE_G4 392 51 | #define NOTE_GS4 415 52 | #define NOTE_A4 440 53 | #define NOTE_AS4 466 54 | #define NOTE_B4 494 55 | #define NOTE_C5 523 56 | #define NOTE_CS5 554 57 | #define NOTE_D5 587 58 | #define NOTE_DS5 622 59 | #define NOTE_E5 659 60 | #define NOTE_F5 698 61 | #define NOTE_FS5 740 62 | #define NOTE_G5 784 63 | #define NOTE_GS5 831 64 | #define NOTE_A5 880 65 | #define NOTE_AS5 932 66 | #define NOTE_B5 988 67 | #define NOTE_C6 1047 68 | #define NOTE_CS6 1109 69 | #define NOTE_D6 1175 70 | #define NOTE_DS6 1245 71 | #define NOTE_E6 1319 72 | #define NOTE_F6 1397 73 | #define NOTE_FS6 1480 74 | #define NOTE_G6 1568 75 | #define NOTE_GS6 1661 76 | #define NOTE_A6 1760 77 | #define NOTE_AS6 1865 78 | #define NOTE_B6 1976 79 | #define NOTE_C7 2093 80 | #define NOTE_CS7 2217 81 | #define NOTE_D7 2349 82 | #define NOTE_DS7 2489 83 | #define NOTE_E7 2637 84 | #define NOTE_F7 2794 85 | #define NOTE_FS7 2960 86 | #define NOTE_G7 3136 87 | #define NOTE_GS7 3322 88 | #define NOTE_A7 3520 89 | #define NOTE_AS7 3729 90 | #define NOTE_B7 3951 91 | #define NOTE_C8 4186 92 | #define NOTE_CS8 4435 93 | #define NOTE_D8 4699 94 | #define NOTE_DS8 4978 95 | 96 | static const uint16_t sNotePitches[] = { 97 | NOTE_B0, NOTE_C1, NOTE_CS1, NOTE_D1, NOTE_DS1, NOTE_E1, NOTE_F1, NOTE_FS1, 98 | NOTE_G1, NOTE_GS1, NOTE_A1, NOTE_AS1, NOTE_B1, NOTE_C2, NOTE_CS2, NOTE_D2, 99 | NOTE_DS2, NOTE_E2, NOTE_F2, NOTE_FS2, NOTE_G2, NOTE_GS2, NOTE_A2, NOTE_AS2, 100 | NOTE_B2, NOTE_C3, NOTE_CS3, NOTE_D3, NOTE_DS3, NOTE_E3, NOTE_F3, NOTE_FS3, 101 | NOTE_G3, NOTE_GS3, NOTE_A3, NOTE_AS3, NOTE_B3, NOTE_C4, NOTE_CS4, NOTE_D4, 102 | NOTE_DS4, NOTE_E4, NOTE_F4, NOTE_FS4, NOTE_G4, NOTE_GS4, NOTE_A4, NOTE_AS4, 103 | NOTE_B4, NOTE_C5, NOTE_CS5, NOTE_D5, NOTE_DS5, NOTE_E5, NOTE_F5, NOTE_FS5, 104 | NOTE_G5, NOTE_GS5, NOTE_A5, NOTE_AS5, NOTE_B5, NOTE_C6, NOTE_CS6, NOTE_D6, 105 | NOTE_DS6, NOTE_E6, NOTE_F6, NOTE_FS6, NOTE_G6, NOTE_GS6, NOTE_A6, NOTE_AS6, 106 | NOTE_B6, NOTE_C7, NOTE_CS7, NOTE_D7, NOTE_DS7, NOTE_E7, NOTE_F7, NOTE_FS7, 107 | NOTE_G7, NOTE_GS7, NOTE_A7, NOTE_AS7, NOTE_B7, NOTE_C8, NOTE_CS8, NOTE_D8, NOTE_DS8, 108 | }; 109 | -------------------------------------------------------------------------------- /libraries/MIDI/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Test 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | MIDI KEYWORD1 10 | MIDI.h KEYWORD1 11 | MidiInterface KEYWORD1 12 | DefaultSettings KEYWORD1 13 | 14 | ####################################### 15 | # Methods and Functions (KEYWORD2) 16 | ####################################### 17 | 18 | send KEYWORD2 19 | sendNoteOn KEYWORD2 20 | sendNoteOff KEYWORD2 21 | sendProgramChange KEYWORD2 22 | sendControlChange KEYWORD2 23 | sendPitchBend KEYWORD2 24 | sendPolyPressure KEYWORD2 25 | sendAfterTouch KEYWORD2 26 | sendSysEx KEYWORD2 27 | sendTimeCodeQuarterFrame KEYWORD2 28 | sendSongPosition KEYWORD2 29 | sendSongSelect KEYWORD2 30 | sendTuneRequest KEYWORD2 31 | sendRealTime KEYWORD2 32 | begin KEYWORD2 33 | read KEYWORD2 34 | getType KEYWORD2 35 | getChannel KEYWORD2 36 | getData1 KEYWORD2 37 | getData2 KEYWORD2 38 | getSysExArray KEYWORD2 39 | getFilterMode KEYWORD2 40 | getThruState KEYWORD2 41 | getInputChannel KEYWORD2 42 | check KEYWORD2 43 | delMsg KEYWORD2 44 | delSysEx KEYWORD2 45 | setInputChannel KEYWORD2 46 | setStatus KEYWORD2 47 | turnThruOn KEYWORD2 48 | turnThruOff KEYWORD2 49 | setThruFilterMode KEYWORD2 50 | disconnectCallbackFromType KEYWORD2 51 | setHandleNoteOff KEYWORD2 52 | setHandleNoteOn KEYWORD2 53 | setHandleAfterTouchPoly KEYWORD2 54 | setHandleControlChange KEYWORD2 55 | setHandleProgramChange KEYWORD2 56 | setHandleAfterTouchChannel KEYWORD2 57 | setHandlePitchBend KEYWORD2 58 | setHandleSystemExclusive KEYWORD2 59 | setHandleTimeCodeQuarterFrame KEYWORD2 60 | setHandleSongPosition KEYWORD2 61 | setHandleSongSelect KEYWORD2 62 | setHandleTuneRequest KEYWORD2 63 | setHandleClock KEYWORD2 64 | setHandleStart KEYWORD2 65 | setHandleContinue KEYWORD2 66 | setHandleStop KEYWORD2 67 | setHandleActiveSensing KEYWORD2 68 | setHandleSystemReset KEYWORD2 69 | getTypeFromStatusByte KEYWORD2 70 | encodeSysEx KEYWORD2 71 | decodeSysEx KEYWORD2 72 | 73 | 74 | ####################################### 75 | # Instances (KEYWORD2) 76 | ####################################### 77 | 78 | ####################################### 79 | # Constants (LITERAL1) 80 | ####################################### 81 | 82 | # Namespace, considering it as a literal 83 | midi LITERAL1 84 | 85 | NoteOff LITERAL1 86 | NoteOn LITERAL1 87 | AfterTouchPoly LITERAL1 88 | ControlChange LITERAL1 89 | ProgramChange LITERAL1 90 | AfterTouchChannel LITERAL1 91 | PitchBend LITERAL1 92 | SystemExclusive LITERAL1 93 | TimeCodeQuarterFrame LITERAL1 94 | SongPosition LITERAL1 95 | SongSelect LITERAL1 96 | TuneRequest LITERAL1 97 | Clock LITERAL1 98 | Start LITERAL1 99 | Stop LITERAL1 100 | Continue LITERAL1 101 | ActiveSensing LITERAL1 102 | SystemReset LITERAL1 103 | InvalidType LITERAL1 104 | Off LITERAL1 105 | Full LITERAL1 106 | SameChannel LITERAL1 107 | DifferentChannel LITERAL1 108 | MIDI_CHANNEL_OMNI LITERAL1 109 | MIDI_CHANNEL_OFF LITERAL1 110 | MIDI_CREATE_INSTANCE LITERAL1 111 | MIDI_CREATE_DEFAULT_INSTANCE LITERAL1 112 | MIDI_CREATE_CUSTOM_INSTANCE LITERAL1 113 | -------------------------------------------------------------------------------- /libraries/MIDI/midi_Message.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file midi_Message.h 3 | * Project Arduino MIDI Library 4 | * @brief MIDI Library for the Arduino - Message struct definition 5 | * @version 4.2 6 | * @author Francois Best 7 | * @date 11/06/14 8 | * @license GPL v3.0 - Copyright Forty Seven Effects 2014 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #pragma once 25 | 26 | #include "midi_Namespace.h" 27 | #include "midi_Defs.h" 28 | 29 | BEGIN_MIDI_NAMESPACE 30 | 31 | /*! The Message structure contains decoded data of a MIDI message 32 | read from the serial port with read() 33 | */ 34 | template 35 | struct Message 36 | { 37 | /*! The maximum size for the System Exclusive array. 38 | */ 39 | static const unsigned sSysExMaxSize = SysExMaxSize; 40 | 41 | /*! The MIDI channel on which the message was recieved. 42 | \n Value goes from 1 to 16. 43 | */ 44 | Channel channel; 45 | 46 | /*! The type of the message 47 | (see the MidiType enum for types reference) 48 | */ 49 | MidiType type; 50 | 51 | /*! The first data byte. 52 | \n Value goes from 0 to 127. 53 | */ 54 | DataByte data1; 55 | 56 | /*! The second data byte. 57 | If the message is only 2 bytes long, this one is null. 58 | \n Value goes from 0 to 127. 59 | */ 60 | DataByte data2; 61 | 62 | /*! System Exclusive dedicated byte array. 63 | \n Array length is stocked on 16 bits, 64 | in data1 (LSB) and data2 (MSB) 65 | */ 66 | DataByte sysexArray[sSysExMaxSize]; 67 | 68 | /*! This boolean indicates if the message is valid or not. 69 | There is no channel consideration here, 70 | validity means the message respects the MIDI norm. 71 | */ 72 | bool valid; 73 | 74 | inline unsigned getSysExSize() const 75 | { 76 | const unsigned size = unsigned(data2) << 8 | data1; 77 | return size > sSysExMaxSize ? sSysExMaxSize : size; 78 | } 79 | }; 80 | 81 | END_MIDI_NAMESPACE 82 | -------------------------------------------------------------------------------- /libraries/MIDI/midi_Namespace.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file midi_Namespace.h 3 | * Project Arduino MIDI Library 4 | * @brief MIDI Library for the Arduino - Namespace declaration 5 | * @version 4.2 6 | * @author Francois Best 7 | * @date 24/02/11 8 | * @license GPL v3.0 - Copyright Forty Seven Effects 2014 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #pragma once 25 | 26 | #define MIDI_NAMESPACE midi 27 | #define BEGIN_MIDI_NAMESPACE namespace MIDI_NAMESPACE { 28 | #define END_MIDI_NAMESPACE } 29 | 30 | #define USING_NAMESPACE_MIDI using namespace MIDI_NAMESPACE; 31 | 32 | BEGIN_MIDI_NAMESPACE 33 | 34 | END_MIDI_NAMESPACE 35 | -------------------------------------------------------------------------------- /libraries/MIDI/midi_Settings.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file midi_Settings.h 3 | * Project Arduino MIDI Library 4 | * @brief MIDI Library for the Arduino - Settings 5 | * @version 4.2 6 | * @author Francois Best 7 | * @date 24/02/11 8 | * @license GPL v3.0 - Copyright Forty Seven Effects 2014 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #pragma once 25 | 26 | #include "midi_Defs.h" 27 | 28 | BEGIN_MIDI_NAMESPACE 29 | 30 | /*! \brief Default Settings for the MIDI Library. 31 | 32 | To change the default settings, don't edit them there, create a subclass and 33 | override the values in that subclass, then use the MIDI_CREATE_CUSTOM_INSTANCE 34 | macro to create your instance. The settings you don't override will keep their 35 | default value. Eg: 36 | \code{.cpp} 37 | struct MySettings : public midi::DefaultSettings 38 | { 39 | static const bool UseRunningStatus = false; // Messes with my old equipment! 40 | }; 41 | 42 | MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial2, midi, MySettings); 43 | \endcode 44 | */ 45 | struct DefaultSettings 46 | { 47 | /*! Running status enables short messages when sending multiple values 48 | of the same type and channel.\n 49 | Set to 0 if you have troubles controlling your hardware. 50 | */ 51 | static const bool UseRunningStatus = true; 52 | 53 | /* NoteOn with 0 velocity should be handled as NoteOf.\n 54 | Set to 1 to get NoteOff events when receiving null-velocity NoteOn messages.\n 55 | Set to 0 to get NoteOn events when receiving null-velocity NoteOn messages. 56 | */ 57 | static const bool HandleNullVelocityNoteOnAsNoteOff = true; 58 | 59 | // Setting this to 1 will make MIDI.read parse only one byte of data for each 60 | // call when data is available. This can speed up your application if receiving 61 | // a lot of traffic, but might induce MIDI Thru and treatment latency. 62 | static const bool Use1ByteParsing = true; 63 | 64 | /*! Override the default MIDI baudrate to transmit over USB serial, to 65 | a decoding program such as Hairless MIDI (set baudrate to 115200)\n 66 | http://projectgus.github.io/hairless-midiserial/ 67 | */ 68 | static const long BaudRate = 31250; 69 | 70 | /*! Maximum size of SysEx receivable. Decrease to save RAM if you don't expect 71 | to receive SysEx, or adjust accordingly. 72 | */ 73 | static const unsigned SysExMaxSize = 256; 74 | }; 75 | 76 | END_MIDI_NAMESPACE 77 | -------------------------------------------------------------------------------- /libraries/MemoryFree/MemoryFree.cpp: -------------------------------------------------------------------------------- 1 | extern unsigned int __bss_end; 2 | extern unsigned int __heap_start; 3 | extern void *__brkval; 4 | 5 | 6 | #include "MemoryFree.h" 7 | 8 | 9 | int freeMemory() { 10 | int free_memory; 11 | 12 | if((int)__brkval == 0) 13 | free_memory = ((int)&free_memory) - ((int)&__bss_end); 14 | else 15 | free_memory = ((int)&free_memory) - ((int)__brkval); 16 | 17 | return free_memory; 18 | } 19 | -------------------------------------------------------------------------------- /libraries/MemoryFree/MemoryFree.h: -------------------------------------------------------------------------------- 1 | #ifndef MEMORY_FREE_H 2 | #define MEMORY_FREE_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | int freeMemory(); 9 | 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | 14 | #endif 15 | 16 | -------------------------------------------------------------------------------- /libraries/MultiButton/MultiButton.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "MultiButton.h" 3 | 4 | void MultiButton::pinClock(int pin) { 5 | digitalWrite(pin, HIGH); 6 | digitalWrite(pin, LOW); 7 | } 8 | 9 | MultiButton::MultiButton() { 10 | buttonInterval = 10; 11 | } 12 | 13 | void MultiButton::attach(int _buttonCount, int _buttonPin, int _pinDS, int _pinSTCP, int _pinSHCP) { 14 | buttonCount = _buttonCount; 15 | buttonPin = _buttonPin; 16 | pinDS = _pinDS; 17 | pinSHCP = _pinSHCP; 18 | pinSTCP = _pinSTCP; 19 | pinMode(buttonPin, INPUT); 20 | pinMode(pinDS, OUTPUT); 21 | pinMode(pinSTCP, OUTPUT); 22 | pinMode(pinSHCP, OUTPUT); 23 | digitalWrite(pinDS, LOW); 24 | for (int i=0;i= buttonInterval && (bool)(buttonState[i] & _BV(DEBOUNCED_STATE)) != val) { 50 | buttonPreviousMillis[i] = millis(); 51 | buttonState[i] ^= _BV(DEBOUNCED_STATE); 52 | buttonState[i] |= _BV(STATE_CHANGED); 53 | } 54 | bool newVal = buttonState[i] & _BV(DEBOUNCED_STATE); 55 | if (newVal != values[i]) 56 | { 57 | values[i] = newVal; 58 | } 59 | pinClock(pinSHCP); 60 | pinClock(pinSTCP); 61 | } 62 | } -------------------------------------------------------------------------------- /libraries/MultiButton/MultiButton.cpp.d: -------------------------------------------------------------------------------- 1 | D:\Dropbox\Personal\Ersin\Music\Kemper\MyFootController\arduino\src_git\libraries\MultiButton\MultiButton.cpp.o: \ 2 | D:\Dropbox\Personal\Ersin\Music\Kemper\MyFootController\arduino\src_git\libraries\MultiButton\MultiButton.cpp \ 3 | D:\Dropbox\Personal\Ersin\Music\Kemper\MyFootController\arduino\src_git\libraries\MultiButton\MultiButton.h \ 4 | C:\Program\ Files\ (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h \ 5 | C:\Program\ Files\ (x86)\Arduino\hardware\arduino\avr\cores\arduino/binary.h \ 6 | C:\Program\ Files\ (x86)\Arduino\hardware\arduino\avr\cores\arduino/WCharacter.h \ 7 | C:\Program\ Files\ (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h \ 8 | C:\Program\ Files\ (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h \ 9 | C:\Program\ Files\ (x86)\Arduino\hardware\arduino\avr\cores\arduino/Stream.h \ 10 | C:\Program\ Files\ (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h \ 11 | C:\Program\ Files\ (x86)\Arduino\hardware\arduino\avr\cores\arduino/Printable.h \ 12 | C:\Program\ Files\ (x86)\Arduino\hardware\arduino\avr\cores\arduino/USBAPI.h \ 13 | C:\Program\ Files\ (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h \ 14 | C:\Program\ Files\ (x86)\Arduino\hardware\arduino\avr\variants\mega/pins_arduino.h 15 | -------------------------------------------------------------------------------- /libraries/MultiButton/MultiButton.cpp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/basarane/kemper-arduino-library/1e5e416610921f6aa660a6cfafa02a7d5fe2a1ba/libraries/MultiButton/MultiButton.cpp.o -------------------------------------------------------------------------------- /libraries/MultiButton/MultiButton.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Arduino.h" 5 | 6 | #define DEBOUNCED_STATE 0 7 | #define UNSTABLE_STATE 1 8 | #define STATE_CHANGED 3 9 | 10 | #define MAX_BUTTON_COUNT 16 11 | 12 | class MultiButton 13 | { 14 | protected: 15 | int buttonPin; 16 | int pinDS; 17 | int pinSTCP; 18 | int pinSHCP; 19 | uint8_t buttonState[MAX_BUTTON_COUNT]; 20 | unsigned long buttonPreviousMillis[MAX_BUTTON_COUNT]; 21 | unsigned long lastButtonUpdate; 22 | int buttonInterval; 23 | 24 | void pinClock(int pin); 25 | public: 26 | int buttonCount; 27 | bool values[MAX_BUTTON_COUNT]; 28 | 29 | MultiButton(); 30 | void attach(int _buttonCount, int _buttonPin, int _pinDS, int _pinSTCP, int _pinSHCP); 31 | void update(); 32 | }; 33 | -------------------------------------------------------------------------------- /libraries/Tlc5940/Tlc5940.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 by Alex Leone 2 | 3 | This file is part of the Arduino TLC5940 Library. 4 | 5 | The Arduino TLC5940 Library is free software: you can redistribute it 6 | and/or modify it under the terms of the GNU General Public License as 7 | published by the Free Software Foundation, either version 3 of the 8 | License, or (at your option) any later version. 9 | 10 | The Arduino TLC5940 Library is distributed in the hope that it will be 11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with The Arduino TLC5940 Library. If not, see 17 | . */ 18 | 19 | #ifndef TLC5940_H 20 | #define TLC5940_H 21 | 22 | /** \file 23 | Tlc5940 library header file. */ 24 | 25 | #include 26 | #include "tlc_config.h" 27 | 28 | #ifdef TLC_ATMEGA_8_H 29 | 30 | /** Enables the Timer1 Overflow interrupt, which will fire after an XLAT 31 | pulse */ 32 | #define set_XLAT_interrupt() TIFR |= _BV(TOV1); TIMSK = _BV(TOIE1) 33 | /** Disables any Timer1 interrupts */ 34 | #define clear_XLAT_interrupt() TIMSK = 0 35 | 36 | #else 37 | 38 | /** Enables the Timer1 Overflow interrupt, which will fire after an XLAT 39 | pulse */ 40 | #define set_XLAT_interrupt() TIFR1 |= _BV(TOV1); TIMSK1 = _BV(TOIE1) 41 | /** Disables any Timer1 interrupts */ 42 | #define clear_XLAT_interrupt() TIMSK1 = 0 43 | 44 | #endif 45 | 46 | /** Enables the output of XLAT pulses */ 47 | #define enable_XLAT_pulses() TCCR1A = _BV(COM1A1) | _BV(COM1B1) 48 | /** Disables the output of XLAT pulses */ 49 | #define disable_XLAT_pulses() TCCR1A = _BV(COM1B1) 50 | 51 | extern volatile uint8_t tlc_needXLAT; 52 | extern volatile void (*tlc_onUpdateFinished)(void); 53 | extern uint8_t tlc_GSData[NUM_TLCS * 24]; 54 | 55 | /** The main Tlc5940 class for the entire library. An instance of this class 56 | will be preinstantiated as Tlc. */ 57 | class Tlc5940 58 | { 59 | public: 60 | void init(uint16_t initialValue = 0); 61 | void clear(void); 62 | uint8_t update(void); 63 | void set(TLC_CHANNEL_TYPE channel, uint16_t value); 64 | uint16_t get(TLC_CHANNEL_TYPE channel); 65 | void setAll(uint16_t value); 66 | #if VPRG_ENABLED 67 | void setAllDC(uint8_t value); 68 | #endif 69 | #if XERR_ENABLED 70 | uint8_t readXERR(void); 71 | #endif 72 | 73 | }; 74 | 75 | void tlc_shift8_init(void); 76 | void tlc_shift8(uint8_t byte); 77 | 78 | #if VPRG_ENABLED 79 | void tlc_dcModeStart(void); 80 | void tlc_dcModeStop(void); 81 | #endif 82 | 83 | // for the preinstantiated Tlc variable. 84 | extern Tlc5940 Tlc; 85 | 86 | #endif 87 | 88 | -------------------------------------------------------------------------------- /libraries/Tlc5940/changelog.txt: -------------------------------------------------------------------------------- 1 | 2009-05-07 2 | - Added support for the Arduino Mega 3 | 4 | 2009-04-19 5 | - Bug fix in tlc_fades.h (incrementing a pointer after removing something 6 | from the fadeBuffer array). Also tlc_updateFades() will wait till after 7 | an update if it's just removed the last fade. 8 | - Updated the core function documentation. 9 | 10 | 2009-03-05 11 | - Fixed the missing pin definitions for the ATmega328p 12 | 13 | 2009-02-16 14 | - Added tlc_servos.h and example (thank you Steve Pomeroy) 15 | - Cleaned up some older documentation 16 | - Added trailing newlines to c, h, cpp, and pde files 17 | 18 | 2009-02-03 19 | - Added support for the Sanguino (ATmega xx4 series) 20 | - Added support for the ATmega 8 21 | - Moved the project to Google Code: 22 | http://code.google.com/p/tlc5940arduino/ 23 | - Fixed a bug in tlc_fades.h: assignment of struct arrays 24 | - Cleaned up the whitespace in the library: 4 spaces instead of tabs 25 | 26 | 2009-01-25 27 | - Added tlc_fades.h 28 | - Added include "tlc_config.h" to Tlc5940.h so it's not required 29 | in the sketch 30 | - Added Tlc.setAll(value) 31 | - Changed a few for loops in Tlc5940.cpp: used *p++ instead of having 32 | p++ in the increment section of the for loop; changed to while loops 33 | 34 | 2008-11-26 35 | - Tlc.init() sets all channels to zero and updates. 36 | - Added TLC_PWM_PERIOD and TLC_GSCLK_PERIOD to tlc_config.h 37 | - Added TLC_CHANNEL_TYPE to tlc_config.h - Adds support for up to 4096 TLCs. 38 | (if TLC_CHANNEL_TYPE is uint16_t) 39 | - Changed the examples to use TLC_CHANNEL_TYPE 40 | - set DATA_TRANSFER_MODE default to TLC_SPI 41 | 42 | 2008-11-11 43 | - Added tlc_animations.h and examples 44 | - Fixed SPI mode - (don't use enums as constants 45 | "#if A == 1" doesn't work) 46 | 47 | 2008-10-31 48 | - Initial Release 49 | -------------------------------------------------------------------------------- /libraries/Tlc5940/examples/BasicAnimations/AnimationCreator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/basarane/kemper-arduino-library/1e5e416610921f6aa660a6cfafa02a7d5fe2a1ba/libraries/Tlc5940/examples/BasicAnimations/AnimationCreator.class -------------------------------------------------------------------------------- /libraries/Tlc5940/examples/BasicAnimations/AnimationCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * First Attempt at generating the TLC output code from an image. 3 | * Run this with "java AnimationCreator" 4 | * It will read any image file in the current directory and create an animation for the TLC library. 5 | * 6 | * Right now this only works with 1 TLC with 16 LEDS connected to it, where 7 | * output0 is the bottom and output15 is the top. 8 | * 9 | * For best results make your files 16 pixels high and as wide as you want. Each vertical pixel 10 | * corresponds to an LED output. 11 | * 12 | * Alex Leone , 2008-11-12 13 | */ 14 | 15 | import java.util.*; 16 | import java.awt.*; 17 | import java.awt.image.*; 18 | import java.io.*; 19 | import javax.imageio.*; 20 | 21 | public class AnimationCreator { 22 | 23 | public static void main(String[] args) throws IOException { 24 | if (args.length == 0) { 25 | autoProcess(); 26 | } 27 | } 28 | 29 | public static void autoProcess() throws IOException { 30 | File currentDirectory = new File ("."); 31 | File[] files = currentDirectory.listFiles(); 32 | int animationCount = 1; 33 | for (File file : files) { 34 | if (!file.isFile()) 35 | continue; 36 | String fileName = file.getName(); 37 | String suffix = fileName.substring(fileName.indexOf('.') + 1); 38 | if(!canReadFormat(suffix)) 39 | continue; 40 | String baseName = fileName.substring(0, fileName.indexOf('.')); 41 | String varName = "ani_" + baseName.toLowerCase(); 42 | String outputName = varName + ".h"; 43 | System.out.println("Writing " + outputName); 44 | BufferedImage image = ImageIO.read(file); 45 | PrintStream output = new PrintStream(new File(outputName)); 46 | output.println("#define " + varName.toUpperCase() + "_FRAMES " + image.getWidth()); 47 | output.println("uint8_t " + varName + "[NUM_TLCS * 24 * " + varName.toUpperCase() + "_FRAMES] PROGMEM = {"); 48 | int[] rowRGB = new int[16]; 49 | for (int w = 0; w < image.getWidth(); w++) { 50 | for (int h = 0; h < 16; h++) { 51 | rowRGB[h] = image.getRGB(w, 15 - h); 52 | } 53 | parseRow(rowRGB, output); 54 | } 55 | output.println("};"); 56 | System.out.println("Wrote " + image.getWidth() + " frames to " + outputName); 57 | animationCount++; 58 | } 59 | } 60 | 61 | // Returns true if the specified format name can be read 62 | public static boolean canReadFormat(String formatName) { 63 | Iterator iter = ImageIO.getImageReadersByFormatName(formatName); 64 | return iter.hasNext(); 65 | } 66 | 67 | public static double rgbToGrayscaleIntensity(int rgb) { 68 | Color c = new Color(rgb); 69 | return 0.2989 * c.getRed() + 0.5870 * c.getGreen() + 0.1140 * c.getBlue(); 70 | } 71 | 72 | public static void parseRow(int[] rowRGB, PrintStream output) { 73 | output.print("\t"); 74 | for (int i = rowRGB.length - 1; i >= 0; i -= 2) { 75 | int a = (255 - (int)Math.round(rgbToGrayscaleIntensity(rowRGB[i]))); 76 | int b = (255 - (int)Math.round(rgbToGrayscaleIntensity(rowRGB[i - 1]))); 77 | output.print(((a >> 4) & 0xFF) + "," + (((a << 4) | (b >> 8)) & 0xFF) + "," + (b & 0xFF) + ","); 78 | //System.out.print( 79 | // "GS_DUO(" + (255 - Math.round(rgbToGrayscaleIntensity(rowRGB[i]))) + "," + 80 | // (255 - Math.round(rgbToGrayscaleIntensity(rowRGB[i - 1]))) + "),"); 81 | } 82 | output.println(); 83 | } 84 | 85 | 86 | } -------------------------------------------------------------------------------- /libraries/Tlc5940/examples/BasicAnimations/Arduino.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/basarane/kemper-arduino-library/1e5e416610921f6aa660a6cfafa02a7d5fe2a1ba/libraries/Tlc5940/examples/BasicAnimations/Arduino.png -------------------------------------------------------------------------------- /libraries/Tlc5940/examples/BasicAnimations/BasicAnimations.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Writes "Ardunio" with Persistance of Vision (POV) with 16 LEDs (output 0 3 | is on bottom, output 15 is top). The animation below doesn't work with 4 | more than 1 TLC. 5 | 6 | I generated the animation with the included java code: 7 | /hardware/libraries/Tlc5940/examples/BasicAnimations 8 | 9 | To use the code, run 10 | java AnimationCreator 11 | in the folder above and it will parse all images in the folder to 12 | .h files. For best results use images that are 16 pixels high. 13 | 14 | See the BasicUse example for hardware setup. 15 | 16 | Alex Leone , 2009-02-03 */ 17 | 18 | #include "Tlc5940.h" 19 | #include "tlc_animations.h" 20 | #include "ani_arduino.h" 21 | 22 | void setup() 23 | { 24 | Tlc.init(); 25 | } 26 | 27 | void loop() 28 | { 29 | // checks to see if the animation is finished playing 30 | if (!tlc_onUpdateFinished) { 31 | 32 | delay(100); 33 | 34 | /* 35 | void tlc_playAnimation(prog_uint8_t *animation, uint16_t frames, 36 | uint16_t periodsPerFrame); 37 | periods per frame is PWM periods, 1.024ms per frame (0 is valid - this 38 | will play the animation as fast as possible). 39 | 40 | Plays an animation in the "background". 41 | Don't call Tlc.update() while this is running. 42 | You can check if this is done with !tlc_onUpdateFinished */ 43 | tlc_playAnimation(ani_arduino, ANI_ARDUINO_FRAMES, 3); 44 | 45 | 46 | // If you don't want to do anything until it's finished, use: 47 | // while (!tlc_onUpdateFinished); 48 | 49 | } 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /libraries/Tlc5940/examples/BasicAnimations/ani_arduino.h: -------------------------------------------------------------------------------- 1 | #define ANI_ARDUINO_FRAMES 80 2 | uint8_t ani_arduino[NUM_TLCS * 24 * ANI_ARDUINO_FRAMES] PROGMEM = { 3 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,6,176,206, 4 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,65,10,64,247,15,240,255, 5 | 0,0,0,0,0,0,0,0,0,0,0,0,1,160,122,13,192,255,15,240,254,11,192,89, 6 | 0,0,0,0,0,0,0,0,4,4,240,179,15,192,255,15,240,255,8,32,33,0,0,0, 7 | 0,0,0,0,0,37,8,128,231,15,240,255,15,144,169,15,240,255,0,0,0,0,0,0, 8 | 0,0,94,12,16,255,15,240,255,13,64,113,1,48,0,15,240,255,0,0,0,0,0,0, 9 | 0,0,255,15,240,243,9,192,56,0,0,0,0,0,0,15,240,255,0,0,0,0,0,0, 10 | 0,0,255,15,240,243,9,208,57,0,0,0,0,0,0,15,240,255,0,0,0,0,0,0, 11 | 0,0,93,12,0,255,15,240,255,13,80,114,1,64,0,15,240,255,0,0,0,0,0,0, 12 | 0,0,0,0,0,36,8,112,230,15,240,255,15,144,170,15,240,255,0,0,0,0,0,0, 13 | 0,0,0,0,0,0,0,0,4,4,224,178,15,192,255,15,240,255,8,32,32,0,0,0, 14 | 0,0,0,0,0,0,0,0,0,0,0,0,1,144,121,13,176,255,15,240,254,11,160,86, 15 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,10,48,246,15,240,255, 16 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,6,160,206, 17 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 18 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 19 | 0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255, 20 | 0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255, 21 | 0,0,0,0,0,0,0,0,2,9,224,248,7,32,24,0,16,0,0,0,0,0,0,0, 22 | 0,0,0,0,0,0,0,0,109,15,240,115,0,0,0,0,0,0,0,0,0,0,0,0, 23 | 0,0,0,0,0,0,0,0,208,15,240,25,0,0,0,0,0,0,0,0,0,0,0,0, 24 | 0,0,0,0,0,0,0,0,248,15,240,1,0,0,0,0,0,0,0,0,0,0,0,0, 25 | 0,0,0,0,0,0,0,0,253,15,240,0,0,0,0,0,0,0,0,0,0,0,0,0, 26 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 27 | 0,0,0,0,0,0,0,0,0,0,16,90,11,176,237,15,192,237,11,176,90,0,16,0, 28 | 0,0,0,0,0,0,0,0,6,11,0,255,15,240,255,15,240,255,15,240,255,11,16,6, 29 | 0,0,0,0,0,0,0,0,125,15,240,247,7,48,26,0,48,26,7,16,246,15,240,126, 30 | 0,0,0,0,0,0,0,0,221,15,240,100,0,0,0,0,0,0,0,0,98,15,240,222, 31 | 0,0,0,0,0,0,0,0,250,15,240,14,0,0,0,0,0,0,0,0,13,15,240,249, 32 | 0,0,0,0,0,0,0,0,226,15,240,14,0,0,0,0,0,0,0,0,13,15,240,223, 33 | 0,0,0,0,0,0,0,0,130,15,240,103,0,0,0,0,0,0,0,0,100,15,240,131, 34 | 0,0,0,0,0,0,0,0,5,10,112,248,7,96,27,0,64,27,7,64,247,10,112,6, 35 | 15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255, 36 | 15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255, 37 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 38 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 39 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 40 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 41 | 0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,253,14,144,173,3,32,0, 42 | 0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,144,57, 43 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,2,224,201,15,240,186, 44 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,46,15,240,242, 45 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,15,240,246, 46 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,23,15,240,206, 47 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,111,15,240,102, 48 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,13,6,32,246,9,80,0, 49 | 0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255, 50 | 0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255, 51 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 52 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 53 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 54 | 15,240,255,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255, 55 | 15,240,255,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255, 56 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 57 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 58 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 59 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 60 | 0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255, 61 | 0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255, 62 | 0,0,0,0,0,0,0,0,0,9,64,246,6,48,13,0,0,0,0,0,0,0,0,0, 63 | 0,0,0,0,0,0,0,0,100,15,240,111,0,0,0,0,0,0,0,0,0,0,0,0, 64 | 0,0,0,0,0,0,0,0,208,15,240,24,0,0,0,0,0,0,0,0,0,0,0,0, 65 | 0,0,0,0,0,0,0,0,250,15,240,4,0,0,0,0,0,0,0,0,0,0,0,0, 66 | 0,0,0,0,0,0,0,0,241,15,240,47,0,0,0,0,0,0,0,0,0,0,0,0, 67 | 0,0,0,0,0,0,0,0,186,15,240,202,2,240,3,0,0,0,0,0,0,0,0,0, 68 | 0,0,0,0,0,0,0,0,57,15,144,255,15,240,255,15,240,255,15,240,255,15,240,255, 69 | 0,0,0,0,0,0,0,0,0,3,32,173,14,144,253,15,240,255,15,240,255,15,240,255, 70 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 71 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 72 | 0,0,0,0,0,0,0,0,0,0,0,73,11,80,235,15,176,235,11,80,74,0,0,0, 73 | 0,0,0,0,0,0,0,0,0,8,80,255,15,240,255,15,240,255,15,240,255,8,144,0, 74 | 0,0,0,0,0,0,0,0,72,15,240,254,8,128,31,0,64,31,8,128,254,15,240,74, 75 | 0,0,0,0,0,0,0,0,179,15,240,137,0,0,0,0,0,0,0,0,136,15,240,181, 76 | 0,0,0,0,0,0,0,0,234,15,240,32,0,0,0,0,0,0,0,0,31,15,240,235, 77 | 0,0,0,0,0,0,0,0,251,15,240,5,0,0,0,0,0,0,0,0,4,15,240,251, 78 | 0,0,0,0,0,0,0,0,234,15,240,33,0,0,0,0,0,0,0,0,32,15,240,235, 79 | 0,0,0,0,0,0,0,0,179,15,240,142,0,0,0,0,0,0,0,0,138,15,240,180, 80 | 0,0,0,0,0,0,0,0,69,15,240,255,8,224,33,0,80,32,8,176,254,15,240,72, 81 | 0,0,0,0,0,0,0,0,0,8,16,255,15,240,255,15,240,255,15,240,255,8,80,0, 82 | 0,0,0,0,0,0,0,0,0,0,0,70,11,48,234,15,176,234,11,48,72,0,0,0, 83 | }; 84 | 85 | -------------------------------------------------------------------------------- /libraries/Tlc5940/examples/BasicUse/BasicUse.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Basic Pin setup: 3 | ------------ ---u---- 4 | ARDUINO 13|-> SCLK (pin 25) OUT1 |1 28| OUT channel 0 5 | 12| OUT2 |2 27|-> GND (VPRG) 6 | 11|-> SIN (pin 26) OUT3 |3 26|-> SIN (pin 11) 7 | 10|-> BLANK (pin 23) OUT4 |4 25|-> SCLK (pin 13) 8 | 9|-> XLAT (pin 24) . |5 24|-> XLAT (pin 9) 9 | 8| . |6 23|-> BLANK (pin 10) 10 | 7| . |7 22|-> GND 11 | 6| . |8 21|-> VCC (+5V) 12 | 5| . |9 20|-> 2K Resistor -> GND 13 | 4| . |10 19|-> +5V (DCPRG) 14 | 3|-> GSCLK (pin 18) . |11 18|-> GSCLK (pin 3) 15 | 2| . |12 17|-> SOUT 16 | 1| . |13 16|-> XERR 17 | 0| OUT14|14 15| OUT channel 15 18 | ------------ -------- 19 | 20 | - Put the longer leg (anode) of the LEDs in the +5V and the shorter leg 21 | (cathode) in OUT(0-15). 22 | - +5V from Arduino -> TLC pin 21 and 19 (VCC and DCPRG) 23 | - GND from Arduino -> TLC pin 22 and 27 (GND and VPRG) 24 | - digital 3 -> TLC pin 18 (GSCLK) 25 | - digital 9 -> TLC pin 24 (XLAT) 26 | - digital 10 -> TLC pin 23 (BLANK) 27 | - digital 11 -> TLC pin 26 (SIN) 28 | - digital 13 -> TLC pin 25 (SCLK) 29 | - The 2K resistor between TLC pin 20 and GND will let ~20mA through each 30 | LED. To be precise, it's I = 39.06 / R (in ohms). This doesn't depend 31 | on the LED driving voltage. 32 | - (Optional): put a pull-up resistor (~10k) between +5V and BLANK so that 33 | all the LEDs will turn off when the Arduino is reset. 34 | 35 | ++++++++++++++ 36 | BLANK on Arduino -> BLANK of TLC1 -> BLANK of TLC2 -> ... 37 | XLAT on Arduino -> XLAT of TLC1 -> XLAT of TLC2 -> ... 38 | The one exception is that each TLC needs it's own resistor between pin 20 39 | and GND. 40 | 41 | This library uses the PWM output ability of digital pins 3, 9, 10, and 11. 42 | Do not use analogWrite(...) on these pins. 43 | 44 | This sketch does the Knight Rider strobe across a line of LEDs. 45 | 46 | Alex Leone , 2009-02-03 */ 47 | 48 | #include "Tlc5940.h" 49 | 50 | void setup() 51 | { 52 | /* Call Tlc.init() to setup the tlc. 53 | You can optionally pass an initial PWM value (0 - 4095) for all channels.*/ 54 | Tlc.init(); 55 | } 56 | 57 | /* This loop will create a Knight Rider-like effect if you have LEDs plugged 58 | into all the TLC outputs. NUM_TLCS is defined in "tlc_config.h" in the 59 | library folder. After editing tlc_config.h for your setup, delete the 60 | Tlc5940.o file to save the changes. */ 61 | 62 | void loop() 63 | { 64 | int direction = 1; 65 | for (int channel = 0; channel < NUM_TLCS * 16; channel += direction) { 66 | 67 | /* Tlc.clear() sets all the grayscale values to zero, but does not send 68 | them to the TLCs. To actually send the data, call Tlc.update() */ 69 | Tlc.clear(); 70 | 71 | /* Tlc.set(channel (0-15), value (0-4095)) sets the grayscale value for 72 | one channel (15 is OUT15 on the first TLC, if multiple TLCs are daisy- 73 | chained, then channel = 16 would be OUT0 of the second TLC, etc.). 74 | 75 | value goes from off (0) to always on (4095). 76 | 77 | Like Tlc.clear(), this function only sets up the data, Tlc.update() 78 | will send the data. */ 79 | if (channel == 0) { 80 | direction = 1; 81 | } else { 82 | Tlc.set(channel - 1, 1000); 83 | } 84 | Tlc.set(channel, 4095); 85 | if (channel != NUM_TLCS * 16 - 1) { 86 | Tlc.set(channel + 1, 1000); 87 | } else { 88 | direction = -1; 89 | } 90 | 91 | /* Tlc.update() sends the data to the TLCs. This is when the LEDs will 92 | actually change. */ 93 | Tlc.update(); 94 | 95 | delay(75); 96 | } 97 | 98 | } 99 | 100 | -------------------------------------------------------------------------------- /libraries/Tlc5940/examples/CircularLightBuffer/CircularLightBuffer.pde: -------------------------------------------------------------------------------- 1 | /* 2 | A circular light buffer. If you manage to construct a circle of LEDs, 3 | definitely send in pictures. What this sketch does is take an analog 4 | reading off of analog pin 0 and add it to the current value of the last LED. 5 | If the resultant sum is greater than 4095, it turns the LED off, 6 | otherwise sets LED 0 to the value of the sum. 7 | 8 | If you ground pin 12, it will set LED 0 to zero. 9 | 10 | Then it shifts all the LED values up one (so LED 0 becomes LED 1) and sets 11 | LED 0 to the value shifted off the last LED (so if one LED is on, it will 12 | go in a circle forever). 13 | 14 | See the BasicUse example for hardware setup. 15 | 16 | Alex Leone , 2009-02-04 */ 17 | 18 | #include "Tlc5940.h" 19 | #include "tlc_shifts.h" 20 | 21 | // which analog pin to use 22 | #define ANALOG_PIN 0 23 | 24 | // which pin to clear the LEDs with 25 | #define CLEAR_PIN 12 26 | 27 | // how many millis for one full revolution over all the LEDs 28 | #define SCOPE_PERIOD (2000 * NUM_TLCS) 29 | #define LED_PERIOD SCOPE_PERIOD / (NUM_TLCS * 16) 30 | 31 | void setup() 32 | { 33 | pinMode(CLEAR_PIN, INPUT); 34 | digitalWrite(CLEAR_PIN, HIGH); // enable pull-up 35 | Tlc.init(); 36 | } 37 | 38 | void loop() 39 | { 40 | // shiftUp returns the value shifted off the last pin 41 | uint16_t sum = tlc_shiftUp() + analogRead(ANALOG_PIN) * 4; 42 | if (digitalRead(CLEAR_PIN) == LOW || sum > 4095) 43 | sum = 0; 44 | Tlc.set(0, sum); 45 | Tlc.update(); 46 | delay(LED_PERIOD); 47 | } 48 | 49 | -------------------------------------------------------------------------------- /libraries/Tlc5940/examples/FadeScope/FadeScope.pde: -------------------------------------------------------------------------------- 1 | /* 2 | A simple 1-d oscilliscope: scan all the channels, setting the PWM output 3 | value to 4x the analog pin 0 value (0 - 1024 * 4 = 4096). The value will 4 | fade to zero as the channels keep scanning. 5 | 6 | See the BasicUse example for hardware setup. 7 | 8 | Alex Leone , 2009-02-03 */ 9 | 10 | #include "Tlc5940.h" 11 | #include "tlc_fades.h" 12 | 13 | // which analog pin to use 14 | #define ANALOG_PIN 0 15 | 16 | // how many millis to strobe over all the LEDs 17 | #define SCOPE_PERIOD (1000 * NUM_TLCS) 18 | #define LED_PERIOD SCOPE_PERIOD / (NUM_TLCS * 16) 19 | 20 | TLC_CHANNEL_TYPE channel; 21 | 22 | void setup() 23 | { 24 | Tlc.init(); 25 | } 26 | 27 | void loop() 28 | { 29 | uint32_t lastMillis = millis(); 30 | tlc_addFade(channel, // led channel 31 | analogRead(ANALOG_PIN) * 4, // start fade value (0-4095) 32 | 0, // end fade value (0-4095) 33 | lastMillis + 2, // start millis 34 | lastMillis + (uint16_t)SCOPE_PERIOD / 4 // end millis 35 | ); 36 | if (channel++ == NUM_TLCS * 16) { 37 | channel = 0; 38 | } 39 | uint32_t currentMillis; 40 | do { 41 | currentMillis = millis(); 42 | tlc_updateFades(currentMillis); 43 | } while (currentMillis - lastMillis <= LED_PERIOD); 44 | } 45 | 46 | -------------------------------------------------------------------------------- /libraries/Tlc5940/examples/Fades/Fades.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Fades a line down the channels, with max value and duration based on 3 | the voltage of analog pin 0. 4 | Try grounding analog 0: everything should turn off. 5 | Try putting +5V into analog 0: everything should turn on. 6 | 7 | See the BasicUse example for hardware setup. 8 | 9 | Alex Leone , 2009-02-03 */ 10 | 11 | #include "Tlc5940.h" 12 | #include "tlc_fades.h" 13 | 14 | TLC_CHANNEL_TYPE channel; 15 | 16 | void setup() 17 | { 18 | Tlc.init(); 19 | } 20 | 21 | void loop() 22 | { 23 | if (tlc_fadeBufferSize < TLC_FADE_BUFFER_LENGTH - 2) { 24 | if (!tlc_isFading(channel)) { 25 | uint16_t duration = analogRead(0) * 2; 26 | int maxValue = analogRead(0) * 2; 27 | uint32_t startMillis = millis() + 50; 28 | uint32_t endMillis = startMillis + duration; 29 | tlc_addFade(channel, 0, maxValue, startMillis, endMillis); 30 | tlc_addFade(channel, maxValue, 0, endMillis, endMillis + duration); 31 | } 32 | if (channel++ == NUM_TLCS * 16) { 33 | channel = 0; 34 | } 35 | } 36 | tlc_updateFades(); 37 | } 38 | 39 | -------------------------------------------------------------------------------- /libraries/Tlc5940/examples/Servos/Servos.pde: -------------------------------------------------------------------------------- 1 | /* 2 | This sketch sweeps a servo on channel 0. 3 | 4 | To connect a servo: 5 | 1. Put a 2k-5k pull-up resistor (R0 below; I've tried with 3.3k) between the 6 | servo control output pin and +5v. 7 | 2. Connect that same pin to the servo's control line like so 8 | 9 | servo data pin 10 | | _____ 11 | OUTn ----+----[_____]---+5v 12 | R0 13 | 14 | Steve Pomeroy , 2009-01-20 */ 15 | 16 | #include "Tlc5940.h" 17 | #include "tlc_servos.h" 18 | 19 | #define SERVO_CHANNEL 0 20 | #define DELAY_TIME 20 21 | 22 | void setup() 23 | { 24 | tlc_initServos(); // Note: this will drop the PWM freqency down to 50Hz. 25 | } 26 | 27 | void loop() 28 | { 29 | for (int angle = 0; angle < 180; angle++) { 30 | tlc_setServo(SERVO_CHANNEL, angle); 31 | Tlc.update(); 32 | delay(DELAY_TIME); 33 | } 34 | for (int angle = 180; angle >= 0; angle--) { 35 | tlc_setServo(SERVO_CHANNEL, angle); 36 | Tlc.update(); 37 | delay(DELAY_TIME); 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /libraries/Tlc5940/examples/UsingProgmem/UsingProgmem.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Setting grayscale from progmem to save RAM. If you want to play 3 | multiple "frames", (an animation), see the BasicAnimations Example. 4 | 5 | See the BasicUse example for hardware setup. 6 | 7 | Alex Leone , 2009-02-03 */ 8 | 9 | #include "Tlc5940.h" 10 | 11 | // Extended functions (they start with tlc_...) require another include 12 | #include "tlc_progmem_utils.h" 13 | 14 | /* 15 | This is an array in program memory. Program memory is 16kB instead of 16 | 1024 bytes for regular variables in SRAM. 17 | 18 | The format for this array is 19 | GS_DUO(OUT15, OUT14), ... GS_DUO(OUT1, OUT0) 20 | 21 | If you have more than one TLC, the format is 22 | GS_DUO(TLC2.OUT15, TLC2.OUT14), ... GS_DUO(TLC2.OUT1, TLC2.OUT0), 23 | GS_DUO(TLC1.OUT15, TLC1.OUT14), ... GS_DUO(TLC1.OUT1, TLC1.OUT0) 24 | 25 | The pattern below will only work with 1 TLC. Copy + Paste the 4 lines 26 | inside the curly brackets for each additional TLC. */ 27 | uint8_t gsArray1[NUM_TLCS * 24] PROGMEM = { 28 | GS_DUO((4095 * 16)/16, (4095 * 15)/16), GS_DUO((4095 * 14)/16, (4095 * 13)/16), 29 | GS_DUO((4095 * 12)/16, (4095 * 11)/16), GS_DUO((4095 * 10)/16, (4095 * 9)/16), 30 | GS_DUO((4095 * 8)/16, (4095 * 7)/16), GS_DUO((4095 * 6)/16, (4095 * 5)/16), 31 | GS_DUO((4095 * 4)/16, (4095 * 3)/16), GS_DUO((4095 * 2)/16, (4095 * 1)/16), 32 | }; 33 | 34 | void setup() 35 | { 36 | Tlc.init(); 37 | } 38 | 39 | void loop() 40 | { 41 | // Display the pattern (brightness ramp over the outputs) 42 | tlc_setGSfromProgmem(gsArray1); 43 | Tlc.update(); 44 | 45 | // Fade each channel to zero 46 | for (TLC_CHANNEL_TYPE channel = 0; channel < NUM_TLCS * 16; channel++) { 47 | int16_t initialValue = Tlc.get(channel); 48 | while (initialValue > 0) { 49 | initialValue -= 5; 50 | if (initialValue < 0) { 51 | initialValue = 0; 52 | } 53 | Tlc.set(channel, initialValue); 54 | 55 | // wait until the data has been sent to the TLCs before continuing 56 | while (Tlc.update()); 57 | } 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /libraries/Tlc5940/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For TLC5940 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | Tlc5940 KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | init KEYWORD2 16 | clear KEYWORD2 17 | update KEYWORD2 18 | set KEYWORD2 19 | get KEYWORD2 20 | setAll KEYWORD2 21 | setAllDC KEYWORD2 22 | readXERR KEYWORD2 23 | tlc_setGSfromProgmem KEYWORD2 24 | tlc_setDCfromProgmem KEYWORD2 25 | tlc_playAnimation KEYWORD2 26 | tlc_addFade KEYWORD2 27 | tlc_removeFade KEYWORD2 28 | tlc_shiftUp KEYWORD2 29 | tlc_shiftDown KEYWORD2 30 | 31 | ####################################### 32 | # Instances (KEYWORD2) 33 | ####################################### 34 | 35 | Tlc KEYWORD2 36 | 37 | ####################################### 38 | # Constants (LITERAL1) 39 | ####################################### 40 | 41 | NUM_TLCS LITERAL1 42 | tlc_needXLAT LITERAL1 43 | tlc_GSData LITERAL1 44 | tlc_onUpdateFinished LITERAL1 45 | TLC_FADE_BUFFER_LENGTH LITERAL1 46 | tlc_fadeBufferSize LITERAL1 -------------------------------------------------------------------------------- /libraries/Tlc5940/pinouts/ATmega_8.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 by Alex Leone 2 | 3 | This file is part of the Arduino TLC5940 Library. 4 | 5 | The Arduino TLC5940 Library is free software: you can redistribute it 6 | and/or modify it under the terms of the GNU General Public License as 7 | published by the Free Software Foundation, either version 3 of the 8 | License, or (at your option) any later version. 9 | 10 | The Arduino TLC5940 Library is distributed in the hope that it will be 11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with The Arduino TLC5940 Library. If not, see 17 | . */ 18 | 19 | #ifndef TLC_ATMEGA_8_H 20 | #define TLC_ATMEGA_8_H 21 | 22 | #if DATA_TRANSFER_MODE == TLC_SPI 23 | #warning SPI cannot be used on the ATmega8 because it interferes with timer2 24 | #warning setting DATA_TRANSFER_MODE to TLC_BITBANG 25 | #define DATA_TRANSFER_MODE TLC_BITBANG 26 | #endif 27 | 28 | /** \file 29 | SPI and timer pins for the ATmega8. Don't edit these. All 30 | changeable pins are defined in tlc_config.h */ 31 | 32 | /** VPRG (Arduino digital pin 8) -> VPRG (TLC pin 27) */ 33 | #define DEFAULT_VPRG_PIN PB0 34 | #define DEFAULT_VPRG_PORT PORTB 35 | #define DEFAULT_VPRG_DDR DDRB 36 | 37 | /** XERR (Arduino digital pin 12) -> XERR (TLC pin 16) */ 38 | #define DEFAULT_XERR_PIN PB4 39 | #define DEFAULT_XERR_PORT PORTB 40 | #define DEFAULT_XERR_DDR DDRB 41 | #define DEFAULT_XERR_PINS PINB 42 | 43 | /** SIN (Arduino digital pin 7) -> SIN (TLC pin 26) */ 44 | #define DEFAULT_BB_SIN_PIN PD7 45 | #define DEFAULT_BB_SIN_PORT PORTD 46 | #define DEFAULT_BB_SIN_DDR DDRD 47 | /** SCLK (Arduino digital pin 4) -> SCLK (TLC pin 25) */ 48 | #define DEFAULT_BB_SCLK_PIN PD4 49 | #define DEFAULT_BB_SCLK_PORT PORTD 50 | #define DEFAULT_BB_SCLK_DDR DDRD 51 | 52 | /** MOSI (Arduino digital pin 11) -> SIN (TLC pin 26) */ 53 | #define TLC_MOSI_PIN PB3 54 | #define TLC_MOSI_PORT PORTB 55 | #define TLC_MOSI_DDR DDRB 56 | 57 | /** SCK (Arduino digital pin 13) -> SCLK (TLC pin 25) */ 58 | #define TLC_SCK_PIN PB5 59 | #define TLC_SCK_PORT PORTB 60 | #define TLC_SCK_DDR DDRB 61 | 62 | /** SS will be set to output as to not interfere with SPI master operation. 63 | If you have changed the pin-outs and the library doesn't seem to work 64 | or works intermittently, make sure this pin is set correctly. This pin 65 | will not be used by the library other than setting its direction to 66 | output. */ 67 | #define TLC_SS_PIN PB2 68 | #define TLC_SS_DDR DDRB 69 | 70 | /** OC1A (Arduino digital pin 9) -> XLAT (TLC pin 24) */ 71 | #define XLAT_PIN PB1 72 | #define XLAT_PORT PORTB 73 | #define XLAT_DDR DDRB 74 | 75 | /** OC1B (Arduino digital pin 10) -> BLANK (TLC pin 23) */ 76 | #define BLANK_PIN PB2 77 | #define BLANK_PORT PORTB 78 | #define BLANK_DDR DDRB 79 | 80 | /** OC2B (Arduino digital pin 3) -> GSCLK (TLC pin 18) */ 81 | #define GSCLK_PIN PD3 82 | #define GSCLK_PORT PORTD 83 | #define GSCLK_DDR DDRD 84 | 85 | #endif 86 | 87 | -------------------------------------------------------------------------------- /libraries/Tlc5940/pinouts/ATmega_xx4.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 by Alex Leone 2 | 3 | This file is part of the Arduino TLC5940 Library. 4 | 5 | The Arduino TLC5940 Library is free software: you can redistribute it 6 | and/or modify it under the terms of the GNU General Public License as 7 | published by the Free Software Foundation, either version 3 of the 8 | License, or (at your option) any later version. 9 | 10 | The Arduino TLC5940 Library is distributed in the hope that it will be 11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with The Arduino TLC5940 Library. If not, see 17 | . */ 18 | 19 | #ifndef TLC_ATMEGA_XX8_H 20 | #define TLC_ATMEGA_XX8_H 21 | 22 | /** \file 23 | SPI and timer pins for the ATmega164/324/644. Don't edit these. All 24 | changeable pins are defined in tlc_config.h */ 25 | 26 | /** VPRG (Sanguino digital pin 15) -> VPRG (TLC pin 27) */ 27 | #define DEFAULT_VPRG_PIN PD7 28 | #define DEFAULT_VPRG_PORT PORTD 29 | #define DEFAULT_VPRG_DDR DDRD 30 | 31 | /** XERR (Sanguino digital pin 6) -> XERR (TLC pin 16) */ 32 | #define DEFAULT_XERR_PIN PB6 33 | #define DEFAULT_XERR_PORT PORTB 34 | #define DEFAULT_XERR_DDR DDRB 35 | #define DEFAULT_XERR_PINS PINB 36 | 37 | /** SIN (Sanguino digital pin 5) -> SIN (TLC pin 26) */ 38 | #define DEFAULT_BB_SIN_PIN PB5 39 | #define DEFAULT_BB_SIN_PORT PORTB 40 | #define DEFAULT_BB_SIN_DDR DDRB 41 | /** SCLK (Sanguino digital pin 7) -> SCLK (TLC pin 25) */ 42 | #define DEFAULT_BB_SCLK_PIN PB7 43 | #define DEFAULT_BB_SCLK_PORT PORTB 44 | #define DEFAULT_BB_SCLK_DDR DDRB 45 | 46 | /** MOSI (Sanguino digital pin 5) -> SIN (TLC pin 26) */ 47 | #define TLC_MOSI_PIN PB5 48 | #define TLC_MOSI_PORT PORTB 49 | #define TLC_MOSI_DDR DDRB 50 | 51 | /** SCK (Sanguino digital pin 7) -> SCLK (TLC pin 25) */ 52 | #define TLC_SCK_PIN PB7 53 | #define TLC_SCK_PORT PORTB 54 | #define TLC_SCK_DDR DDRB 55 | 56 | /** SS will be set to output as to not interfere with SPI master operation. 57 | If you have changed the pin-outs and the library doesn't seem to work 58 | or works intermittently, make sure this pin is set correctly. This pin 59 | will not be used by the library other than setting its direction to 60 | output. */ 61 | #define TLC_SS_PIN PB4 62 | #define TLC_SS_DDR DDRB 63 | 64 | /** OC1A (Sanguino digital pin 13) -> XLAT (TLC pin 24) */ 65 | #define XLAT_PIN PD5 66 | #define XLAT_PORT PORTD 67 | #define XLAT_DDR DDRD 68 | 69 | /** OC1B (Sanguino digital pin 12) -> BLANK (TLC pin 23) */ 70 | #define BLANK_PIN PD4 71 | #define BLANK_PORT PORTD 72 | #define BLANK_DDR DDRD 73 | 74 | /** OC2B (Sanguino digital pin 14) -> GSCLK (TLC pin 18) */ 75 | #define GSCLK_PIN PD6 76 | #define GSCLK_PORT PORTD 77 | #define GSCLK_DDR DDRD 78 | 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /libraries/Tlc5940/pinouts/ATmega_xx8.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 by Alex Leone 2 | 3 | This file is part of the Arduino TLC5940 Library. 4 | 5 | The Arduino TLC5940 Library is free software: you can redistribute it 6 | and/or modify it under the terms of the GNU General Public License as 7 | published by the Free Software Foundation, either version 3 of the 8 | License, or (at your option) any later version. 9 | 10 | The Arduino TLC5940 Library is distributed in the hope that it will be 11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with The Arduino TLC5940 Library. If not, see 17 | . */ 18 | 19 | #ifndef TLC_ATMEGA_XX8_H 20 | #define TLC_ATMEGA_XX8_H 21 | 22 | /** \file 23 | SPI and timer pins for the ATmega168/48/88. Don't edit these. All 24 | changeable pins are defined in tlc_config.h */ 25 | 26 | /** VPRG (Arduino digital pin 8) -> VPRG (TLC pin 27) */ 27 | #define DEFAULT_VPRG_PIN PB0 28 | #define DEFAULT_VPRG_PORT PORTB 29 | #define DEFAULT_VPRG_DDR DDRB 30 | 31 | /** XERR (Arduino digital pin 12) -> XERR (TLC pin 16) */ 32 | #define DEFAULT_XERR_PIN PB4 33 | #define DEFAULT_XERR_PORT PORTB 34 | #define DEFAULT_XERR_DDR DDRB 35 | #define DEFAULT_XERR_PINS PINB 36 | 37 | /** SIN (Arduino digital pin 7) -> SIN (TLC pin 26) */ 38 | #define DEFAULT_BB_SIN_PIN PD7 39 | #define DEFAULT_BB_SIN_PORT PORTD 40 | #define DEFAULT_BB_SIN_DDR DDRD 41 | /** SCLK (Arduino digital pin 4) -> SCLK (TLC pin 25) */ 42 | #define DEFAULT_BB_SCLK_PIN PD4 43 | #define DEFAULT_BB_SCLK_PORT PORTD 44 | #define DEFAULT_BB_SCLK_DDR DDRD 45 | 46 | /** MOSI (Arduino digital pin 11) -> SIN (TLC pin 26) */ 47 | #define TLC_MOSI_PIN PB3 48 | #define TLC_MOSI_PORT PORTB 49 | #define TLC_MOSI_DDR DDRB 50 | 51 | /** SCK (Arduino digital pin 13) -> SCLK (TLC pin 25) */ 52 | #define TLC_SCK_PIN PB5 53 | #define TLC_SCK_PORT PORTB 54 | #define TLC_SCK_DDR DDRB 55 | 56 | /** SS will be set to output as to not interfere with SPI master operation. 57 | If you have changed the pin-outs and the library doesn't seem to work 58 | or works intermittently, make sure this pin is set correctly. This pin 59 | will not be used by the library other than setting its direction to 60 | output. */ 61 | #define TLC_SS_PIN PB2 62 | #define TLC_SS_DDR DDRB 63 | 64 | /** OC1A (Arduino digital pin 9) -> XLAT (TLC pin 24) */ 65 | #define XLAT_PIN PB1 66 | #define XLAT_PORT PORTB 67 | #define XLAT_DDR DDRB 68 | 69 | /** OC1B (Arduino digital pin 10) -> BLANK (TLC pin 23) */ 70 | #define BLANK_PIN PB2 71 | #define BLANK_PORT PORTB 72 | #define BLANK_DDR DDRB 73 | 74 | /** OC2B (Arduino digital pin 3) -> GSCLK (TLC pin 18) */ 75 | #define GSCLK_PIN PD3 76 | #define GSCLK_PORT PORTD 77 | #define GSCLK_DDR DDRD 78 | 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /libraries/Tlc5940/pinouts/Arduino_Mega.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 by Alex Leone 2 | 3 | This file is part of the Arduino TLC5940 Library. 4 | 5 | The Arduino TLC5940 Library is free software: you can redistribute it 6 | and/or modify it under the terms of the GNU General Public License as 7 | published by the Free Software Foundation, either version 3 of the 8 | License, or (at your option) any later version. 9 | 10 | The Arduino TLC5940 Library is distributed in the hope that it will be 11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with The Arduino TLC5940 Library. If not, see 17 | . */ 18 | 19 | #ifndef ARDUINO_MEGA_H 20 | #define ARDUINO_MEGA_H 21 | 22 | /** \file 23 | SPI and timer pins for the Arduino Mega. Don't edit these. All 24 | changeable pins are defined in tlc_config.h */ 25 | 26 | /** VPRG (Mega pin 50) -> VPRG (TLC pin 27) */ 27 | #define DEFAULT_VPRG_PIN PB3 28 | #define DEFAULT_VPRG_PORT PORTB 29 | #define DEFAULT_VPRG_DDR DDRB 30 | 31 | /** XERR (Mega pin 10) -> XERR (TLC pin 16) */ 32 | #define DEFAULT_XERR_PIN PB4 33 | #define DEFAULT_XERR_PORT PORTB 34 | #define DEFAULT_XERR_DDR DDRB 35 | #define DEFAULT_XERR_PINS PINB 36 | 37 | /** SIN (Mega pin 51) -> SIN (TLC pin 26) */ 38 | #define DEFAULT_BB_SIN_PIN PB2 39 | #define DEFAULT_BB_SIN_PORT PORTB 40 | #define DEFAULT_BB_SIN_DDR DDRB 41 | /** SCLK (Mega pin 52) -> SCLK (TLC pin 25) */ 42 | #define DEFAULT_BB_SCLK_PIN PB1 43 | #define DEFAULT_BB_SCLK_PORT PORTB 44 | #define DEFAULT_BB_SCLK_DDR DDRB 45 | 46 | /** MOSI (Mega pin 51) -> SIN (TLC pin 26) */ 47 | #define TLC_MOSI_PIN PB2 48 | #define TLC_MOSI_PORT PORTB 49 | #define TLC_MOSI_DDR DDRB 50 | 51 | /** SCK (Mega pin 52) -> SCLK (TLC pin 25) */ 52 | #define TLC_SCK_PIN PB1 53 | #define TLC_SCK_PORT PORTB 54 | #define TLC_SCK_DDR DDRB 55 | 56 | // SS (Mega pin 53) 57 | /** SS will be set to output as to not interfere with SPI master operation. 58 | If you have changed the pin-outs and the library doesn't seem to work 59 | or works intermittently, make sure this pin is set correctly. This pin 60 | will not be used by the library other than setting its direction to 61 | output. */ 62 | #define TLC_SS_PIN PB0 63 | #define TLC_SS_DDR DDRB 64 | 65 | /** OC1A (Mega pin 11) -> XLAT (TLC pin 24) */ 66 | #define XLAT_PIN PB5 67 | #define XLAT_PORT PORTB 68 | #define XLAT_DDR DDRB 69 | 70 | /** OC1B (Mega pin 12) -> BLANK (TLC pin 23) */ 71 | #define BLANK_PIN PB6 72 | #define BLANK_PORT PORTB 73 | #define BLANK_DDR DDRB 74 | 75 | /** OC2B (Mega pin 9) -> GSCLK (TLC pin 18) */ 76 | #define GSCLK_PIN PH6 77 | #define GSCLK_PORT PORTH 78 | #define GSCLK_DDR DDRH 79 | 80 | #endif 81 | 82 | -------------------------------------------------------------------------------- /libraries/Tlc5940/pinouts/Teensy_xxU4.h: -------------------------------------------------------------------------------- 1 | #ifndef TLC_Teensy_xxU4_h 2 | #define TLC_Teensy_xxU4_h 3 | 4 | #if DATA_TRANSFER_MODE == TLC_BITBANG 5 | #error "If you want bitbang mode, insert pin defs here" 6 | #endif 7 | 8 | // MOSI (Teensy pin 2) -> SIN (TLC pin 26) 9 | #define TLC_MOSI_PIN 2 10 | #define TLC_MOSI_PORT PORTB 11 | #define TLC_MOSI_DDR DDRB 12 | 13 | // SCK (Teensy pin 1) -> SCLK (TLC pin 25) 14 | #define TLC_SCK_PIN 1 15 | #define TLC_SCK_PORT PORTB 16 | #define TLC_SCK_DDR DDRB 17 | 18 | // SS (Teensy pin 0) 19 | #define TLC_SS_PIN 0 20 | #define TLC_SS_DDR DDRB 21 | 22 | // OC1A (Teensy pin 14) -> XLAT (TLC pin 24) 23 | #define XLAT_PIN 5 24 | #define XLAT_PORT PORTB 25 | #define XLAT_DDR DDRB 26 | 27 | // OC1B (Teensy pin 15) -> BLANK (TLC pin 23) 28 | #define BLANK_PIN 6 29 | #define BLANK_PORT PORTB 30 | #define BLANK_DDR DDRB 31 | 32 | // OC3A (Teensy pin 9) -> GSCLK (TLC pin 18) 33 | #define GSCLK_PIN 6 34 | #define GSCLK_PORT PORTC 35 | #define GSCLK_DDR DDRC 36 | #define TLC_TIMER3_GSCLK 1 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /libraries/Tlc5940/pinouts/Teensypp_xxx6.h: -------------------------------------------------------------------------------- 1 | #ifndef TLC_Teensypp_xxx6_H 2 | #define TLC_Teensypp_xxx6_H 3 | 4 | #if DATA_TRANSFER_MODE == TLC_BITBANG 5 | #error "If you want bitbang mode, insert pin defs here" 6 | #endif 7 | 8 | // MOSI (Teensy++ pin 22) -> SIN (TLC pin 26) 9 | #define TLC_MOSI_PIN 2 10 | #define TLC_MOSI_PORT PORTB 11 | #define TLC_MOSI_DDR DDRB 12 | 13 | // SCK (Teensy++ pin 21) -> SCLK (TLC pin 25) 14 | #define TLC_SCK_PIN 1 15 | #define TLC_SCK_PORT PORTB 16 | #define TLC_SCK_DDR DDRB 17 | 18 | // SS (Teensy++ pin 20) 19 | #define TLC_SS_PIN 0 20 | #define TLC_SS_DDR DDRB 21 | 22 | // OC1A (Teensy++ pin 25) -> XLAT (TLC pin 24) 23 | #define XLAT_PIN 5 24 | #define XLAT_PORT PORTB 25 | #define XLAT_DDR DDRB 26 | 27 | // OC1B (Teensy++ pin 26) -> BLANK (TLC pin 23) 28 | #define BLANK_PIN 6 29 | #define BLANK_PORT PORTB 30 | #define BLANK_DDR DDRB 31 | 32 | // OC2B (Teensy++ pin 1) -> GSCLK (TLC pin 18) 33 | #define GSCLK_PIN 1 34 | #define GSCLK_PORT PORTD 35 | #define GSCLK_DDR DDRD 36 | 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /libraries/Tlc5940/pinouts/chip_includes.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 by Alex Leone 2 | 3 | This file is part of the Arduino TLC5940 Library. 4 | 5 | The Arduino TLC5940 Library is free software: you can redistribute it 6 | and/or modify it under the terms of the GNU General Public License as 7 | published by the Free Software Foundation, either version 3 of the 8 | License, or (at your option) any later version. 9 | 10 | The Arduino TLC5940 Library is distributed in the hope that it will be 11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with The Arduino TLC5940 Library. If not, see 17 | . */ 18 | 19 | #ifndef TLC_CHIP_INCLUDES_H 20 | #define TLC_CHIP_INCLUDES_H 21 | 22 | /** \file 23 | Includes the chip-specfic defaults and pin definitions. */ 24 | 25 | #include 26 | 27 | #ifndef PB0 28 | #define PB0 PORTB0 29 | #define PB1 PORTB1 30 | #define PB2 PORTB2 31 | #define PB3 PORTB3 32 | #define PB4 PORTB4 33 | #define PB5 PORTB5 34 | #define PB6 PORTB6 35 | #define PB7 PORTB7 36 | #endif 37 | #ifndef PC0 38 | #define PC0 PORTC0 39 | #define PC1 PORTC1 40 | #define PC2 PORTC2 41 | #define PC3 PORTC3 42 | #define PC4 PORTC4 43 | #define PC5 PORTC5 44 | #define PC6 PORTC6 45 | #define PC7 PORTC7 46 | #endif 47 | #ifndef PD0 48 | #define PD0 PORTD0 49 | #define PD1 PORTD1 50 | #define PD2 PORTD2 51 | #define PD3 PORTD3 52 | #define PD4 PORTD4 53 | #define PD5 PORTD5 54 | #define PD6 PORTD6 55 | #define PD7 PORTD7 56 | #endif 57 | #ifndef PH0 58 | #define PH0 PORTH0 59 | #define PH1 PORTH1 60 | #define PH2 PORTH2 61 | #define PH3 PORTH3 62 | #define PH4 PORTH4 63 | #define PH5 PORTH5 64 | #define PH6 PORTH6 65 | #define PH7 PORTH7 66 | #endif 67 | 68 | /* Chip Specific Pinouts */ 69 | #if defined (__AVR_ATmega168__) \ 70 | || defined (__AVR_ATmega168P__) \ 71 | || defined (__AVR_ATmega88P__) \ 72 | || defined (__AVR_ATmega88__) \ 73 | || defined (__AVR_ATmega48P__) \ 74 | || defined (__AVR_ATmega48__) \ 75 | || defined (__AVR_ATmega328P__) 76 | 77 | /* Diecimila / Duemilanove / almost everything */ 78 | #include "ATmega_xx8.h" 79 | 80 | #elif defined (__AVR_ATmega8__) 81 | 82 | /* ATmega8 */ 83 | #include "ATmega_8.h" 84 | 85 | #elif defined (__AVR_ATmega164P__) \ 86 | || defined (__AVR_ATmega324P__) \ 87 | || defined (__AVR_ATmega644__) \ 88 | || defined (__AVR_ATmega644P__) 89 | 90 | /* Sanguino */ 91 | #include "ATmega_xx4.h" 92 | 93 | #elif defined (__AVR_ATmega640__) \ 94 | || defined (__AVR_ATmega1280__) \ 95 | || defined (__AVR_ATmega1281__) \ 96 | || defined (__AVR_ATmega2560__) \ 97 | || defined (__AVR_ATmega2561__) 98 | 99 | /* Arduino Mega */ 100 | #include "Arduino_Mega.h" 101 | 102 | #elif defined (__AVR_ATmega32U4__) 103 | 104 | /* Teensy 2.0 */ 105 | #include "Teensy_xxU4.h" 106 | 107 | #elif defined (__AVR_AT90USB646__) \ 108 | || defined (__AVR_AT90USB1286__) 109 | 110 | /* Teensy++ 2.0 */ 111 | #include "Teensypp_xxx6.h" 112 | 113 | #else 114 | #error "Unknown Chip!" 115 | #endif 116 | 117 | #endif 118 | 119 | -------------------------------------------------------------------------------- /libraries/Tlc5940/tlc_animations.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 by Alex Leone 2 | 3 | This file is part of the Arduino TLC5940 Library. 4 | 5 | The Arduino TLC5940 Library is free software: you can redistribute it 6 | and/or modify it under the terms of the GNU General Public License as 7 | published by the Free Software Foundation, either version 3 of the 8 | License, or (at your option) any later version. 9 | 10 | The Arduino TLC5940 Library is distributed in the hope that it will be 11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with The Arduino TLC5940 Library. If not, see 17 | . */ 18 | 19 | #ifndef TLC_ANIMATIONS_H 20 | #define TLC_ANIMATIONS_H 21 | 22 | /** \file 23 | TLC Animation functions. These play animations from PROGMEM. */ 24 | 25 | #include 26 | #include 27 | 28 | #include "tlc_config.h" 29 | #include "Tlc5940.h" 30 | #include "tlc_progmem_utils.h" 31 | 32 | /** The currently playing animation */ 33 | prog_uint8_t *tlc_currentAnimation; 34 | /** The number of frames in the current animation */ 35 | volatile uint16_t tlc_animationFrames; 36 | /** The number of PWM periods to display each frame - 1 */ 37 | volatile uint16_t tlc_animationPeriodsPerFrame; 38 | /** The current number of periods we've displayed this frame for */ 39 | volatile uint16_t tlc_animationPeriodsWait; 40 | 41 | volatile void tlc_animationXLATCallback(void); 42 | void tlc_playAnimation(prog_uint8_t *animation, uint16_t frames, uint16_t periodsPerFrame); 43 | 44 | /** \addtogroup ExtendedFunctions 45 | \code #include "tlc_animations.h" \endcode 46 | - void tlc_playAnimation(prog_uint8_t *animation, uint16_t frames, 47 | uint16_t periodsPerFrame) - plays an animation from progmem. */ 48 | /* @{ */ 49 | 50 | /** Plays an animation from progmem in the "background" (with interrupts). 51 | \param animation A progmem array of grayscale data, length NUM_TLCS * 52 | 24 * frames, in reverse order. Ensure that there is not an update 53 | waiting to happen before calling this. 54 | \param frames the number of frames in animation 55 | \param periodsPerFrame number of PWM periods to wait between each frame 56 | (0 means play the animation as fast as possible). 57 | The default PWM period for a 16MHz clock is 1.024ms. */ 58 | void tlc_playAnimation(prog_uint8_t *animation, uint16_t frames, uint16_t periodsPerFrame) 59 | { 60 | tlc_currentAnimation = animation; 61 | tlc_animationFrames = frames; 62 | tlc_animationPeriodsPerFrame = periodsPerFrame; 63 | tlc_animationPeriodsWait = 0; 64 | tlc_onUpdateFinished = tlc_animationXLATCallback; 65 | tlc_animationXLATCallback(); 66 | } 67 | 68 | /** This is called by the XLAT interrupt every PWM period to do stuff. */ 69 | volatile void tlc_animationXLATCallback(void) 70 | { 71 | if (tlc_animationPeriodsWait) { 72 | tlc_animationPeriodsWait--; 73 | set_XLAT_interrupt(); 74 | } else { 75 | if (tlc_animationFrames) { 76 | tlc_setGSfromProgmem(tlc_currentAnimation + 77 | (--tlc_animationFrames * NUM_TLCS * 24)); 78 | tlc_animationPeriodsWait = tlc_animationPeriodsPerFrame; 79 | Tlc.update(); 80 | } else { // animation is done 81 | tlc_onUpdateFinished = 0; 82 | } 83 | } 84 | } 85 | 86 | /* @} */ 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /libraries/Tlc5940/tlc_progmem_utils.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 by Alex Leone 2 | 3 | This file is part of the Arduino TLC5940 Library. 4 | 5 | The Arduino TLC5940 Library is free software: you can redistribute it 6 | and/or modify it under the terms of the GNU General Public License as 7 | published by the Free Software Foundation, either version 3 of the 8 | License, or (at your option) any later version. 9 | 10 | The Arduino TLC5940 Library is distributed in the hope that it will be 11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with The Arduino TLC5940 Library. If not, see 17 | . */ 18 | 19 | #ifndef TLC_PROGMEM_UTILS_H 20 | #define TLC_PROGMEM_UTILS_H 21 | 22 | /** \file 23 | PROGMEM utility functions for setting grayscale or dot correction data 24 | from PROGMEM. See the UsingProgmem Example for an example. */ 25 | 26 | #include 27 | #include 28 | 29 | #include "tlc_config.h" 30 | #include "Tlc5940.h" 31 | 32 | void tlc_setGSfromProgmem(prog_uint8_t *gsArray); 33 | #if VPRG_ENABLED 34 | void tlc_setDCfromProgmem(prog_uint8_t *dcArray); 35 | #endif 36 | 37 | /** \addtogroup ExtendedFunctions 38 | \code #include "tlc_progmem_utils.h" \endcode 39 | - void tlc_setGSfromProgmem(prog_uint8_t *gsArray) - copies the progmem 40 | grayscale to current grayscale array. Requires a 41 | \link Tlc5940::update Tlc.update() \endlink. 42 | - void tlc_setDCfromProgmem(prog_uint8_t *dcArray) - shifts the data from a 43 | progmem dot correction array (doesn't need an update). */ 44 | /* @{ */ 45 | 46 | /** Sets the grayscale data from an array in progmem. This doesn't shift out 47 | any data: call Tlc.update(). An example: 48 | \code 49 | #include "tlc_progmem_utils.h" 50 | prog_uint8_t gsArray1[NUM_TLCS * 24] = { 51 | GS_DUO((4095 * 16)/16, (4095 * 15)/16), GS_DUO((4095 * 14)/16, (4095 * 13)/16), 52 | GS_DUO((4095 * 12)/16, (4095 * 11)/16), GS_DUO((4095 * 10)/16, (4095 * 9)/16), 53 | GS_DUO((4095 * 8)/16, (4095 * 7)/16), GS_DUO((4095 * 6)/16, (4095 * 5)/16), 54 | GS_DUO((4095 * 4)/16, (4095 * 3)/16), GS_DUO((4095 * 2)/16, (4095 * 1)/16), 55 | }; 56 | 57 | // sometime after Tlc.init() 58 | tlc_setGSfromProgmem(gsArray1); 59 | Tlc.update(); 60 | \endcode 61 | This would set a ramp of values from OUT0 to OUT15. (Although the 62 | NUM_TLCS * 24 looks like an error, each #GS_DUO is 3 bytes). The array 63 | would have to be expanded if #NUM_TLCS != 1. 64 | 65 | The format of the grayscale array is explained in #tlc_GSData. 66 | 67 | \param gsArray A progmem array of grayscale data. */ 68 | void tlc_setGSfromProgmem(prog_uint8_t *gsArray) 69 | { 70 | prog_uint8_t *gsArrayp = gsArray; 71 | uint8_t *gsDatap = tlc_GSData; 72 | while (gsDatap < tlc_GSData + NUM_TLCS * 24) { 73 | *gsDatap++ = pgm_read_byte(gsArrayp++); 74 | *gsDatap++ = pgm_read_byte(gsArrayp++); 75 | *gsDatap++ = pgm_read_byte(gsArrayp++); 76 | } 77 | } 78 | 79 | 80 | #if VPRG_ENABLED 81 | 82 | /** \addtogroup ReqVPRG_ENABLED 83 | From tlc_progmem_utils.h: 84 | - tlc_setDCfromProgmem(prog_uint8_t *dcArray) - shifts the data from a 85 | progmem dot correction array (doesn't need an update). */ 86 | /* @{ */ 87 | 88 | /** Sets the dot correction data from an array in progmem. An example: 89 | \code 90 | #include "tlc_progmem_utils.h" 91 | prog_uint8_t dcArray1[NUM_TLCS * 12] = { 92 | DC_QUARTET(32, 63, 32, 63), DC_QUARTET(32, 63, 32, 63), 93 | DC_QUARTET(32, 63, 32, 63), DC_QUARTET(32, 63, 32, 63), 94 | }; 95 | 96 | // sometime after Tlc.init() 97 | tlc_setDCfromProgmem(dcArray1); 98 | \endcode 99 | This would set every other channel to have a dot correction value of 32. 100 | (Although the NUM_TLCS * 12 looks like an error, each #DC_QUARTET is 3 101 | bytes). The array would have to be expanded if #NUM_TLCS != 1. 102 | 103 | The Format of the array is similar to #tlc_GSData, the last channel of 104 | the last TLC is the first value in the array. In the example above, 105 | the first 32 is setting OUT15, and the last 63 is setting OUT0. 106 | 107 | \param dcArray A progmem array of dot correction data to be shifted out. 108 | \see \link Tlc5940::setAllDC Tlc.setAllDC \endlink */ 109 | void tlc_setDCfromProgmem(prog_uint8_t *dcArray) 110 | { 111 | tlc_dcModeStart(); 112 | 113 | prog_uint8_t *p = dcArray; 114 | prog_uint8_t *dcArrayEnd = dcArray + NUM_TLCS * 12; 115 | while (p < dcArrayEnd) { 116 | tlc_shift8(pgm_read_byte(p++)); 117 | } 118 | XLAT_PORT |= _BV(XLAT_PIN); 119 | XLAT_PORT &= ~_BV(XLAT_PIN); 120 | 121 | tlc_dcModeStop(); 122 | } 123 | 124 | /* @} */ 125 | 126 | #endif 127 | 128 | /* @} */ 129 | 130 | #endif 131 | 132 | -------------------------------------------------------------------------------- /libraries/Tlc5940/tlc_servos.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 by Alex Leone 2 | 3 | This file is part of the Arduino TLC5940 Library. 4 | 5 | The Arduino TLC5940 Library is free software: you can redistribute it 6 | and/or modify it under the terms of the GNU General Public License as 7 | published by the Free Software Foundation, either version 3 of the 8 | License, or (at your option) any later version. 9 | 10 | The Arduino TLC5940 Library is distributed in the hope that it will be 11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with The Arduino TLC5940 Library. If not, see 17 | . */ 18 | 19 | #ifndef TLC_SERVOS_H 20 | #define TLC_SERVOS_H 21 | 22 | /** \file 23 | TLC servo functions. */ 24 | 25 | #include 26 | #include "Tlc5940.h" 27 | 28 | #ifndef SERVO_MAX_ANGLE 29 | /** The maximum angle of the servo. */ 30 | #define SERVO_MAX_ANGLE 180 31 | #endif 32 | #ifndef SERVO_MIN_WIDTH 33 | /** The 1ms pulse width for zero degrees (0 - 4095). */ 34 | #define SERVO_MIN_WIDTH 204 35 | #endif 36 | #ifndef SERVO_MAX_WIDTH 37 | /** The 2ms pulse width for 180 degrees (0 - 4095). */ 38 | #define SERVO_MAX_WIDTH 410 39 | #endif 40 | #ifndef SERVO_TIMER1_TOP 41 | /** The top value for XLAT and BLANK pulses. This is with the div8 prescale, 42 | so 43 | \f$\displaystyle f_{PWM} = \frac{f_{osc}}{2 * 8 * SERVO\_TIMER1\_TOP} \f$ 44 | The default is 20000, which corresponds to 50Hz. */ 45 | #define SERVO_TIMER1_TOP 20000 46 | #endif 47 | #ifndef SERVO_TIMER2_TOP 48 | /** The top value for GSCLK pulses. Related to SERVO_TIMER1_TOP by 49 | \f$\displaystyle SERVO\_TIMER2\_TOP = 50 | \frac{2 * 8 * SERVO\_TIMER1\_TOP}{4096} - 1 \f$ 51 | The default is 77. */ 52 | #define SERVO_TIMER2_TOP 77 53 | #endif 54 | 55 | void tlc_initServos(uint8_t initAngle = 0); 56 | void tlc_setServo(TLC_CHANNEL_TYPE channel, uint8_t angle); 57 | uint8_t tlc_getServo(TLC_CHANNEL_TYPE channel); 58 | uint16_t tlc_angleToVal(uint8_t angle); 59 | uint8_t tlc_valToAngle(uint16_t value); 60 | 61 | /** \addtogroup ExtendedFunctions 62 | \code #include "tlc_servos.h" \endcode 63 | - void tlc_initServos(uint8_t initAngle = 0) - initializes the tlc for 64 | servos. 65 | - void tlc_setServo(TLC_CHANNEL_TYPE channel, uint8_t angle) - sets a 66 | servo to an angle 67 | - uint8_t tlc_getServo(TLC_CHANNEL_TYPE channel) - gets the currently set 68 | servo angle */ 69 | /* @{ */ 70 | 71 | /** Initializes the tlc. 72 | \param initAngle the initial angle to set all servos to 73 | (0 - SERVO_MAX_ANGLE). */ 74 | void tlc_initServos(uint8_t initAngle) 75 | { 76 | Tlc.init(tlc_angleToVal(initAngle)); 77 | TCCR1B &= ~(_BV(CS12) | _BV(CS11) | _BV(CS10)); // stop timer1 78 | ICR1 = SERVO_TIMER1_TOP; 79 | TCNT1 = 0; 80 | #ifdef TLC_ATMEGA_8_H 81 | uint8_t oldTCCR2 = TCCR2; 82 | TCCR2 = 0; 83 | TCNT2 = 0; 84 | OCR2 = SERVO_TIMER2_TOP / 2; 85 | TCCR2 = oldTCCR2; 86 | #else 87 | uint8_t oldTCCR2B = TCCR2B; 88 | TCCR2B = 0; 89 | TCNT2 = 0; 90 | OCR2A = SERVO_TIMER2_TOP; 91 | TCCR2B = oldTCCR2B; 92 | #endif 93 | TCCR1B |= _BV(CS11); // start timer1 with div 8 prescale 94 | } 95 | 96 | /** Sets a servo on channel to angle. 97 | \param channel which channel to set 98 | \param angle (0 - SERVO_MAX_ANGLE) */ 99 | void tlc_setServo(TLC_CHANNEL_TYPE channel, uint8_t angle) 100 | { 101 | Tlc.set(channel, tlc_angleToVal(angle)); 102 | } 103 | 104 | /** Gets the current angle that channel is set to. 105 | \param channel which channel to get */ 106 | uint8_t tlc_getServo(TLC_CHANNEL_TYPE channel) 107 | { 108 | return tlc_valToAngle(Tlc.get(channel)); 109 | } 110 | 111 | /** Converts and angle (0 - SERVO_MAX_ANGLE) to the inverted tlc channel value 112 | (4095 - 0). */ 113 | uint16_t tlc_angleToVal(uint8_t angle) 114 | { 115 | return 4095 - SERVO_MIN_WIDTH - ( 116 | ((uint16_t)(angle) * (uint16_t)(SERVO_MAX_WIDTH - SERVO_MIN_WIDTH)) 117 | / SERVO_MAX_ANGLE); 118 | } 119 | 120 | /** Converts an inverted tlc channel value (4095 - 0) into an angle (0 - 121 | SERVO_MAX_ANGLE). */ 122 | uint8_t tlc_valToAngle(uint16_t value) 123 | { 124 | return SERVO_MAX_ANGLE * (4095 - SERVO_MIN_WIDTH - value) 125 | / (SERVO_MAX_WIDTH - SERVO_MIN_WIDTH); 126 | } 127 | 128 | /* @} */ 129 | 130 | #endif 131 | 132 | -------------------------------------------------------------------------------- /libraries/Tlc5940/tlc_shifts.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 by Alex Leone 2 | 3 | This file is part of the Arduino TLC5940 Library. 4 | 5 | The Arduino TLC5940 Library is free software: you can redistribute it 6 | and/or modify it under the terms of the GNU General Public License as 7 | published by the Free Software Foundation, either version 3 of the 8 | License, or (at your option) any later version. 9 | 10 | The Arduino TLC5940 Library is distributed in the hope that it will be 11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with The Arduino TLC5940 Library. If not, see 17 | . */ 18 | 19 | #ifndef TLC_SHIFTS_H 20 | #define TLC_SHIFTS_H 21 | 22 | /** \file 23 | TLC channel shifting functions. */ 24 | 25 | #include "Tlc5940.h" 26 | 27 | uint16_t tlc_shiftUp(uint16_t zeroValue = 0); 28 | uint16_t tlc_shiftDown(uint16_t topValue = 0); 29 | 30 | /** \addtogroup ExtendedFunctions 31 | \code #include "tlc_shifts.h" \endcode 32 | - uint16_t tlc_shiftUp(uint16_t zeroValue = 0) - shifts all channel data 33 | up (OUT0 becomes OUT1 ...) and returns OUT15 34 | - uint16_t tlc_shiftDown(uint16_t topValue = 0) - shifts all channel data 35 | down (OUT15 becomes OUT14 ...) and returns OUT0 */ 36 | /* @{ */ 37 | 38 | /** Shifts all the channel data up (OUT0 becomes OUT1 ...). Needs a 39 | Tlc.update() after. 40 | \param zeroValue the value of channel 0. 41 | \returns the value that was shifted off the end (OUT15) */ 42 | uint16_t tlc_shiftUp(uint16_t zeroValue) 43 | { 44 | uint16_t topValue = ((uint16_t)(*tlc_GSData) << 4) 45 | | (*(tlc_GSData + 1) >> 4); 46 | uint8_t *p = tlc_GSData + 1; 47 | while (p < tlc_GSData + NUM_TLCS * 24 - 1) { 48 | *(p - 1) = (*p << 4) | (*(p + 1) >> 4); 49 | *p = (*(p + 1) << 4) | (*(p + 2) >> 4); 50 | p += 2; 51 | } 52 | *(tlc_GSData + NUM_TLCS * 24 - 2) = (*(tlc_GSData + NUM_TLCS * 24 - 1) << 4) 53 | | ((zeroValue & 0x0F00) >> 8); 54 | *(tlc_GSData + NUM_TLCS * 24 - 1) = (uint8_t)zeroValue; 55 | return topValue; 56 | } 57 | 58 | /** Shifts all the channel data down (OUT 15 -> OUT 14 ...). Needs a 59 | Tlc.update() after. 60 | \param topValue the value of Tlc (n) channel 15. 61 | \returns the value that was shifted off the bottom (OUT0) */ 62 | uint16_t tlc_shiftDown(uint16_t topValue) 63 | { 64 | uint8_t *p = tlc_GSData + NUM_TLCS * 24 - 2; 65 | uint16_t zeroValue = 66 | ((uint16_t)(*(tlc_GSData + NUM_TLCS * 24 - 2) & 0x0F) << 8) 67 | | *(tlc_GSData + NUM_TLCS * 24 - 1); 68 | while (p > tlc_GSData) { 69 | *(p + 1) = (*p >> 4) | (*(p - 1) << 4); 70 | *p = (*(p - 1) >> 4) | (*(p - 2) << 4); 71 | p -= 2; 72 | } 73 | *(tlc_GSData + 1) = (*tlc_GSData >> 4) | ((uint8_t)topValue << 4); 74 | *tlc_GSData = topValue >> 4; 75 | return zeroValue; 76 | } 77 | 78 | /* @} */ 79 | 80 | #endif 81 | 82 | --------------------------------------------------------------------------------