Вы находитесь на странице: 1из 48

Led Blink

For our first project, we will blink an LED. That is, turn the Light Emitting Diode(LED) on and off
successively for a period of time.

#include <CloudX\M633.h> // Load in the text in this header file to your code

#define LED 1 // anytime the compiler sees the text LED replace it with 1

setup(){

//setup here

pinMode(LED , OUTPUT); // setup digital I/O pin 1 (LED) as an OUTPUT


loop(){

//Program here
digitalWrite(LED , ON); // turn on LED
delayMs(1000);
digitalWrite(LED // keep LED on for (1000 milliseconds)one second
}delayMs(1000); , OFF); // turn off LED // keep LED off for one
} second

pin Led ON and OFF control with a


Pushbutton
This project turns on and off an LED with respect to the current LED state, when you press the button.
A pushbutton is a component that connects two points in a circuit when you press it.
In the First Project, we used one of the digital I/O(Input/Output) pins of the CloudX as an output to blink
our LEDs. We use these same pins to accept Input from users. We use the pinMode function to
configure our pins as INPUT, such as detecting whether a push button has been pressed by a user
or taking reading from a sensor.
Note: pinxMode = OUTPUT and pinxMode = INPUT can also be used to configure any CloudX digital I/O
pin as an OUTPUT or INPUT pin respectively just like the pinMode function.
#include <CloudX\M633.h> #define LED pinl // anytime the compiler sees the text LED replace
it with pinl

#define BUTTON 2 // digital pin 2 to BUTTON


setup(){

//setup here
pinlMode = OUTPUT; // configure digital I/O pin 1 (LED) as an OUTPUT pin
pinMode(BUTTON, INPUT); // setup digital I/O pin 2(BUTTON) as an INPUT pin
LED = OFF ; // cLear/turn off digital pin 1

//Program here
if(readPin(BUTTON) is LOW and LED is OFF)

//execute this section of code if button is pressed and pinl is OFF


{

delayMs(250); // switch debounce delay LED


= ON; // turn on digital pin
1
}
if(readPin(BUTTON) is LOW and LED is ON )

//execute this section of code if button is pressed and pin1 is ON {

delayMs(250); // switch debounce delay

LED = OFF; // turn off digital pin 1


}

}
Traffic Light
}

In this project, we create a simple Traffic light. when the RED light is on, the GREEN light will be off and
vice versa, while the YELLOW will come on when the RED and GREEN Lights are about to change
status.

#include <CloudX/M633.h>

#define RED 1 // digital pin 1 to the Red LED

#define YELLOW 2 // digital pin 2 to the YeLLow LED


#define GREEN 3 // digital pin 3 to the Green LED

char i; // create a storage place for placing values or single characters

setup(){
// configure pin 1 - pin 3 as OUTPUT pins
pinlMode = OUTPUT; pin2Mode = OUTPUT;
pin3Mode = OUTPUT;

digitalWrite(RED , OFF); // turn off RED LED


digitalWrite(YELLOW , OFF); // turn off YELLOW LED
digitalWrite(GREEN , OFF); // turn off GREEN LED
loop()
{
//Program here
digitalWrite(RED , ON); // turn on RED LED
delayMs(1500); // wait for 1 and a half seconds
digitalWrite(RED , OFF); // turn off RED LED
digitalWrite(YELLOW , ON); // turn on YELLOW LED
delayMs(500); // wait for half a second
digitalWrite(YELLOW , OFF); // turn off YELLOW LED

digitalWrite(GREEN , ON); // turn on GREEN LED


delayMs(1500); // wait for 1 and a half seconds
digitalWrite(GREEN , OFF); // turn off GREEN LED

setup()
{
digitalWrite(YELLOW , ON); // turn on YELLOW LED delayMs(500); // wait for half a

}
}

second digitalWrite(YELLOW , OFF); // turn off YELLOW LED 7-Segment


0-9 Counter
In this project we use a seven-segment LED display to count from 0 to 9.
A seven-segment LED display consists of eight LEDs and it is perfect for displaying numbers.
To reduce the number of pins used by the display, all of the anodes or cathodes of the LEDs are
connected together and are called common-anode or common-cathode, respectively. For our
project we use the common-cathode type. The 8 LEDs are labeled A to G and DP (for the decimal
point). For our common cathode module, there is an anode pin for each LED segment. For
example, if you want to display the number 4, then you would apply current to segments B, C, F
and G. The CloudX Segment Library makes using the 7-segment module easier.

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


char NumberOfDigit = 1; // set number of 7 segment displays to be used

// connect these CloudX pins to the Data Pins A,B,C,D,E,F,G and H pins of the Display
char segmentDataPins[]= {1, 2, 3, 4, 5, 6, 7, 8};

// connect these CloudX pins to the Common Anode or Cathode of each 7-segment display
char segmentScanPins[]= 0; // to save pins we connect directly to ground(cathode)
//setup here// initialize the 7 segment Display with these data
Segment_setting(CCathode,NumberOfDigit,segmentScanPins,segmentDataPins);
loop(){
//Program here 1000); write 7-segment display
Segment_write(0
1 1000); write 7-segment display
Segment_write(2 1000); write 7-segment display
Segment_write(3 1000); write 7-segment display
Segment_write(4 1000); write 7-segment display
Segment_write(5 1000); write 7-segment display
Segment_write(6 1000); write 7-segment display
Segment_write(7 1000); write 7-segment display
Segment_write(8 1000); write 7-segment display
Segment_write(9 1000); write 7-segment display

}
For this project, we use two buttons to increase and decrease the number shown on a seven-
segment LED display.

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

7-Segment 0-9 Counter with


}

