├── .gitattributes ├── .gitignore ├── fire ├── fire.ino └── readme.md ├── hueCycle └── hueCycle.ino ├── patterns └── patterns.ino └── readme.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | [Dd]ebug/ 46 | [Rr]elease/ 47 | *_i.c 48 | *_p.c 49 | *.ilk 50 | *.meta 51 | *.obj 52 | *.pch 53 | *.pdb 54 | *.pgc 55 | *.pgd 56 | *.rsp 57 | *.sbr 58 | *.tlb 59 | *.tli 60 | *.tlh 61 | *.tmp 62 | *.vspscc 63 | .builds 64 | *.dotCover 65 | 66 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 67 | #packages/ 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | 76 | # Visual Studio profiler 77 | *.psess 78 | *.vsp 79 | 80 | # ReSharper is a .NET coding add-in 81 | _ReSharper* 82 | 83 | # Installshield output folder 84 | [Ee]xpress 85 | 86 | # DocProject is a documentation generator add-in 87 | DocProject/buildhelp/ 88 | DocProject/Help/*.HxT 89 | DocProject/Help/*.HxC 90 | DocProject/Help/*.hhc 91 | DocProject/Help/*.hhk 92 | DocProject/Help/*.hhp 93 | DocProject/Help/Html2 94 | DocProject/Help/html 95 | 96 | # Click-Once directory 97 | publish 98 | 99 | # Others 100 | [Bb]in 101 | [Oo]bj 102 | sql 103 | TestResults 104 | *.Cache 105 | ClientBin 106 | stylecop.* 107 | ~$* 108 | *.dbmdl 109 | Generated_Code #added for RIA/Silverlight projects 110 | 111 | # Backup & report files from converting an old project file to a newer 112 | # Visual Studio version. Backup files are not needed, because we have git ;-) 113 | _UpgradeReport_Files/ 114 | Backup*/ 115 | UpgradeLog*.XML 116 | 117 | 118 | 119 | ############ 120 | ## Windows 121 | ############ 122 | 123 | # Windows image file caches 124 | Thumbs.db 125 | 126 | # Folder config file 127 | Desktop.ini 128 | 129 | 130 | ############# 131 | ## Python 132 | ############# 133 | 134 | *.py[co] 135 | 136 | # Packages 137 | *.egg 138 | *.egg-info 139 | dist 140 | build 141 | eggs 142 | parts 143 | bin 144 | var 145 | sdist 146 | develop-eggs 147 | .installed.cfg 148 | 149 | # Installer logs 150 | pip-log.txt 151 | 152 | # Unit test / coverage reports 153 | .coverage 154 | .tox 155 | 156 | #Translations 157 | *.mo 158 | 159 | #Mr Developer 160 | .mr.developer.cfg 161 | 162 | # Mac crap 163 | .DS_Store 164 | -------------------------------------------------------------------------------- /fire/fire.ino: -------------------------------------------------------------------------------- 1 | //'r' for rainbowduino, 'c' for colorduino 2 | #define BOARD 'r' 3 | 4 | #if BOARD == 'c' 5 | #include 6 | #else 7 | #include 8 | #endif 9 | 10 | #define M_WIDTH 8 11 | #define M_HEIGHT 8 12 | 13 | typedef struct 14 | { 15 | unsigned char r; 16 | unsigned char g; 17 | unsigned char b; 18 | } ColorRGB; 19 | 20 | //a color with 3 components: h, s and v 21 | typedef struct 22 | { 23 | unsigned char h; 24 | unsigned char s; 25 | unsigned char v; 26 | } ColorHSV; 27 | 28 | //these values are substracetd from the generated values to give a shape to the animation 29 | const unsigned char valueMask[M_WIDTH][M_HEIGHT]={ 30 | {32 , 0 , 0 , 0 , 0 , 0 , 0 , 32 }, 31 | {64 , 0 , 0 , 0 , 0 , 0 , 0 , 64 }, 32 | {96 , 32 , 0 , 0 , 0 , 0 , 32 , 96 }, 33 | {128, 64 , 32 , 0 , 0 , 32 , 64 , 128}, 34 | {160, 96 , 64 , 32 , 32 , 64 , 96 , 160}, 35 | {192, 128, 96 , 64 , 64 , 96 , 128, 192}, 36 | {255, 160, 128, 96 , 96 , 128, 160, 255}, 37 | {255, 192, 160, 128, 128, 160, 192, 255} 38 | }; 39 | 40 | //these are the hues for the fire, 41 | //should be between 0 (red) to about 13 (yellow) 42 | const unsigned char hueMask[M_WIDTH][M_HEIGHT]={ 43 | {1, 4, 7, 9, 9, 8, 4, 1}, 44 | {1, 3, 5, 7, 9, 7, 3, 1}, 45 | {1, 3, 5, 6, 7, 6, 3, 1}, 46 | {1, 2, 4, 5, 5, 5, 2, 1}, 47 | {1, 2, 4, 4, 4, 4, 2, 1}, 48 | {0, 1, 2, 3, 3, 2, 1, 0}, 49 | {0, 0, 1, 2, 2, 1, 0, 0}, 50 | {0, 0, 0, 1, 1, 0, 0, 0} 51 | }; 52 | 53 | unsigned char matrix[M_WIDTH][M_HEIGHT]; 54 | unsigned char line[M_WIDTH]; 55 | int pcnt = 0; 56 | 57 | //Converts an HSV color to RGB color 58 | void HSVtoRGB(void *vRGB, void *vHSV) 59 | { 60 | float r, g, b, h, s, v; //this function works with floats between 0 and 1 61 | float f, p, q, t; 62 | int i; 63 | ColorRGB *colorRGB=(ColorRGB *)vRGB; 64 | ColorHSV *colorHSV=(ColorHSV *)vHSV; 65 | 66 | h = (float)(colorHSV->h / 256.0); 67 | s = (float)(colorHSV->s / 256.0); 68 | v = (float)(colorHSV->v / 256.0); 69 | 70 | //if saturation is 0, the color is a shade of grey 71 | if(s == 0.0) { 72 | b = v; 73 | g = b; 74 | r = g; 75 | } 76 | //if saturation > 0, more complex calculations are needed 77 | else 78 | { 79 | h *= 6.0; //to bring hue to a number between 0 and 6, better for the calculations 80 | i = (int)(floor(h)); //e.g. 2.7 becomes 2 and 3.01 becomes 3 or 4.9999 becomes 4 81 | f = h - i;//the fractional part of h 82 | 83 | p = (float)(v * (1.0 - s)); 84 | q = (float)(v * (1.0 - (s * f))); 85 | t = (float)(v * (1.0 - (s * (1.0 - f)))); 86 | 87 | switch(i) 88 | { 89 | case 0: r=v; g=t; b=p; break; 90 | case 1: r=q; g=v; b=p; break; 91 | case 2: r=p; g=v; b=t; break; 92 | case 3: r=p; g=q; b=v; break; 93 | case 4: r=t; g=p; b=v; break; 94 | case 5: r=v; g=p; b=q; break; 95 | default: r = g = b = 0; break; 96 | } 97 | } 98 | colorRGB->r = (int)(r * 255.0); 99 | colorRGB->g = (int)(g * 255.0); 100 | colorRGB->b = (int)(b * 255.0); 101 | } 102 | 103 | void setPixel(unsigned char x, unsigned char y, unsigned char colorR, unsigned char colorG, unsigned char colorB){ 104 | #if BOARD == 'c' 105 | Colorduino.SetPixel(x, y, colorR, colorG, colorB); 106 | #else 107 | Rb.setPixelXY(M_HEIGHT-y-1, x, colorR, colorG, colorB); 108 | #endif 109 | } 110 | 111 | /** 112 | * Randomly generate the next line (matrix row) 113 | */ 114 | void generateLine(){ 115 | for(unsigned char x=0;x0;y--) { 127 | for(unsigned char x=0;x0;y--) { 148 | for (unsigned char x=0;x= 100){ 203 | shiftUp(); 204 | generateLine(); 205 | pcnt = 0; 206 | } 207 | drawFrame(pcnt); 208 | #if BOARD == 'c' 209 | Colorduino.FlipPage(); // swap screen buffers to show it 210 | #endif 211 | pcnt+=30; 212 | } 213 | -------------------------------------------------------------------------------- /fire/readme.md: -------------------------------------------------------------------------------- 1 | A fire simulation using an 8x8 RGB LED matrix mounted on a Rainbowduino or Colorduino (Arduino compatible). 2 | 3 | Hardware setup: 4 | ![Hardware setup](http://giladlabs.files.wordpress.com/2013/02/hardware-setup1.jpg) 5 | 6 | See it in action here: http://www.youtube.com/watch?v=AspZ8Np3_Bo -------------------------------------------------------------------------------- /hueCycle/hueCycle.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Gilad Dayagi. All rights reserved. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* 11 | * An example for the Arduino particle system library 12 | * Creates a green flame effect. 13 | */ 14 | 15 | #define DEBUG 1; 16 | //'r' for rainbowduino, 'c' for colorduino 17 | #define BOARD 'r' 18 | 19 | #if BOARD == 'c' 20 | #include 21 | #else 22 | #include 23 | #endif 24 | 25 | #define M_WIDTH 8 26 | #define M_HEIGHT 8 27 | 28 | typedef struct 29 | { 30 | byte r; 31 | byte g; 32 | byte b; 33 | } ColorRGB; 34 | 35 | //a color with 3 components: h, s and v 36 | typedef struct 37 | { 38 | byte h; 39 | byte s; 40 | byte v; 41 | } ColorHSV; 42 | 43 | unsigned int counter; 44 | 45 | void setup() 46 | { 47 | #if BOARD == 'c' 48 | Colorduino.Init(); // initialize the board 49 | 50 | // compensate for relative intensity differences in R/G/B brightness 51 | // array of 6-bit base values for RGB (0~63) 52 | // whiteBalVal[0]=red 53 | // whiteBalVal[1]=green 54 | // whiteBalVal[2]=blue 55 | unsigned char whiteBalVal[3] = { 56 | 36,63,6 }; // for LEDSEE 6x6cm round matrix 57 | Colorduino.SetWhiteBal(whiteBalVal); 58 | #else 59 | Rb.init(); 60 | #endif 61 | 62 | counter = 0; 63 | 64 | #ifdef DEBUG 65 | Serial.begin(9600); 66 | #endif 67 | } 68 | 69 | void loop() 70 | { 71 | ColorRGB colorRGB; 72 | ColorHSV colorHSV; 73 | 74 | colorHSV.v = 255; 75 | colorHSV.s = 255; 76 | colorHSV.h = counter%255; 77 | 78 | HSVtoRGB(&colorRGB, &colorHSV); 79 | uint32_t result = ((((uint32_t)colorRGB.r)<<16) | (((uint32_t)colorRGB.g)<<8) | colorRGB.b); 80 | 81 | #ifdef DEBUG 82 | Serial.print("H: "); 83 | Serial.print(colorHSV.h); 84 | Serial.print(" -> R: "); 85 | Serial.print(colorRGB.r); 86 | Serial.print(" G: "); 87 | Serial.print(colorRGB.g); 88 | Serial.print(" B: "); 89 | Serial.print(colorRGB.b); 90 | Serial.print(" -> "); 91 | Serial.println(result, HEX); 92 | #endif 93 | 94 | #if BOARD == 'c' 95 | Colorduino.ColorFill(colorRGB.r, colorRGB.g, colorRGB.b); 96 | #else 97 | Rb.fillRectangle(0, 0, 8, 8, result); 98 | #endif 99 | counter++; 100 | delay(100); 101 | } 102 | 103 | //Converts an HSV color to RGB color 104 | void HSVtoRGB(void *vRGB, void *vHSV) 105 | { 106 | float r, g, b, h, s, v; //this function works with floats between 0 and 1 107 | float f, p, q, t; 108 | int i; 109 | ColorRGB *colorRGB=(ColorRGB *)vRGB; 110 | ColorHSV *colorHSV=(ColorHSV *)vHSV; 111 | 112 | h = (float)(colorHSV->h / 256.0); 113 | s = (float)(colorHSV->s / 256.0); 114 | v = (float)(colorHSV->v / 256.0); 115 | 116 | //if saturation is 0, the color is a shade of grey 117 | if(s == 0.0) { 118 | b = v; 119 | g = b; 120 | r = g; 121 | } 122 | //if saturation > 0, more complex calculations are needed 123 | else 124 | { 125 | h *= 6.0; //to bring hue to a number between 0 and 6, better for the calculations 126 | i = (int)(floor(h)); //e.g. 2.7 becomes 2 and 3.01 becomes 3 or 4.9999 becomes 4 127 | f = h - i;//the fractional part of h 128 | 129 | p = (float)(v * (1.0 - s)); 130 | q = (float)(v * (1.0 - (s * f))); 131 | t = (float)(v * (1.0 - (s * (1.0 - f)))); 132 | 133 | switch(i) 134 | { 135 | case 0: r=v; g=t; b=p; break; 136 | case 1: r=q; g=v; b=p; break; 137 | case 2: r=p; g=v; b=t; break; 138 | case 3: r=p; g=q; b=v; break; 139 | case 4: r=t; g=p; b=v; break; 140 | case 5: r=v; g=p; b=q; break; 141 | default: r = g = b = 0; break; 142 | } 143 | } 144 | colorRGB->r = (int)(r * 255.0); 145 | colorRGB->g = (int)(g * 255.0); 146 | colorRGB->b = (int)(b * 255.0); 147 | } 148 | -------------------------------------------------------------------------------- /patterns/patterns.ino: -------------------------------------------------------------------------------- 1 | //'r' for rainbowduino, 'c' for colorduino 2 | #define BOARD 'r' 3 | 4 | #if BOARD == 'c' 5 | #include 6 | #else 7 | #include 8 | #endif 9 | 10 | #define M_WIDTH 8 11 | #define M_HEIGHT 8 12 | 13 | void setPixel(unsigned char x, unsigned char y, unsigned char colorR, unsigned char colorG, unsigned char colorB){ 14 | #if BOARD == 'c' 15 | Colorduino.SetPixel(x, y, colorR, colorG, colorB); 16 | #else 17 | Rb.setPixelXY(x, y, colorR, colorG, colorB); 18 | #endif 19 | } 20 | 21 | /** 22 | * red-green gradient 23 | * @param maxi maximum color intensity 24 | */ 25 | void gradRg(unsigned char maxi){ 26 | int mult = maxi / M_WIDTH; 27 | for (unsigned char y=0;y