Question

create and design the ultimate smart home using various senors, in C+ + program

create and design the ultimate smart home using various senors, in C+ + program
0 0
Add a comment Improve this question Transcribed image text
Answer #1

smart home using various senors:

1)Window & door open and close:

// doors open or closed

#include <bits/stdc++.h>

using namespace std;

  

// Function to check whether 'n'

// has even number of factors or not

bool hasEvenNumberOfFactors(int n)

{

    int root_n = sqrt(n);

    // if 'n' is a perfect square

    // it has odd number of factors

    if ((root_n*root_n) == n)

        return false;

    // else 'n' has even

    // number of factors

    return true;

}

// Function to find and print

// status of each door

void printStatusOfDoors(int n)

{

    for (int i=1; i<=n; i++)

    {

        // If even number of factors

        // final status is closed

        if (hasEvenNumberOfFactors(i))

            cout << "closed" << " ";

        // else odd number of factors

        // final status is open

        else

            cout << "open" << " ";

    }

}

// Driver program

int main()

{

    nt n = 5;

    printStatusOfDoors(n);

    return 0;

}

2)WIRELESS DOORBELL:

#include <RH_ASK.h>

#include <SPI.h> // Not actually used but needed to compile

RH_ASK driver;

void setup()

{

Serial.begin(9600); // Debugging only

pinMode(5,INPUT);

if (!driver.init())

Serial.println("init failed");

}

void loop()

{

if(digitalRead(5)==HIGH){

const char *msg = "a";

driver.send((uint8_t *)msg, strlen(msg));

driver.waitPacketSent();

delay(200);

}

}

Doorbell Receiver Code

#include <RH_ASK.h>

#include <SPI.h> // Not actualy used but needed to compile

#include "pitches.h" //add Equivalent frequency for musical note

#include "themes.h" //add Note vale and duration

RH_ASK driver;

void setup()

{

Serial.begin(9600); // Debugging only

if (!driver.init())

Serial.println("init failed");

else

Serial.println("done");

}

void Play_Pirates()

{

for (int thisNote = 0; thisNote < (sizeof(Pirates_note)/sizeof(int)); thisNote++) {

int noteDuration = 1000 / Pirates_duration[thisNote];//convert duration to time delay

tone(8, Pirates_note[thisNote], noteDuration);

int pauseBetweenNotes = noteDuration * 1.05; //Here 1.05 is tempo, increase to play it slower

delay(pauseBetweenNotes);

noTone(8); //stop music on pin 8

}

}

void loop()

{

uint8_t buf[1];

uint8_t buflen = sizeof(buf);

if (driver.recv(buf, &buflen)) // Non-blocking

{

Serial.println("Selected -> 'He is a Pirate' ");  

Play_Pirates();

Serial.println("stop");

}

}

3)Turning LED on and off with C++:

#include <Arduino\SerialClass.h>
#include "Send.h"
#include "led.h"

namespace ledtest {
Serial* SP = new Serial("COM3");

[STAThread]
void main(array<String^>^ args) {

Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);

ledtest::led form;
Application::Run(%form);
}

void sendState(int state) {
if (state == 1)
SP->WriteData("1", 1);
if (state == 0)
SP->WriteData("0", 1);
}

void readState() {
char* iState;

while (SP->IsConnected()) {
SP->ReadData(iState, 255);
printf(iState);
}
}

The button click events are as follows:

private: System::Void btnHigh_Click(System::Object^ sender, System::EventArgs^ e) {
ledtest::sendState(1);
}
private: System::Void btnLow_Click(System::Object^ sender, System::EventArgs^ e) {
ledtest::sendState(0);
}

Add a comment
Know the answer?
Add Answer to:
create and design the ultimate smart home using various senors, in C+ + program
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT