Components and supplies
12V Power Supply - to power the Octowide Light modules
Arduino UNO
Jumper wires (generic)
Keyes KY-022
Apps and platforms
Arduino IDE
Project description
Code
Octowide Digital Light - 2 Warm x 2 Cold
c_cpp
With this code you will be able to control 2 sets of octowide light with an infrared remote controller - tweaking the brightness, color temperature and fade speed.
1/* octowide.com Example 2 2 Warm White Octowide x 2 Cold White Octowide 3 Light 3W modules Demo 4 info@octowide.com 5 Get Library at: https://github.com/shirriff/Arduino-IRremote 6 7 Unzip folder into Libraries. RENAME folder IRremote 8*/ 9 10/*-----( Import 11 needed libraries )-----*/ 12 13/* Get Library at: https://github.com/shirriff/Arduino-IRremote 14 15 Unzip folder into Libraries. RENAME folder IRremote 16 NOTE!! If you have a late 17 version of Arduino with a library IRRobotRemote, it may conflict and you may have 18 to remove that library. 19 Make sure to delete Arduino_Root/libraries/RobotIRremote. 20 21 Where Arduino_Root refers to the install directory of Arduino. The library RobotIRremote 22 has similar definitions to IRremote and causes errors. 23 */ 24#include "IRremote.h" 25 26/*-----( 27 Declare Constants )-----*/ 28const int ir_receiver = 12; // pin 29 1 of IR receiver to Arduino digital pin 12 30 31/*-----( Declare objects )-----*/ 32IRrecv 33 irrecv(ir_receiver); // create instance of 'irrecv' 34decode_results 35 results; // create instance of 'decode_results' 36 37/*-----( 38 Declare Variables )-----*/ 39int Warm_White_Level = 0; // brightness 40 level of Octowide Warm White (0 - 255) 41int New_Warm_White_Level = 0; // 42 new brightness level of Octowide Warm White (0 - 255) 43int Cold_White_Level = 44 0; // brightness level of Octowide Cold White (0 - 255) 45int 46 New_Cold_White_Level = 0; // new brightness level of Octowide Cold 47 White (0 - 255) 48int Step = 1; // brightness update 49 step - 1 for the slowest transition to 255 for immediate transition 50enum channel 51{ 52 53 WARM_WHITE = 9, // Arduino Digital pin 9 connected 54 to Octowide (Warm White) Signal pin 55 COLD_WHITE = 10 // 56 Arduino Digital pin 10 connected to Octowide (Cold White) Signal pin 57}; 58enum 59 channel channel_selected = WARM_WHITE; // Default Channel selected 60 61void 62 setup() /*----( SETUP: RUNS ONCE )----*/ 63{ 64 analogWrite(WARM_WHITE, Warm_White_Level); 65 // Set initial Warm White Level 66 analogWrite(COLD_WHITE, Cold_White_Level); 67 // Set initial Cold White Level 68 Serial.begin(9600); 69 Serial.println("Octowide 70 2 Warm x 2 Cold Demo"); 71 Serial.println("More Info: info@octowide.com"); 72 73 irrecv.enableIRIn(); // Start the infrared receiver 74} 75 76void loop() 77 /*----( LOOP: RUNS CONSTANTLY )----*/ 78{ 79 static int cnt = 0; 80 81 82 if (cnt++ == 5) // Check for a new IR once each 50ms 83 { 84 if (irrecv.decode(&results)) 85 // have we received an IR signal? 86 { 87 translateIR(); 88 irrecv.resume(); 89 // receive the next value 90 } 91 cnt = 0; 92 } 93 94 // Update Warm 95 White Channel (if needed) 96 if (Warm_White_Level != New_Warm_White_Level) 97 98 update_level(WARM_WHITE, Warm_White_Level, New_Warm_White_Level); 99 100 // 101 Update Cold White Channel (if needed) 102 if (Cold_White_Level != New_Cold_White_Level) 103 104 update_level(COLD_WHITE, Cold_White_Level, New_Cold_White_Level); 105 106 delay(10); 107 // Wait a bit 108} 109 110/*-----( Declare User-written Functions )-----*/ 111 112/* 113 Low level brightness update function */ 114void update_level(enum channel ch, int 115 &level, int &new_level) 116{ 117 if (level < new_level) 118 { 119 level += 120 Step; 121 if (level > new_level) 122 level = new_level; 123 } else { 124 125 level -= Step; 126 if (level < new_level) 127 level = new_level; 128 129 } 130 analogWrite(ch, level); 131} 132 133/* Function stating what to do when 134 receiving an IR code 135 * 1 - Warm White channel selected 136 * 2 - Cold White 137 channel selected 138 * UP - increase brightness by aprox. 20% (on the channel selected) 139 140 * DWN - decrease brightness by aprox. 20% (on the channel selected) 141 * 0 - 142 Fade down both channels 143 * 4 - Max Brightness Warm White channel 144 * 5 - 145 Max Brightness Both channels 146 * 6 - Max Brightness Cold White channel 147 * 148 7 - Slow Fade (transition) 149 * 8 - Fast Fade (transition) 150 * 9 - No Fade 151 152 * Code received / action taken sent by serial port 153 */ 154void translateIR() 155 // takes action based on IR code received 156 157// describing KEYES Remote IR codes 158 159{ 160 int level; 161 162 switch(results.value) 163 { 164 case 0xFF6897: 165 Serial.println("WARM WHITE channel selected"); 166 channel_selected = WARM_WHITE; 167 168 break; 169 170 case 0xFF9867: Serial.println("COLD WHITE channel selected"); 171 172 channel_selected = COLD_WHITE; 173 break; 174 175 case 0xFF629D: 176 Serial.println("UP 20%"); 177 if (channel_selected == WARM_WHITE) 178 fade_channels(Warm_White_Level 179 + 51, Cold_White_Level); 180 else fade_channels(Warm_White_Level, Cold_White_Level 181 + 51); 182 break; 183 184 case 0xFFA857: Serial.println("DOWN 20%"); 185 186 if (channel_selected == WARM_WHITE) 187 fade_channels(Warm_White_Level 188 - 51, Cold_White_Level); 189 else fade_channels(Warm_White_Level, Cold_White_Level 190 - 51); 191 break; 192 193 case 0xFF4AB5: Serial.println("Fade DOWN"); 194 195 fade_channels(0, 0); 196 break; 197 198 case 0xFF30CF: Serial.println("MAX 199 Warm White"); 200 fade_channels(255, 0); 201 break; 202 203 204 case 0xFF18E7: Serial.println("MAX Both channels"); 205 fade_channels(255, 206 255); 207 break; 208 case 0xFF7A85: Serial.println("MAX Cold White"); 209 210 fade_channels(0, 255); 211 break; 212 213 case 0xFF10EF: Serial.println("SLOW 214 fade"); 215 Step = 1; 216 break; 217 218 case 0xFF38C7: 219 Serial.println("FAST fade"); 220 Step = 4; 221 break; 222 223 224 case 0xFF5AA5: Serial.println("NO fade"); 225 Step = 255; 226 break; 227 228 } 229} 230 231/* Update global new brightness values to start fading 232 * Serial 233 print of start and new brightness for each channel 234 */ 235void fade_channels(int 236 new_warm_level, int new_cold_level) 237{ 238 char buf[32]; 239 240 // Sanitize 241 both levels 242 New_Warm_White_Level = sanitize_level(new_warm_level); 243 New_Cold_White_Level 244 = sanitize_level(new_cold_level); 245 246 sprintf(buf, "WARM %3d > %3d | COLD 247 %3d > %3d", Warm_White_Level, New_Warm_White_Level, Cold_White_Level, New_Cold_White_Level); 248 249 Serial.println(buf); 250} 251 252/* Check the boundaries - max / min allowable 253 brightness levels */ 254int sanitize_level(int level) 255{ 256 if (level > 255) 257 258 return 255; 259 else if (level < 0) 260 return 0; 261 return level; 262} 263/* 264 ( THE END ) */
Downloadable files
Octowide Digital Light - 2 Warm x 2 Cold
Circuit Diagram to build the 2x2 Octowide Light project
Octowide Digital Light - 2 Warm x 2 Cold
Octowide Digital Light - 2 Warm x 2 Cold
Circuit Diagram to build the 2x2 Octowide Light project
Octowide Digital Light - 2 Warm x 2 Cold
Comments
Only logged in users can leave comments