Button
#define DECREASE 9 // digital pin 9 to DECREASE Button
#define INCREASE 10 // digital pin 10 to INCREASE Button

char i=0;
char NumberOfDigit = 1;
char segmentDataPins[]= {1, 2, 3, 4, 5, 6, 7, 8}; char segmentScanPins[]=
0;

setup(){

//setup here
pinMode(DECREASE, INPUT); pinMode(INCREASE, INPUT);
Segment_setting(CCathode,NumberOfDigit,segmentScanPins,segmentDataPins);
loop(){

//Program here if(readPin(DECREASE)


== 0)

//execute this section of code if DECREASE button is pressed {

delayMs(250); // removes the possibility of switch bounce i--;


//reduce the value assigned to the i variable by one
}
if(readPin(INCREASE) == 0)

//execute this section of code if DECREASE button is pressed {


delayMs(250); // removes the possibility of switch bounce i++;
//increase the value assigned to the i variable by one }

// Defensive driving: make sure i stays in the range 0-9


if(i==255) i=9; //if the value inside the i variable is 255, change it to 9
if(i==10) i=0; //if the value inside the i variable is 10, change it to 0

Segment_write(i , 1000); // write current value in i the variable on 7-segment

}
This Project shows how to write data on a Liquid Crystal Display (LCD) using the CloudX LCD

}
LCD Hello World
#include<CloudX/M633.h>

#include<CloudX/Lcd.h> // Load the text from this header file into your code setup(){

//setup here

Lcd_setting(1,2J3J4J5J6); // setup the LCD with these CLoudX pins.


Lcd_cmd(clear); // Clear LCD display
Lcd_cmd(cursorOff); // LCD Cursor off
loop(){
//Program here

// Display "Hello World!" on the 1st row and from the 2nd column of the LCD
Lcd_writeText(1,2, "Hello World!");
}
Count with Multiple 7 Segment
Display Counter
This Project explains how to display data on Two 7-Segment using the CloudX Segment library, with
example you will be able to use the Segment library to display data on as many 7-Segment
displays as you want.

#include <CloudX\M633.h> #include <CloudX\Segment.h> #include <CloudX/stdlib.h> char


counter[2] = {'0','0'}; setup()
{

//setup here
char NumberOfDigit = 2; // set number of 7 segment displays to be used

// connect these CloudX pins to the Data Pins A,B,C,D,E,F,G and H pins of the Display
char segmentDataPins[]= {1,2,3,4,5,6,7,8};

// connect these CloudX pins to the Common Anode or Cathode of each 7-segment display
char segmentScanPins[]= {9,10};
// initialize the 7 segment Display with these data
Segment_setting(CCathodeJNumberOfDigitJ segmentScanPins,segmentDataPins);

loop(){

//Program here
for (int i =0; i<100; i++) {

// calculate i / 10 and add 48 (to convert it to a character) then Load in counter[0]


counter[0] = (i/10) + 48 ;

counter[1] = (i%10) + 48 ; // load this calculation into counter[0]

Segment_writeText(counter , 1000); // Display the content in counter array


on 7segment }

for (int i =99; i>0; i--){

// convert the vaLue in the i variabLe (input) to a string(output) in base 10


intTostr(counter , i , DEC);

if( i < 10)

{
//execute this section of code if the value in the i variable is less than 10

counter[1]=counter[0]; // replace counter[1] with the content of the counter[0]


counter[0] ='0'; // replace counter[0] variable with the character '0'
}

Segment_writeText(counter , 1000); // Display the content in counter array for 1

sec
}
}
74hc595 Shift Register with LED
}

