Академический Документы
Профессиональный Документы
Культура Документы
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
//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
//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)
}
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>
setup(){
// configure pin 1 - pin 3 as OUTPUT pins
pinlMode = OUTPUT; pin2Mode = OUTPUT;
pin3Mode = OUTPUT;
setup()
{
digitalWrite(YELLOW , ON); // turn on YELLOW LED delayMs(500); // wait for half a
}
}
// 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.
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(){
}
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
// 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.
//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++) {
{
//execute this section of code if the value in the i variable is less than 10
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
//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);
char KeypadCharacters[NumberOfRows]
[NumberOfColumns] = {
//Layout of the Keypad's Keys
setup(){
//setup here
Lcd_setting(1,2,3,4,5,6);
Lcd_cmd(cursorOff);
Lcd_cmd(clear);
loop(){
//Program here
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
//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
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)
}
}
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.
//setup here
pinMode(soundSensor, INPUT); // configure Sound sensor as INPUT
pinMode(RELAY, OUTPUT); // configure Relay as OUTPUT loop(){
//Program here
if(readPin(soundSensor))
}
}
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
loop(){
//Program here if (readPin(DO))
//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>
setup(){
//setup here
}
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.
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
// 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(){
}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
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.
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
#include<CloudX/M633.h>
#include<CloudX/Keypad.h>
#include<CloudX/Lcd.h>
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 ");
variabLe
if(Keys=='*')
Lcd_writeText(1,1, " ENTER PIN "); // display " ENTER PIN " on LCD
}
// 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 ");
//do this if times is less than 4 and any keypad key other than '#' or is pressed {
Code[times] = Keys; // store the present Key Pressed in the Code char array
times++; // increment times variable by one
}
}
while(times<=4) {
Keys=Keypad_getKey();
if(Keys=='*'){
Lcd_cmd(clear)
; times=0;
Lcd_writeText(1,1, " ENTER PIN ");
}
if (check == 4)
for (i=0; i<4; i++) Attempt[i]=0; // remove item in the Attempt array
check = 0; times = 0;
}
}
}
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>
txt[3] = "30
CountDownTimer(){// Create a Function to countdown 30 seconds on display.
for(int i=30; i>=0; i--){
sec
}
YellowPrompt(){
for(int i=30; i>=0; i--){ intTostr(txt,i,DEC);
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);
//Program here
(){
//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
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;
}