KevinMcArthur
Published

KEVino General Purpose I/O

A generic setup for museum exhibit automation. DFRobot 4 relay shield 2.1 and screw shields, Hitachi 16*2 Display shield on UNO or Mega.

BeginnerWork in progress1,426
KEVino General Purpose I/O

Things used in this project

Hardware components

DFRobot Relay Shield 2.1
×1
DFRobot 16*2 LCD Display Shield
×1
DFRobot Screw Shield Wing
×1
ADAFRUIT Switchable 110v Outlet
×1
Arduino UNO
Arduino UNO
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Hand tools and fabrication machines

Digilent Screwdriver
Digilent Screwdriver

Story

Read more

Schematics

Kevino Museum Interface

Generic minimum configuration platform for kiosk / exhibit automation.

Adafruit Switched outlet powerbar

Code

ESCplusTOGGLEv2_1.ino

Arduino
  /*
   *******************************************************************************
     Base program developed around the DFRobot 4 relay shiel
     and Hitachi 16*2 LCD,5 Button Display.
     Relays are reassigned as made necessary by the inclusion of the display,
     D2,D3,D11, and D12 are used to drive the 4 coils.
     A1,A2,A3, and A4  are loosely associated with the corresponding relay...
     A1 thru A4 are configured active low with internal pullups enabled.
     The basic loop structure incorporates debouncing without delay commands.
                                                                                                         
     Escape V2.1- Input 1 (A1) triggers Relay A for 0.5 sec, 
                                        Relay B for 20 seconds. 
                  RelayA- BRIGHTSIGN Video Playback,  RelayB Effect Output                                 
   ***************************************************************************** */


  
// set pin numbers:
const int buttonAPin = A1;     // the number of the pushbutton pins
const int buttonBPin = A2;     // 
const int buttonCPin = A3;     // 
const int buttonDPin = A4;     // 
const int ledPin =  13;      // the number of the LED pin
const int RelayA =2;      // the number of the relay coil drive pin
const int RelayB =3;      // 
const int RelayC =11;      // 
const int RelayD =12;      // 
// Variables will change:


int buttonAState;             // 
int lastButtonAState = HIGH;   // 
 
int buttonBState;             // 
int lastButtonBState = HIGH;   // 
int toggleStateB;

int buttonCState;             // 
int lastButtonCState = HIGH;   //

int buttonDState;             // 
int lastButtonDState = HIGH;   // 

// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.

long lastDebounceTimeA = 0;  // the last time the output pin was toggled
long lastDebounceTimeB = 0;  // the last time the output pin was toggled
long lastDebounceTimeC = 0;  // the last time the output pin was toggled
long lastDebounceTimeD = 0;  // the last time the output pin was toggled
long debounceDelay = 50;    // the debounce time; increase if the output flickers
long loopdelayA =1000;
long looptriggerA;
long loopdelayB =20000;
long looptriggerB;

#include <LiquidCrystal.h>

// Select the pin used on LCD
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

// define the button
int lcd_key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

//read the button value
int read_LCD_buttons()
{
  adc_key_in = analogRead(0);          // read analog A0 value 
  // when read the 5 key values in the vicinity of the following0,144,329,504,741
  // By setting different threshold, you can read the one button
  
  if (adc_key_in < 50)   return btnRIGHT;  
  if (adc_key_in < 250)  return btnUP; 
  if (adc_key_in < 450)  return btnDOWN; 
  if (adc_key_in < 650)  return btnLEFT; 
  if (adc_key_in < 850)  return btnSELECT; 
  return btnNONE; 
}

void setup()
{
  lcd.begin(16, 2);                
  lcd.setCursor(0,0);
  lcd.print("KEVino 2017");
  lcd.setCursor(0,1);
  lcd.print("Escape Room");
  delay(1000);
   // scroll 16 positions (string length) to the left 
  // to move it offscreen left:
  for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
    // scroll one position left:
    lcd.scrollDisplayRight(); 
    // wait a bit:
    delay(300);
  }
  { 
    lcd.begin(16, 2); 
    lcd.setCursor(0,0);
    lcd.print("ESCAPE VIDEO"); 
  }
  
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);   
  // initialize the Relay drive pin as an output:
  pinMode(RelayA, OUTPUT);    
  // initialize the pushbutton pin as an input:
  pinMode(buttonAPin, INPUT_PULLUP);  
   pinMode(RelayB, OUTPUT);    
  // initialize the pushbutton pin as an input:
  pinMode(buttonBPin, INPUT_PULLUP);  
   pinMode(RelayC, OUTPUT);    
  // initialize the pushbutton pin as an input:
  pinMode(buttonCPin, INPUT_PULLUP);  
   pinMode(RelayD, OUTPUT);    
  // initialize the pushbutton pin as an input:
  pinMode(buttonDPin, INPUT_PULLUP);  
 
}

