Beginners Tutorials with sample codes - Part 3 CloudX

  • img
Project Details

1. Keypad with LCD

Brief Description

For this project, we’ll accept data from a Matrix Keypad, and then display them on an LCD Module. Keypad is a typical example of an input device to a microcontroller.

 

4x4 Membrane Keypad Pin-Out

 

 

Wiring

 

Code

#include <CloudX\Keypad.h>  
#include <CloudX\LCD.h>


#define NumberOfRows 4 //sets keypad to four rows

#define NumberOfColumns 4 //sets keypad to four columns

char KeypadCharacters[NumberOfRows][NumberOfColumns] = {
'1', '2', '3', 'A',
'4', '5', '6', 'B',
'7', '8', '9', 'C',
'*', '0', '#', 'D'
};

char RowPins[NumberOfRows] = {7, 8, 9, 10};
char ColumnsPins[NumberOfColumns] = {11, 12, 13, 14};

char Keys;


setup(){
//setup here

Keypad_setting(PULLDOWNCOL, RowPins, ColumnsPins, NumberOfRows, NumberOfColumns, KeypadCharacters, 15);
//key-press indicator pin
//set at pin15

LCD_setting(1, 2, 3, 4, 5, 6); //RS, EN, D4, D5, D6, D7
LCD_cmd(clear);
LCD_writeText(1, 2, "Keypad with LCD");
delayMs(1700);
LCD_cmd(clear);



loop(){
//Program here

Keys = Keypad_getKey();
if(Keys isNot 0)
{
LCD_cmd(clear);
LCD_writeText(1, 1, "Key:");
LCD_writeCP(Keys);
LCD_writeText(1, 6, " pressed!");
delayMs(1000);
}
else
LCD_writeText(1, 1, "No Key pressed!");
}
}

 

 

Simulation

 

2. Keypad with 7-Segment

Brief Description

For this project, we’ll accept numeric input from a Matrix Keypad, and then display it on a seven-segment display unit.

Here, the DP LED is not in use, and hence not connected.

Wiring

 

Code

#include <CloudX\Keypad.h>  
#include <CloudX\Segment.h>


//-------------------------------------------------
//This section defines the relevant parameters for
//the keypad configuration.
//-------------------------------------------------
#define NumberOfRows 4 //sets keypad to four rows

#define NumberOfColumns 3 //sets keypad to three columns

char KeypadCharacters[NumberOfRows][NumberOfColumns] = {
//key-layout of the Keypad
'1', '2', '3',
'4', '5', '6',
'7', '8', '9',
'*', '0', '#',
};

char ColumnsPins[NumberOfColumns] = {8, 9, 10};
char RowPins[NumberOfRows] = {11, 12, 13, 14};


//-------------------------------------------------
//This section defines the relevant parameters for
//the segment configuration.
//-------------------------------------------------
char NumberOfDigit = 1; //A digit on display

char segmentDataPins[] = {1, 2, 3, 4, 5, 6, 7, NULL};
//a,b,c,d,e,f,g,(No)dp

char segmentScanPins[] = {0}; //No scan pin



char Keys;


setup(){
//setup here

//----------------------------------------------------------
//The keypad configuration -proper, is eventually executed
//by this function-call, utilizing the above already defined
//parameters.
//----------------------------------------------------------
Keypad_setting(PULLDOWNROW, RowPins, ColumnsPins, NumberOfRows, NumberOfColumns, KeypadCharacters, 0);
//key-press indicator pin
//set at pin15

//----------------------------------------------------------
//The segment configuration -proper, is eventually executed
//by this function-call, utilizing the above already defined
//parameters.
//----------------------------------------------------------
Segment_setting(CCathode, NumberOfDigit, segmentScanPins, segmentDataPins);



loop(){
//Program here

Keys = Keypad_getKey();
Segment_write(Keys, 100); //displays the pressed key for
//a delay scale factor of 100

}
}
 

 

Simulation

 

 

3. Joystick

Brief Description

In this project, we’ll be using the popular Joystick control device to control an array of LEDs.

 

Navigating the device up/down, sideways or pressing its centre-switch activates the corresponding LED/LEDs under their respective control. 

 

Wiring

 

Code

#include <CloudX\ADC.h>  
#include <CloudX\Joystick.h>

#define LED_Up pin2
#define LED_Down pin5

#define LED_Left pin4
#define LED_Right pin3


setup(){

//setup here
Analog_setting();

pin2Mode = OUTPUT;
pin3Mode = OUTPUT;
pin4Mode = OUTPUT;
pin5Mode = OUTPUT;

//Initialize all the 4 LEDs to an OFF-state
LED_Up = OFF;
LED_Down = OFF;
LED_Left = OFF;
LED_Right = OFF;

loop(){
//Program here

if(Joystick_upDown(A1) is JOYSTICK_UP)
{
LED_Up = ON;
delay(1000); //leaves the LED ON to be noticeable
//to the human eye
}

else if(Joystick_upDown(A1) is JOYSTICK_DOWN)
{
LED_Down = ON;
delay(1000);
}

if(Joystick_leftRight(A0) is JOYSTICK_LEFT)
{
LED_Left = ON;
delay(1000);
}

else if(Joystick_leftRight(A0) is JOYSTICK_RIGHT)
{
LED_Right = ON;
delay(1000);
}

if(Joystick_centre(1) is LOW) //joystick centre SW is
//connected to pin1
{
//Turn ON all the 4 LEDs
LED_Up = ON;
LED_Down = ON;
LED_Left = ON;
LED_Right = ON;
delayMs(1000);
}

else
{
//Turn OFF all the 4 LEDs
LED_Up = OFF;
LED_Down = OFF;
LED_Left = OFF;
LED_Right = OFF;
}

//Clear all the 4 LEDs to an OFF-state before going over
//the loop again
LED_Up = OFF;
LED_Down = OFF;
LED_Left = OFF;
LED_Right = OFF;

}
}

 

Simulation

 

4. LED Dot-Matrix Display 

Brief Description

 

In this project, we’ll make use of an LED Dot-Matrix Display Module to display a smiley face. 

A unit module of LED matrix display we’ll be using consists of eight rows and eight columns of LEDs; hence, the name 8x8 LED Matrix display Unit.

To further learn more on the dot matrix display, refer to a resource material titled “Dot Matrix Display” that is embedded in the help button of the CloudX IDE.

Wiring

 

Code

//array representing the layout of the lit LEDs  
char smiley[] =
{
0b00000000,
0b01100110,
0b01100110,
0b00000000,
0b00011000,
0b00000000,
0b11000011,
0b01111110
};

//array to control which row is turned ON/OFF
char row[8] = {1, 2, 4, 8, 16, 32, 64, 128};

char i;

setup(){
//setup here

portMode(1, OUTPUT); //sets up digital I/O port1 as
//OUTPUT
portMode(2, OUTPUT); //sets up digital I/O port 2
//pin 9 – pin 16) as OUTPUT

portWrite(1, OFF_ALL); //clears/turns off port 1
portWrite(2, ON_ALL); //clears/turns off port 2
//(pin 9 – pin 16)

loop(){
//Program here

for(i = 0; i < 8; i++)
{
portWrite(2, ~row[i]); //loads port 2 with the
//complement of the row
//array element

portWrite(1, smiley[i]); //loads port 2 with the
//value inside the smiley
//array element
delayUs(20); //waits for (20 microseconds)
//i.e. 20× 10−6 seconds
}
}
}
 

 

Simulation

 

You can drop your comment below.

Share this with friends