ahmed soliman
Published

Change LEDs Between Green and Red

When you press on a key green led turn on and when you press to another key red led turn on.

BeginnerWork in progress15 hours3,087
Change LEDs Between Green and Red

Things used in this project

Story

Read more

Schematics

connection of LEDs on board

Connect LEDs to pins as shown

Code

light LED with oneshield

Arduino
upload on one shield
/*

Keypad Shield Example

This example shows an application on 1Sheeld's keypad shield.

By using this example,  when you prees on a key green led turn on and 
when you press to another key red led turn on
when you prees on a key white led turn on and 
when you press to another key yellow led turn on

OPTIONAL:
To reduce the library compiled size and limit its memory usage, you
can specify which shields you want to include in your sketch by
defining CUSTOM_SETTINGS and the shields respective INCLUDE_ define. 

*/

#define CUSTOM_SETTINGS
#define INCLUDE_KEYPAD_SHIELD

/* Include 1Sheeld library. */
#include <OneSheeld.h>
int A, B, C, D; //vaiables with names of buttons in keypad
/* A name for the LED on pin 8. */
int yellow = 8;
/* A name for the LED on pin 9. */
int green = 9;
/* A name for the LED on pin 10. */
int white = 10;
/* A name for the LED on pin 11. */
int red = 11;

void setup() 
{
  /* Start communication. */
  OneSheeld.begin();
  /* Set LEDs A, B, C and D as output. */
  pinMode(yellow,OUTPUT);
  pinMode(red,OUTPUT);
  pinMode(green,OUTPUT);
  pinMode(white,OUTPUT);
}

void loop()
{
  /* If keypad's button A is pressed. */
  if(Keypad.isRowPressed(0) && Keypad.isColumnPressed(3))
  {
    A = 1; // press A 
    B = 0;
    C = 0;
    D = 0;
  }
  
  else if(Keypad.isRowPressed(1) && Keypad.isColumnPressed(3))
  {
    A = 0;
    B = 1;// press B
    C = 0;
    D = 0;
  }
  
   else if(Keypad.isRowPressed(2) && Keypad.isColumnPressed(3))
  {
    A = 0;
    B = 0;
    C = 1;  // press c
    D = 0;
  }

   else if(Keypad.isRowPressed(3) && Keypad.isColumnPressed(3))
  {
    A = 0;
    B = 0;
    C = 0;
    D = 1; // press D
  }
  else
  {
    /* Turn off all of LEDs. */
    digitalWrite(yellow,LOW);
    digitalWrite(green,LOW);
    digitalWrite(white,LOW);
    digitalWrite(red,LOW);
  }
  if(A) //press button A
    digitalWrite(yellow, HIGH);
  if(B) //press button B
    digitalWrite(green, HIGH);
  if(C) //press button C
    digitalWrite(white, HIGH);
  if(D) //press button D
    digitalWrite(red, HIGH);
}

Credits

ahmed soliman

ahmed soliman

2 projects • 19 followers
Computer system Engineer

Comments