Components and supplies
DFRobot Screw Shield Wing
ADAFRUIT Switchable 110v Outlet
DFRobot 16*2 LCD Display Shield
Jumper wires (generic)
Arduino UNO
DFRobot Relay Shield 2.1
Tools and machines
Digilent Screwdriver
Project description
Code
ESCplusTOGGLEv2_1.ino
arduino
1 2 /* 3 ******************************************************************************* 4 Base program developed around the DFRobot 4 relay shiel 5 and Hitachi 16*2 LCD,5 Button Display. 6 Relays are reassigned as made necessary by the inclusion of the display, 7 D2,D3,D11, and D12 are used to drive the 4 coils. 8 A1,A2,A3, and A4 are loosely associated with the corresponding relay... 9 A1 thru A4 are configured active low with internal pullups enabled. 10 The basic loop structure incorporates debouncing without delay commands. 11 12 Escape V2.1- Input 1 (A1) triggers Relay A for 0.5 sec, 13 Relay B for 20 seconds. 14 RelayA- BRIGHTSIGN Video Playback, RelayB Effect Output 15 ***************************************************************************** */ 16 17 18 19// set pin numbers: 20const int buttonAPin = A1; // the number of the pushbutton pins 21const int buttonBPin = A2; // 22const int buttonCPin = A3; // 23const int buttonDPin = A4; // 24const int ledPin = 13; // the number of the LED pin 25const int RelayA =2; // the number of the relay coil drive pin 26const int RelayB =3; // 27const int RelayC =11; // 28const int RelayD =12; // 29// Variables will change: 30 31 32int buttonAState; // 33int lastButtonAState = HIGH; // 34 35int buttonBState; // 36int lastButtonBState = HIGH; // 37int toggleStateB; 38 39int buttonCState; // 40int lastButtonCState = HIGH; // 41 42int buttonDState; // 43int lastButtonDState = HIGH; // 44 45// the following variables are long's because the time, measured in miliseconds, 46// will quickly become a bigger number than can be stored in an int. 47 48long lastDebounceTimeA = 0; // the last time the output pin was toggled 49long lastDebounceTimeB = 0; // the last time the output pin was toggled 50long lastDebounceTimeC = 0; // the last time the output pin was toggled 51long lastDebounceTimeD = 0; // the last time the output pin was toggled 52long debounceDelay = 50; // the debounce time; increase if the output flickers 53long loopdelayA =1000; 54long looptriggerA; 55long loopdelayB =20000; 56long looptriggerB; 57 58#include <LiquidCrystal.h> 59 60// Select the pin used on LCD 61LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 62 63// define the button 64int lcd_key = 0; 65int adc_key_in = 0; 66#define btnRIGHT 0 67#define btnUP 1 68#define btnDOWN 2 69#define btnLEFT 3 70#define btnSELECT 4 71#define btnNONE 5 72 73//read the button value 74int read_LCD_buttons() 75{ 76 adc_key_in = analogRead(0); // read analog A0 value 77 // when read the 5 key values in the vicinity of the following0,144,329,504,741 78 // By setting different threshold, you can read the one button 79 80 if (adc_key_in < 50) return btnRIGHT; 81 if (adc_key_in < 250) return btnUP; 82 if (adc_key_in < 450) return btnDOWN; 83 if (adc_key_in < 650) return btnLEFT; 84 if (adc_key_in < 850) return btnSELECT; 85 return btnNONE; 86} 87 88void setup() 89{ 90 lcd.begin(16, 2); 91 lcd.setCursor(0,0); 92 lcd.print("KEVino 2017"); 93 lcd.setCursor(0,1); 94 lcd.print("Escape Room"); 95 delay(1000); 96 // scroll 16 positions (string length) to the left 97 // to move it offscreen left: 98 for (int positionCounter = 0; positionCounter < 16; positionCounter++) { 99 // scroll one position left: 100 lcd.scrollDisplayRight(); 101 // wait a bit: 102 delay(300); 103 } 104 { 105 lcd.begin(16, 2); 106 lcd.setCursor(0,0); 107 lcd.print("ESCAPE VIDEO"); 108 } 109 110 // initialize the LED pin as an output: 111 pinMode(ledPin, OUTPUT); 112 // initialize the Relay drive pin as an output: 113 pinMode(RelayA, OUTPUT); 114 // initialize the pushbutton pin as an input: 115 pinMode(buttonAPin, INPUT_PULLUP); 116 pinMode(RelayB, OUTPUT); 117 // initialize the pushbutton pin as an input: 118 pinMode(buttonBPin, INPUT_PULLUP); 119 pinMode(RelayC, OUTPUT); 120 // initialize the pushbutton pin as an input: 121 pinMode(buttonCPin, INPUT_PULLUP); 122 pinMode(RelayD, OUTPUT); 123 // initialize the pushbutton pin as an input: 124 pinMode(buttonDPin, INPUT_PULLUP); 125 126} 127 128void loop() 129{ 130 lcd.setCursor(13,0); 131 lcd.print(millis()/1000); 132 133 // read the state of the switch A into a local variable: 134 int readingA = digitalRead(buttonAPin); 135 136 // check to see if you just pressed the button 137 // If the switch changed, due to noise or pressing: 138 139 if (readingA != lastButtonAState) { 140 141 // reset the debouncing timer 142 143 lastDebounceTimeA = millis(); 144 looptriggerA = millis(); 145 looptriggerB = millis(); 146 147 } 148 if ((millis() - lastDebounceTimeA) > debounceDelay) { 149 // whatever the reading is at, it's been there for longer than the 150 // debounce delay, so take it as the actual current state: 151 152 // if the button state has changed: 153 if (readingA != buttonAState) { 154 buttonAState = readingA; 155 156 157 // action if the new button state is LOW 158 if (buttonAState == LOW) { 159 160 lcd.setCursor(0,1); 161 lcd.print("A1"); 162 163 digitalWrite(ledPin, HIGH); 164 digitalWrite(RelayA, HIGH); 165 166 lcd.setCursor(7,1); 167 lcd.print("D2"); 168 lcd.setCursor(13,1); 169 lcd.print("R1"); 170 171 digitalWrite(RelayB, HIGH); 172 lcd.setCursor(4,1); 173 lcd.print("D3"); 174 lcd.setCursor(10,1); 175 lcd.print("R2"); 176 } 177 } 178 // action after loop delay "A" has expired 179 if ((millis() - looptriggerA) >loopdelayA ) { 180 lcd.setCursor(0,1); 181 lcd.print(" " ); 182 lcd.setCursor(7,1); 183 lcd.print(" "); 184 185 lcd.setCursor(13,1); 186 lcd.print(" "); 187 digitalWrite(ledPin, LOW); 188 digitalWrite(RelayA, LOW); 189 } 190 // action after loop delay "B" has expired 191 if ((millis() - looptriggerB) >loopdelayB ) { 192 lcd.setCursor(0,1); 193 lcd.print(" " ); 194 lcd.setCursor(4,1); 195 lcd.print(" "); 196 lcd.setCursor(10,1); 197 lcd.print(" "); 198 digitalWrite(ledPin, LOW); 199 digitalWrite(RelayB, LOW); 200 } 201 } 202 // save the reading. Next time through the loop, 203 // it'll be the lastButtonState: 204 205 lastButtonAState = readingA; 206 207 // ************this ends the loop for switch input A.********** 208 //************************************************************* 209 210 // ***read the state of the switch B into a local variable:*** 211 212 int readingB = digitalRead(buttonBPin); 213 214 // check to see if you just pressed the button 215 // If the switch changed, due to noise or pressing: 216 217 if (readingB != lastButtonBState) { 218 219 // reset the debouncing timer 220 221 lastDebounceTimeB = millis(); 222 223 } 224 if ((millis() - lastDebounceTimeB) > debounceDelay) { 225 // whatever the reading is at, it's been there for longer than the 226 // debounce delay, so take it as the actual current state: 227 228 // if the button state has changed: 229 if (readingB != buttonBState) { 230 buttonBState = readingB; 231 232 233 // action if the new button state is LOW 234 if (buttonAState == LOW) 235 236 toggleStateB = !toggleStateB; 237 238 // set Relay C: 239 240 digitalWrite(RelayC, toggleStateB); 241 if (toggleStateB == LOW) { 242 243 lcd.setCursor(0,1); 244 lcd.print(" "); 245 } 246 else{ 247 lcd.setCursor(0,1); 248 lcd.print("RELAY C"); 249 } 250 251 // save the reading. Next time through the loop, 252 // it'll be the lastButtonState: 253 lastButtonBState = readingB; 254 } 255 } 256 257 // ************LCD BUTTON INPUT************ 258 259 lcd.setCursor(0,1); 260 lcd_key = read_LCD_buttons(); // read key 261 262 switch (lcd_key) // display key 263 { 264 /* case btnRIGHT: 265 { 266 lcd.print("RIGHT "); 267 break; 268 } 269 case btnLEFT: 270 { 271 lcd.print("LEFT "); 272 break; 273 } 274 case btnUP: 275 { 276 lcd.print("UP "); 277 break; 278 } 279 case btnDOWN: 280 { 281 lcd.print("DOWN "); 282 break; 283 } 284 */ 285 case btnSELECT: 286 { 287 lcd.begin(16, 2); 288 lcd.setCursor(0,0); 289 lcd.print("dont touch"); 290 delay(3000); 291 lcd.begin(16, 2); 292 lcd.setCursor(0,0); 293 lcd.print("KEVino 2017"); 294 break; 295 } 296 /* case btnNONE: 297 { 298 lcd.print(" "); 299 break; 300 } 301 */ 302 } 303} 304 305 306 307 308 309 310
ESCplusTOGGLEv2_1.ino
arduino
1 2 /* 3 ******************************************************************************* 4 5 Base program developed around the DFRobot 4 relay shiel 6 and Hitachi 7 16*2 LCD,5 Button Display. 8 Relays are reassigned as made necessary by the 9 inclusion of the display, 10 D2,D3,D11, and D12 are used to drive the 4 coils. 11 12 A1,A2,A3, and A4 are loosely associated with the corresponding relay... 13 14 A1 thru A4 are configured active low with internal pullups enabled. 15 The 16 basic loop structure incorporates debouncing without delay commands. 17 18 19 Escape V2.1- Input 1 (A1) triggers Relay A for 0.5 sec, 20 Relay 21 B for 20 seconds. 22 RelayA- BRIGHTSIGN Video Playback, RelayB 23 Effect Output 24 ***************************************************************************** 25 */ 26 27 28 29// set pin numbers: 30const int buttonAPin = A1; // the 31 number of the pushbutton pins 32const int buttonBPin = A2; // 33const int 34 buttonCPin = A3; // 35const int buttonDPin = A4; // 36const int ledPin 37 = 13; // the number of the LED pin 38const int RelayA =2; // the number 39 of the relay coil drive pin 40const int RelayB =3; // 41const int RelayC 42 =11; // 43const int RelayD =12; // 44// Variables will change: 45 46 47int 48 buttonAState; // 49int lastButtonAState = HIGH; // 50 51int 52 buttonBState; // 53int lastButtonBState = HIGH; // 54int toggleStateB; 55 56int 57 buttonCState; // 58int lastButtonCState = HIGH; // 59 60int buttonDState; 61 // 62int lastButtonDState = HIGH; // 63 64// the following variables 65 are long's because the time, measured in miliseconds, 66// will quickly become 67 a bigger number than can be stored in an int. 68 69long lastDebounceTimeA = 0; 70 // the last time the output pin was toggled 71long lastDebounceTimeB = 0; // 72 the last time the output pin was toggled 73long lastDebounceTimeC = 0; // the 74 last time the output pin was toggled 75long lastDebounceTimeD = 0; // the last 76 time the output pin was toggled 77long debounceDelay = 50; // the debounce time; 78 increase if the output flickers 79long loopdelayA =1000; 80long looptriggerA; 81long 82 loopdelayB =20000; 83long looptriggerB; 84 85#include <LiquidCrystal.h> 86 87// 88 Select the pin used on LCD 89LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 90 91// define 92 the button 93int lcd_key = 0; 94int adc_key_in = 0; 95#define btnRIGHT 0 96#define 97 btnUP 1 98#define btnDOWN 2 99#define btnLEFT 3 100#define btnSELECT 4 101#define 102 btnNONE 5 103 104//read the button value 105int read_LCD_buttons() 106{ 107 adc_key_in 108 = analogRead(0); // read analog A0 value 109 // when read the 5 key values 110 in the vicinity of the following0,144,329,504,741 111 // By setting different threshold, 112 you can read the one button 113 114 if (adc_key_in < 50) return btnRIGHT; 115 116 if (adc_key_in < 250) return btnUP; 117 if (adc_key_in < 450) return btnDOWN; 118 119 if (adc_key_in < 650) return btnLEFT; 120 if (adc_key_in < 850) return 121 btnSELECT; 122 return btnNONE; 123} 124 125void setup() 126{ 127 lcd.begin(16, 128 2); 129 lcd.setCursor(0,0); 130 lcd.print("KEVino 2017"); 131 132 lcd.setCursor(0,1); 133 lcd.print("Escape Room"); 134 delay(1000); 135 // 136 scroll 16 positions (string length) to the left 137 // to move it offscreen left: 138 139 for (int positionCounter = 0; positionCounter < 16; positionCounter++) { 140 // 141 scroll one position left: 142 lcd.scrollDisplayRight(); 143 // wait a bit: 144 145 delay(300); 146 } 147 { 148 lcd.begin(16, 2); 149 lcd.setCursor(0,0); 150 151 lcd.print("ESCAPE VIDEO"); 152 } 153 154 // initialize the LED pin as 155 an output: 156 pinMode(ledPin, OUTPUT); 157 // initialize the Relay drive pin 158 as an output: 159 pinMode(RelayA, OUTPUT); 160 // initialize the pushbutton 161 pin as an input: 162 pinMode(buttonAPin, INPUT_PULLUP); 163 pinMode(RelayB, 164 OUTPUT); 165 // initialize the pushbutton pin as an input: 166 pinMode(buttonBPin, 167 INPUT_PULLUP); 168 pinMode(RelayC, OUTPUT); 169 // initialize the pushbutton 170 pin as an input: 171 pinMode(buttonCPin, INPUT_PULLUP); 172 pinMode(RelayD, 173 OUTPUT); 174 // initialize the pushbutton pin as an input: 175 pinMode(buttonDPin, 176 INPUT_PULLUP); 177 178} 179 180void loop() 181{ 182 lcd.setCursor(13,0); 183 184 lcd.print(millis()/1000); 185 186 // read the state of the switch A into 187 a local variable: 188 int readingA = digitalRead(buttonAPin); 189 190 // check 191 to see if you just pressed the button 192 // If the switch changed, due to noise 193 or pressing: 194 195 if (readingA != lastButtonAState) { 196 197 // reset the 198 debouncing timer 199 200 lastDebounceTimeA = millis(); 201 looptriggerA = 202 millis(); 203 looptriggerB = millis(); 204 205 } 206 if ((millis() - lastDebounceTimeA) 207 > debounceDelay) { 208 // whatever the reading is at, it's been there for longer 209 than the 210 // debounce delay, so take it as the actual current state: 211 212 213 // if the button state has changed: 214 if (readingA != buttonAState) { 215 216 buttonAState = readingA; 217 218 219 // action if the new 220 button state is LOW 221 if (buttonAState == LOW) { 222 223 lcd.setCursor(0,1); 224 225 lcd.print("A1"); 226 227 digitalWrite(ledPin, HIGH); 228 229 digitalWrite(RelayA, HIGH); 230 231 lcd.setCursor(7,1); 232 233 lcd.print("D2"); 234 lcd.setCursor(13,1); 235 lcd.print("R1"); 236 237 238 digitalWrite(RelayB, HIGH); 239 lcd.setCursor(4,1); 240 241 lcd.print("D3"); 242 lcd.setCursor(10,1); 243 lcd.print("R2"); 244 245 } 246 } 247 // action after loop delay "A" has expired 248 if 249 ((millis() - looptriggerA) >loopdelayA ) { 250 lcd.setCursor(0,1); 251 252 lcd.print(" " ); 253 lcd.setCursor(7,1); 254 lcd.print(" 255 "); 256 257 lcd.setCursor(13,1); 258 lcd.print(" "); 259 260 digitalWrite(ledPin, LOW); 261 digitalWrite(RelayA, LOW); 262 263 } 264 // action after loop delay "B" has expired 265 if ((millis() 266 - looptriggerB) >loopdelayB ) { 267 lcd.setCursor(0,1); 268 lcd.print(" 269 " ); 270 lcd.setCursor(4,1); 271 lcd.print(" "); 272 lcd.setCursor(10,1); 273 274 lcd.print(" "); 275 digitalWrite(ledPin, LOW); 276 digitalWrite(RelayB, 277 LOW); 278 } 279 } 280 // save the reading. Next time through the loop, 281 282 // it'll be the lastButtonState: 283 284 lastButtonAState = readingA; 285 286 287 // ************this ends the loop for switch input A.********** 288 //************************************************************* 289 290 291 // ***read the state of the switch B into a local variable:*** 292 293 294 int readingB = digitalRead(buttonBPin); 295 296 // check to see if you just 297 pressed the button 298 // If the switch changed, due to noise or pressing: 299 300 301 if (readingB != lastButtonBState) { 302 303 // reset the debouncing timer 304 305 306 lastDebounceTimeB = millis(); 307 308 } 309 if ((millis() - lastDebounceTimeB) 310 > debounceDelay) { 311 // whatever the reading is at, it's been there for longer 312 than the 313 // debounce delay, so take it as the actual current state: 314 315 316 // if the button state has changed: 317 if (readingB != buttonBState) { 318 319 buttonBState = readingB; 320 321 322 // action if the new 323 button state is LOW 324 if (buttonAState == LOW) 325 326 toggleStateB 327 = !toggleStateB; 328 329 // set Relay C: 330 331 digitalWrite(RelayC, 332 toggleStateB); 333 if (toggleStateB == LOW) { 334 335 lcd.setCursor(0,1); 336 337 lcd.print(" "); 338 } 339 else{ 340 lcd.setCursor(0,1); 341 342 lcd.print("RELAY C"); 343 } 344 345 // save the reading. 346 Next time through the loop, 347 // it'll be the lastButtonState: 348 lastButtonBState 349 = readingB; 350 } 351 } 352 353 // ************LCD BUTTON INPUT************ 354 355 356 lcd.setCursor(0,1); 357 lcd_key = read_LCD_buttons(); // read key 358 359 360 switch (lcd_key) // display key 361 { 362 /* case btnRIGHT: 363 { 364 365 lcd.print("RIGHT "); 366 break; 367 } 368 case btnLEFT: 369 { 370 371 lcd.print("LEFT "); 372 break; 373 } 374 case btnUP: 375 { 376 377 lcd.print("UP "); 378 break; 379 } 380 case btnDOWN: 381 { 382 383 lcd.print("DOWN "); 384 break; 385 } 386 */ 387 case btnSELECT: 388 389 { 390 lcd.begin(16, 2); 391 lcd.setCursor(0,0); 392 lcd.print("dont 393 touch"); 394 delay(3000); 395 lcd.begin(16, 2); 396 lcd.setCursor(0,0); 397 398 lcd.print("KEVino 2017"); 399 break; 400 } 401 /* case btnNONE: 402 403 { 404 lcd.print(" "); 405 break; 406 } 407 */ 408 } 409} 410 411 412 413 414 415 416 417
Downloadable files
Adafruit Switched outlet powerbar
Adafruit Switched outlet powerbar
Kevino Museum Interface
Generic minimum configuration platform for kiosk / exhibit automation.
Kevino Museum Interface
Adafruit Switched outlet powerbar
Adafruit Switched outlet powerbar
Comments
Only logged in users can leave comments
KevinMcArthur
0 Followers
•0 Projects
Table of contents
Intro
0
0