void loop() 
{
    lcd.setCursor(13,0);
    lcd.print(millis()/1000);
  
  // read the state of the switch A into a local variable:
  int readingA = digitalRead(buttonAPin);
    
  // check to see if you just pressed the button 
  // If the switch changed, due to noise or pressing:

  if (readingA != lastButtonAState) {

    // reset the debouncing timer

    lastDebounceTimeA = millis();
    looptriggerA = millis();
    looptriggerB = millis();
  
  } 
 if ((millis() - lastDebounceTimeA) > debounceDelay) {
    // whatever the reading is at, it's been there for longer than the 
    // debounce delay, so take it as the actual current state:

    // if the button state has changed:
    if (readingA != buttonAState) {
      buttonAState = readingA;
      
      
      // action if the new button state is LOW
      if (buttonAState == LOW) {
       
         lcd.setCursor(0,1);
         lcd.print("A1"); 
   
        digitalWrite(ledPin, HIGH); 
        digitalWrite(RelayA, HIGH);
       
        lcd.setCursor(7,1);
        lcd.print("D2");
        lcd.setCursor(13,1);
        lcd.print("R1");
       
        digitalWrite(RelayB, HIGH);
        lcd.setCursor(4,1);
        lcd.print("D3");
        lcd.setCursor(10,1);
        lcd.print("R2");
      }  
    }
       // action after loop delay "A" has expired
          if ((millis() - looptriggerA) >loopdelayA ) {  
         lcd.setCursor(0,1);
         lcd.print("  " );
         lcd.setCursor(7,1);
         lcd.print("  ");
         
         lcd.setCursor(13,1);
         lcd.print("  ");
          digitalWrite(ledPin, LOW); 
          digitalWrite(RelayA, LOW); 
    }
       // action after loop delay "B" has expired
      if ((millis() - looptriggerB) >loopdelayB ) {  
         lcd.setCursor(0,1);
         lcd.print("  " );
         lcd.setCursor(4,1);
         lcd.print("  ");
         lcd.setCursor(10,1);
         lcd.print("  ");
         digitalWrite(ledPin, LOW); 
         digitalWrite(RelayB, LOW); 
      }
  }   
  // save the reading. Next time through the loop,
  // it'll be the lastButtonState:
 
        lastButtonAState = readingA;
  
  // ************this ends the loop for switch input A.**********
  //*************************************************************
  
   // ***read the state of the switch B into a local variable:***
   
  int readingB = digitalRead(buttonBPin);
    
  // check to see if you just pressed the button 
  // If the switch changed, due to noise or pressing:

  if (readingB != lastButtonBState) {

    // reset the debouncing timer

    lastDebounceTimeB = millis();

  } 
 if ((millis() - lastDebounceTimeB) > debounceDelay) {
    // whatever the reading is at, it's been there for longer than the 
    // debounce delay, so take it as the actual current state:

    // if the button state has changed:
    if (readingB != buttonBState) {
      buttonBState = readingB;
      
      
      // action if the new button state is LOW
      if (buttonAState == LOW) 
    
      toggleStateB = !toggleStateB;
      
      // set Relay C:
  
      digitalWrite(RelayC, toggleStateB);
      if (toggleStateB == LOW) {
 
        lcd.setCursor(0,1);
        lcd.print("      ");
      }
      else{
         lcd.setCursor(0,1);
        lcd.print("RELAY C");
      }
        
  // save the reading. Next time through the loop, 
  // it'll be the lastButtonState:
  lastButtonBState = readingB;
  } 
 }   
 
 // ************LCD BUTTON INPUT************
  
  lcd.setCursor(0,1);  
  lcd_key = read_LCD_buttons();  // read key

 switch (lcd_key)               // display key
 {
 /*  case btnRIGHT:
     {
     lcd.print("RIGHT ");
     break;
     }
   case btnLEFT:
     {
     lcd.print("LEFT   ");
     break;
     }
   case btnUP:
     {
     lcd.print("UP    ");
     break;
     }
   case btnDOWN:
     {
     lcd.print("DOWN  ");
     break;
     }
     */
   case btnSELECT:
     {
    lcd.begin(16, 2); 
    lcd.setCursor(0,0);
     lcd.print("dont touch");
     delay(3000);
     lcd.begin(16, 2); 
    lcd.setCursor(0,0);
     lcd.print("KEVino 2017");
     break;
     }
    /* case btnNONE:
     {
     lcd.print("       ");
     break;
     }
     */
 }
}
 
 


 

Credits

KevinMcArthur
3 projects • 11 followers
Contact

Comments

Please log in or sign up to comment.