This example is based on using the 74HC595 shift register to control 8 LEDs. For projects where
you need more pins than what is obtainable on your CloudX board, with shift registers you can
address that issue easily.

#include
<CloudX/74HC595.h> char
data , mask ; char i;
setup(){

//setup here

HC595_setting(2, 1, 3); //Initialize the Shift


Register data = 0x80;
loop(){
//Program here for(i=0; i<8; i++) {
mask = data >>i; // shift value in data to the right by "i" and Load in mask

//Load content of mask into shift register from the LSB up to the MSB
HC595_shiftOut(mask, LSBFIRST);
HC595_latch(); //change shift output to match the data received(mask)
delayMs(500); //keep shift output for half a second

//Load content of mask into shift register from the MSB down to the LSB
HC595_shiftOut(mask, MSBFIRST);

HC595_latch(); //change shift output to match the new data received


delayMs(500);
}
}
}

Keypad With LCD


For this project, we will accept data from a Matrix Keypad and then display it on an LCD
Module.
#include <CloudX/M633.h>
#include <CloudX/Lcd.h>
#include <CloudX/Keypad.h>

#define NumberOfRows 4 // set the number of ROWS for Keypad


#define NumberOfColumns 4 // set the number of COLUMNS for Keypad

char KeypadCharacters[NumberOfRows]
[NumberOfColumns] = {
//Layout of the Keypad's Keys

char RowPins[NumberOfRows] = {7, 8, 9, 10}; // Keypad's Row Pins to CloudX


char ColumnsPins[NumberOfColumns] = {11, 12, 13, 14}; // Keypad's Column Pins

char Keys; //store Keypad output here

setup(){
//setup here

Lcd_setting(1,2,3,4,5,6);
Lcd_cmd(cursorOff);
Lcd_cmd(clear);

Keypad_setting (PULLDOWNCOL, RowPins, ColumnsPins, NumberOfRows, NumberOfColumns,


KeypadCharacters); // initialize Keypad with these data

loop(){

//Program here

while(Keys==0) //if no Key is Pressed keep checking for a Key Press


Keys=Keypad_getKey();//if a Key is Pressed load Key data into the Keys variable
Lcd_writeCP(Keys); // Display the Key Pressed on LCD's Current Cursor Position
Keys=0; //Clear the Content of the Keys variable
Keypad With 7 Segment
}

For this project, we will accept numeric input from a Matrix Keypad and then display it on a seven-
segment display Module. Since the 8 LEDs are labeled A to G and DP (for the decimal point), if
you want to display the number 6, then you would apply current to segments A, C,D,E F and G.

#include <CloudX/Keypad.h>
#define NumberOfRows 4 #define NumberOfColumns 3

Therefore 6 equals 0b01111101(DP,G,F,E,D,C,B,A) in binary and 0x7D in Hexadecimal


char KeypadCharacters[NumberOfRows][NumberOfColumns] = {
1
1 1 1
2 1
'4', '5' '7', '8' '*' 'Q'
,
}; //Layout of '6' the Keypad's Keys
char , RowPins[NumberOfRows] = {12,
13, 14, '9' 15}; char
, ColumnsPins[NumberOfColumns] =
{9, 10, '#' 11};
char Keys;

//Instead of creating ten separate char variables, we create an array to group them
unsigned char seg[] = {0x3F,0x06,0x5B,0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};

setup(){

//setup here
Keypad_setting (PULLDOWNROW, RowPins, ColumnsPins, NumberOfRows, NumberOfColumns,
KeypadCharacters); // initialize Keypad with these data
//Segment_setting(CCathode,NumberOfDigit, segmentScanPins,
segmentDataPins); portMode(1,OUTPUT); // setup digital I/O port 1 as OUTPUT
portWrite(1, OFF_ALL); // clear/turn off port 1

loop(){
//Program here

Keys = getKey(); // check for Key Press on Keypad


In this project, we use a button to switch OFF and ON a Light Bulb using a RELAY connected to
the Microcontroller.
#include <CloudX\M633.h>
#define BUTTON 1

define RELAY pin2 // digital pin 1 to Button


// digital pin 2 to the RELAY

if(Keys!=0) portWrite(1, seg[Keys - 48]); // write Key Pressed on 7-

segment Relay
setup(){

//setup here
pinMode(BUTTON , INPUT); // setup digital I/O pin 1 (BUTTON) as INPUT
pin2Mode = OUTPUT; // configure digital I/O pin 2 (RELAY) as an OUTPUT pin
RELAY = LOW; // turn off RELAY

loop(){
//Program here if(readPin(BUTTON) == LOW)

//execute this section of code if BUTTON is pressed {

delayMs(250); // switch debounce delay


RELAY = ~RELAY; // ToggLe/Change RELAY'S status

}
}
Clap Switch Control Using
Sound Sensor
In this project, we will check the output from a sound through an input pin and then switch OFF
and ON a Light Bulb using a RELAY connected to the Microcontroller.

#define soundSensor 1 // digital pin 1 to soundSensor

#define RELAY 2 // digital pin 2 to Relay


setup(){

//setup here
pinMode(soundSensor, INPUT); // configure Sound sensor as INPUT
pinMode(RELAY, OUTPUT); // configure Relay as OUTPUT loop(){
//Program here
if(readPin(soundSensor))

//execute this section of code if Clap is Heard by the Sound Sensor


{

delayMs(250); //clear feedback/echo/noise from surrounding.


if(readPin(RELAY)) { //if relay is on
digitalWrite(RELAY, LOW); // turn off relay
}
else { // if relay is off
digitalWrite(RELAY, HIGH); // turn on relay
}

}
}
In this project, we will check for Fire with a Flame Sensor and Display data on an LCD according
to the state of the sensor. We also, control the state of a buzzer, a RED LED and a GREEN LED
with respect to the sensor's Output.
#include <CloudX/M633.h> #include <CloudX/Lcd.h>

define DO 7 #define
Flame Sensor
// digital pin 7 to D0 pin on the Flame Sensor //
BUZZER 8 #define digital pin 8 to Buzzer // digital pin 9 to RED
RedLED 9 LED // digital pin 10 to GREEN LED
define GreenLED 10
setup() {

//setup here
Lcd_setting(1,2,3,4,5,6); // initialize LCD

pinMode(DO, INPUT); // setup D0 pin on the Flame Sensor as INPUT


pinMode(BUZZER, OUTPUT); // setup Buzzer as OUTPUT
pinMode(RedLED, OUTPUT); // setup RED LED as OUTPUT
pinMode(GreenLED, OUTPUT); // setup GREEN LED as OUTPUT
Lcd_cmd(cursorOff);
Lcd_cmd(clear);
Lcd_writeText(1,1," Flame Sensor "); // Display "Flame Sensor" on LCD

loop(){
//Program here if (readPin(DO))

//execute this section of code if the Flame sensor senses Fire {


digitalWrite(BUZZER, HIGH); // turn on Buzzer digitalWrite(RedLED, HIGH);
// turn on Red LED digitalWrite(GreenLED, LOW); // turn off Green LED

Lcd_writeText(2,1,"FIRE!!! CALL 911"); // Show "FIRE!!! CALL 911" on LCD }


else

//execute this section of code if the if statement above is NOT TRUE (NO FIRE)
{
digitalWrite(BUZZER, LOW); // turn off Buzzer
digitalWrite(RedLED, LOW); // turn off Red LED
digitalWrite(GreenLED, HIGH); // turn on Green LED Lcd_writeText(2,1," No
flame "); // Show "No flame" on LCD
}

}
Led Dot Matrix Display
}

In this project, we make use of an LED matrix display module to display a smiley face. The LED matrix
module consists of several rows and columns of LEDs.

#include <CloudX/M633.h>

char smiley[] = {0b00000000,


0b01100110,
0b01100110,
0b00000000,
0b00011000,
0b00000000,
0b11000011,
0b01111110 }; // array to represent the Layout of the Lit LEDs

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


i;

setup(){
//setup here

portMode(1,OUTPUT); // setup digital I/O port1 as OUTPUT


portMode(2,OUTPUT); // setup digital I/O port 2 (pin 9 - pin 16) as OUTPUT
portWrite(1,OFF_ALL); // clear/turn off port 1 portWrite(2,ON_ALL); //
clear/turn off port 2 (pin 9 - pin 16)
loop(){
//Program here
for(i=0; i<8; i++){
portWrite(2,~row[i]); // Load port 2 with the complement of the row array element
portWrite(1,smiley[i]); // Load port 2 with the value inside the smiLey array eLement
delayUs(20) // wait for (20 microseconds) i.e. 20x 10 6 seconds
;

}
Light Intensity Control
In this project, we make use of a Light Dependent Resistor(LDR) to detect the presence and intensity of
Light in a particular space and use the received data to control the light intensity of an LED.

#include <CloudX/M633.h> #include <CloudX/Adc.h> #include <CloudX/Pwm.h>

int LDRValue; // create a variable for placing a whole number or integer

setup(){
//setup here
// Analog_setting(); Configure and initialize the CloudX Analog Pins for Use //
Pwm1_init(5000); Configure the CloudX PWM module 1 // Start PWM Module 1
Pwm1_start(); Operation.
// Pwm1_duty(0); Set PWM duty cycle to 0.

loop(){

//Program here

LDRValue = Analog_read(A0); //read analog signal at A0 and store value in


LDRValue

LDRValue = ((float)LDRValue/1023) * 100; //convert LDRValue's value to percentage


Pwm1_duty(LDRValue); // Sets PWM duty cycle with the value inside LDRValue }
LM35 Temp Sensor
For this project, we take reading from the LM35 temperature sensor and display the data on an
LCD Module.

#include <CloudX/stdlib.h> #include <CloudX\Adc.h> #include <CloudX\Lcd.h>

float TemperatureReading; // storage for placing non-whoLe number or fraction


char *TemperatureDisplay; //create pointer variable

// custom character array


const byte character[] = {0x06, 0x09, 0x09, 0x06, 0x00, 0x00, 0x00, 0x00};

// custom char function that wouLd be caLLed in anywhere inside the code
void customCharacter(char row, char col, char addressCGRAM) { unsigned
char i;
Lcd_cmd(64 + (addressCGRAM * 8));
for (i = 0; i<=7; i++)
Lcd_writeCP(character[i]);
Lcd_cmd(returnHome);
Lcd_write(row, col, addressCGRAM);
}
setup(){

//setup here
Lcd_setting (1,2,3,4,5,6);
Analog_setting();
Lcd_cmd(clear);
Lcd_cmd(cursorOff);
Lcd_writeText(1,1,"TEMP. READING");//Show " TEMP. READING" on LCD

loop(){

TemperatureReading = Analog_read(A0); //read data from analog input pin 0

// convert raw sensor value to its Celsius scale value


TemperatureReading = TemperatureReading * 500 / 1023;

// convert float value in TemperatureReading to string


TemperatureDisplay = floatTostr(TemperatureReading);
TemperatureDisplay[5]=0; // control string to contain only five characters
Lcd_writeText(2,1,"Value: "); // Write to LCD

// Display content in TemperatureDisplay in the Current Cursor Position of the LCD


Lcd_writeTextCP(TemperatureDisplay); customCharacter(2, 13, 0); // show degree sign on
LCD // Display single character in the Current Cursor Position of the LCD
Lcd_writeCP('C');
}
For this project, we use a Passive Infrared (PIR) to sense motion and display the reading on an
LCD Module. Also, we use a buzzer sound to represent the presence of Motion.

}MOTION Sensor
#include <CloudX\M633.h>
#include <CloudX/Lcd.h>
#define PIR 7 #define
Buzzer 8 setup(){
//setup here pinMode(PIR, INPUT);
pinMode(Buzzer, OUTPUT);
Lcd_setting (1,2,3,4,5,6);
Lcd_cmd(clear);
Lcd_cmd(cursorOff);

Lcd_writeText(1,1,"MOTION DETECTOR");
loop(){

//Program here
if ( readPin (PIR) is HIGH)

//execute this section of code if the motion sensor senses ANY movement
{
digitalWrite(Buzzer, HIGH); // turn buzzer on
Lcd_writeText(2,1,"STATUS: PRESENT "); // display "STATUS: PRESENT " on

LCD

else // execute this section of code if the if statement is not True

// execute this section of code if the if motion sensor senses NO movement


digitalWrite(Buzzer, LOW); // turn buzzer off

Lcd_writeText(2,1,"STATUS: ABSENT ");// display "STATUS: ABSENT " on

LCD
}

}
Smoke or Gas Detector

In this project, we check for smoke or gas leakage with a smoke detector and control the
state of a buzzer, a RED LED and a GREEN LED with respect to the sensor's Output.
#include <CloudX\M633.h>

}
#define DO 1
#define Buzzer 2
#define RedLED 3
#define YellowLED 5
#define GreenLED 4

setup(){
//setup here pinMode(DO,
INPUT); pinMode(Buzzer,
OUTPUT); pinMode(RedLED,
OUTPUT); pinMode(YellowLED,
OUTPUT); pinMode(GreenLED,
OUTPUT); Analog_setting();

loop(){
//Program
here if (readPin(DO))

//execute this section of code if the Smoke sensor senses smoke or gas

{
digitalWrite(Buzzer, LOW); // turn buzzer off
digitalWrite(RedLED, LOW); // turn RedLED off
digitalWrite(GreenLED, HIGH); // turn GreenLED
on }
else

//execute this section of code if the Smoke sensor does not sense smoke or gas
{
digitalWrite(Buzzer, HIGH); // turn buzzer on
digitalWrite(RedLED, HIGH); // turn RedLED on
digitalWrite(GreenLED, LOW); // turn GreenLED off

}
Soil Moisture Sensor
}

In this project, we will check the output from a Soil Moisture Sensor and then use the data to switch
OFF or ON a RELAY connected to the Microcontroller.

#include <CloudX/Lcd.h>
#define DO 1 #define RELAY 2

setup(){
//setup here pinMode(DO,
INPUT); pinMode(RELAY,
OUTPUT);

loop(){

//Program here

// if the if the soil is dry put on the relay switch to the water irrigation system if
(readPin(DO)) digitalWrite(RELAY, HIGH);
// if the if the soil is wet put off the relay switch to the water irrigation system
else digitalWrite(RELAY, LOW);
}
}

CloudX Ohmmeter
For this project, we use the CloudX microcontroller to measure the resistance of a resistor with
unknown resistance value.

#include <CloudX/M633.h> #include <CloudX/Adc.h> #include <CloudX/Lcd.h> #include


<CloudX/stdlib.h> #define R1 10000 #define Vin 5

float VoltageReading; // keep decimal value inside VoltageReading variable


char *OhmDisplay;

setup(){
//setup here Analog_setting();
Lcd_setting(1,2,3,4,5,6);
Lcd_cmd(cursorOff);
Lcd_cmd(clear);

Lcd_writeText(1,1,"CloudX Ohmmeter");
loop(){
//Program here

// store value of voltage across the unknown resistor inside VoltageReading variable
VoltageReading = Analog read(A0);
delayMs(200); // wait for 200 milliseconds

// convert the digiLtaL value in VoLtageReading variable is to its analog value


VoltageReading = VoltageReading * Vin / 1023;
// caLcuLate the vaLue of unknown resistor and store inside VoLtageReading variabLe
VoltageReading = (VoltageReading * R1) / (Vin - VoltageReading);

// convert fLoat vaLue in VoLtageReading to string


OhmDisplay = floatTostr(VoltageReading);

OhmDisplay[6]=0; // Restrict to 6 character text Length Lcd_writeText(2,1,


"Res: "); // display text on LCD

Lcd_writeTextCP(OhmDisplay);// show string on LCD current cursor position


Lcd_writeTextCP(" Ohms");// display text on LCD current cursor position
delayMs(1000); // wait for 1 second
}
}Simple Smart Keypad Lock
System
In this project, we'll create a simple keypad-controlled lock system that checks for Input from the user
using a keypad and grants access or denies access to the user depending on the
information provided.

#include<CloudX/M633.h>
#include<CloudX/Keypad.h>
#include<CloudX/Lcd.h>

#define NumberOfRows 4 #define NumberOfColumns 4


char KeypadCharacters[NumberOfRows][NumberOfColumns] = {

char RowPins[NumberOfRows] = {7, 8, 9, 10};

char ColumnsPins[NumberOfColumns] = {11, 12, 13, 14};


char Keys , times=0 , check=0 , i;

char Code[4] = {0,0,0,0}; // char array to store PIN Code


char Attempt[4] = {0,0,0,0} ; // char array to store PIN Attempt

setup(){

//setup here
Keypad_setting (PULLDOWNCOL, RowPins, ColumnsPins, NumberOfRows,
NumberOfColumns, KeypadCharacters);
Lcd_setting (1,2,3,4,5,6) ;
Lcd_cmd(clear);
Lcd_cmd(cu rsorOff);
Lcd_writeText(1,1, " WELCOME "); delayMs(1500);
Lcd_writeText(1,1, " INPUT NEW PIN ");

while(times<=4) { // repeat this Loop till times variable is greater than 4

Keys=Keypad_getKey(); // check for Keypress and Key pressed store in keys

variabLe
if(Keys=='*')

// execute this line of code if key is pressed {


Lcd_cmd(clear); // clear LCD

times=0; // clear times variable

Lcd_writeText(1,1, " ENTER PIN "); // display " ENTER PIN " on LCD
}

if(Keys == '#' && times == 4 )

// execute this line of code if '#' key is pressed and value in times variable is 4 {
Lcd_cmd(clear); // clear LCD
Lcd_writeText(1,1, " NEW PIN STORED ");
Lcd_writeText(2,1, " SUCCESSFULLY ");

delayMs(2000); // show content currently on LCD for 2 seconds Lcd_cmd(clear);


// clear LCD
Lcd_writeText(1,1, " ENTER PIN ");

times++; // increment times variable by one


}

if (times<4 && ((Keys>='A'&& Keys<='D') || (Keys>='0'&&Keys<='9')))

//do this if times is less than 4 and any keypad key other than '#' or is pressed {

Lcd_write(2,times+1, Keys ); //show key on (2nd Row and times+1 column) of


LCD

Code[times] = Keys; // store the present Key Pressed in the Code char array
times++; // increment times variable by one
}
}

times=0; // fill times variable with zero


loop(){
//Program here

while(times<=4) {
Keys=Keypad_getKey();
if(Keys=='*'){
Lcd_cmd(clear)
; times=0;
Lcd_writeText(1,1, " ENTER PIN ");
}

if(Keys == '#' && times == 4 ){

for (i = 0; i < 4 ; i++ ) {// run this Loop four times if


(Attempt[i]==Code[i]) //compare characters in Code and Attempt array
check++; // do this if they match
}

if (check == 4)

//do this if the value in check variable is 4


{
Lcd_cmd(clear);
Lcd_writeText(1,1, " ACCESS GRANTED ");
delayMs(2000);
Lcd_writeText(1,1, " ENTER PIN ");
times = 0;
} else { //do this if the vaLue in check variabLe is NOT 4
Lcd_cmd(clear);
Lcd_writeText(1,1, " ACCESS DENIED ");
delayMs(1000);
Lcd_writeText(1,1, " ENTER PIN ");
}

for (i=0; i<4; i++) Attempt[i]=0; // remove item in the Attempt array
check = 0; times = 0;
}

if (times<4 && ((Keys>='A'&& Keys<='D') || (Keys>='0'&&Keys<='9')))


{ Lcd_write(2,times+1, Keys );
Attempt[times] = Keys; // store Key Pressed in the Attempt char array times++;

}
}
Traffic Light with 7seg
Countdown Timer
In this project, we create a Two-Way traffic light that operates based on a timer that displays on two
seven-segment displays.
Note: pinSelect( 1 , HIGH ) and pinSelect( 1 , LOW ) can also be used to set the state of any CloudX
digital I/O pin to ON/HIGH or OFF/LOW respectively just like the digitalWrite function.
#include <CloudX/M633.h>
#include <CloudX/Segment.h>
#include <CloudX/stdlib.h>

define Red1 11 #define


Yellowl 12 #define // digital pin 11 to theRed
// LED on the Left Yellow
Green1 13 #define digital pin 12 to the // LED on the Left Green
Red2 14 #define digital pin 13 to the // LED on the Left Red LED
Yellow2 15 #define digital pin 14 to the // on the Right Yellow LED
Green2 16 digital pin 15 to the // on the Right Green LED
digital pin 16 to the on the Right
char

txt[3] = "30
CountDownTimer(){// Create a Function to countdown 30 seconds on display.
for(int i=30; i>=0; i--){

intTostr(txt,i,DEC); // convert value in i to a string in base 10


if((i>= 0) && (i<=9)){ //do this if the value in i is Less than 10
txt[1] = txt[0]; // replace txt[1] with the content of the txt[0]
txt[0] = '0'; // replace txt[0] with zer0
}

Segment_writeText(txt, 1000); // Display the content in txt array for 1

sec
}

YellowPrompt(){
for(int i=30; i>=0; i--){ intTostr(txt,i,DEC);

if((i>= 0) && (i<=9)){ txt[1] = txt[0]; txt[0] = '0';


}

if(i<=5 && i>=0){

pinSelect(Yellow1, LOW); // turn off Yellow on left traffic light


pinSelect(Yellow2, LOW); // turn off Yellow on right traffic light
Segment_writeText(txt, 500);

pinSelect(Yellow1, HIGH); // turn on Yellow on left traffic light


pinSelect(Yellow2, HIGH); // turn on Yellow on right traffic light }
Segment_writeText(txt, 1000);
}

setup(){

//setup here
portMode(1,OUTPUT); // setup digital I/O port 1 as OUTPUT
portMode(2,OUTPUT); // setup digital I/O port 2 as OUTPUT
portWrite(1, OFF_ALL); // clear/turn off port 1 portWrite(2,
OFF_ALL); // clear/turn off port 2

int NumberOfDigit = 2;
char segmentDataPins[]= {1,2,3,4,5,6,7,8}; char segmentScanPins[]=
{9,10};

Segment_setting(CCathode,NumberOfDigit,segmentScanPins,segmentDataPins);

pinSelect(Red1,LOW); // turn off Red on left traffic light


pinSelect(Yellow1, LOW); // turn off Yellow on left traffic light
pinSelect(Green1, HIGH); // turn on Green on left traffic light
pinSelect(Red2, HIGH); // turn on Red on right traffic light

pinSelect(Yellow2, LOW); // turn off Yellow on right traffic light


pinSelect(Green2, LOW); // turn off Green on right traffic Light
loop(){

//Program here

CountDownTimer(); // run commands in the CountDownTimer() function

pinSelect(Yellow1, HIGH); // turn on YeLLow on Left traffic Light

pinSelect(Yellow2, HIGH); // turn on Yellow on right traffic light

YellowPrompt(); // run commands in the YeLLouPrompt() function


pinSelect(Red1,HIGH);
pinSelect(Green1, LOW);
pinSelect(Red2, LOW);
pinSelect(Green2, HIGH);
pinSelect(Yellow2, LOW);
pinSelect(Yellow1, LOW);
CountDownTimer();
pinSelect(Yellow1, HIGH);
pinSelect(Yellow2, HIGH);
YellowPrompt();
pinSelect(Red1,LOW);
pinSelect(Green1, HIGH);
pinSelect(Red2, HIGH);
pinSelect(Green2, LOW);
pinSelect(Yellow2, LOW);
pinSelect(Yellow1, LOW);
CountDownTimer();

Visitor In & Out Counter


is project, we create a system that counts the number of incoming and outgoing individuals in a Hall and also keeps track of the
total number of people in that place.

#include <CloudX\M633.h> #include <CloudX\Lcd.h>

ine VISTORIN pin7 // connect VISITOR IN Button(sensor) to pin 7

ine VISTOROUT pin8 // connect VISITOR OUT Button(sensor) to pin 8

ine greenLED pin9 // connect Green LED to pin 9

ine redLED pin10 // connect Red LED to pin 10


ine Capacity 2000 // set maximum number of persons the HaLL can contain

char in[4] ; char out[4] ; char


total[4];
signed int incount, outcount, totalcount; unsigned char i;
p(){
//setup here pin7Mode = INPUT;
pin8Mode = INPUT; pin9Mode = OUTPUT;
pin10Mode = OUTPUT; greenLED = LOW; redLED =
LOW;
Lcd_setting(1,2,3,4,5,6);
Lcd_cmd(clear);
Lcd_cmd(cursorOff);

Lcd_writeText(1,1,"Visitor IN & OUT");


Lcd_writeText(2,6,"Counter"); delayMs(2000);
Lcd_cmd(clear);

(){

//Program here
if(VISTOROUT is HIGH){ //do this if a person Leaves the haLL redLED = HIGH; //turn on
Red LED delayMs(200); outcount++;
if (incount<outcount) outcount--; //control difference between variables if(outcount > 9999)
outcount = 0;
out[0] = (outcount/1000)+ 48;//get 1st character of item in the out array out[1] = ((outcount
%1000)/100)+ 48; //get second character of value out[2] = ((outcount%100)/10)+ 48; //get third
character of value out[3] = ((outcount%100)%10)+ 48; //get fourth character of value

redLED = LOW; //turn off Red LED }

if(VISTORIN is HIGH){ //do this if a person enters the hall greenLED = HIGH;
delayMs(200); incount++;
if(incount > 9999) incount = 0; in[0] = (incount/1000)+ 48; in[1] = ((incount%1000)/100)+ 48; in[2]
= ((incount%100)/10)+ 48; in[3] = (incount%10)+ 48; greenLED = LOW;
}

totalcount = incount - outcount; //calculate number of persons in Hall if (totalcount <= 0)


totalcount=0; //control totalcount not to go below zero
total[0] = (totalcount/1000)+ 48; total[1] = ((totalcount%1000)/100)+ 48; total[2] = ((totalcount
%100)/10)+ 48; total[3] = (totalcount%10)+ 48;
Lcd_writeText(1,1,"IN:");
Lcd_writeText(1,4, in); //display content inside in array Lcd_writeText(1,9,"OUT:");
Lcd_writeText(1,13, out); //display content inside out arra
y

Lcd_writeText(2,1, "TOTAL: ");

Lcd_writeText(2,8, total); //display content inside toetaL array

Вам также может понравиться