James Cadman
Published © CC BY-NC

LetterBot

Every Home Should Have One.

Work in progress23,058
LetterBot

Things used in this project

Hardware components

Spark Core
Particle Spark Core
×1
Texas Instruments CC3000
×1

Story

Read more

Code

file_4635.txt

C/C++
/*
LetterBot Project by James Cadman.  @Jay_uk
Conceived, created and built by me!

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.
*/

// Your secret DevID from PushingBox.com. You can use multiple DevID  on multiple Pin if you want
const char * DEVID1 = "[!!your DEVID here!!]";         // Scenario: "Doorbell pressed."
const char * DEVID2 = "[!!your DEVID Here!!]";       // Scenario: "Mail bas been delivered."
const char * serverName = "api.pushingbox.com";   // PushingBox API URL
const int ledA = A0;                          // The pin my LED's are attached to, must be a PWM pin.
const int ledB = A1;
const int soundPin = D5;
int i;
TCPClient client;                               // Starts the Spark Core's TCP Client.



void setup() {
    pinMode(ledA, OUTPUT);                    // Set the LED pin as an output.
    pinMode(ledB, OUTPUT);
    pinMode(soundPin, OUTPUT);
    attachInterrupt(D3, letterBox, RISING);     // This sets up the letterbox microswitch as an Interrupt.
    attachInterrupt(D2, doorBell, RISING);      // Same as above for the doorbell.
}

void loop() {

    digitalWrite(ledB, LOW);
            for(i = 0; i < 255; i++){
                analogWrite(ledA, i);
                delay(3);
            }
            for(i = 255; i > 0; i--){
                analogWrite(ledA, i);
                delay(3);
            }
  
    digitalWrite(ledA, LOW);
        for(i = 0; i < 255; i++){
            analogWrite(ledB, i);
            delay(3);
        }
        for(i = 255; i > 0; i--){
            analogWrite(ledB, i);
            delay(3);
        }
}

void letterBox(){
        RGB.control(true);              // Steals control of the Spark Core's RGB LED
        RGB.color(51, 51 ,255);         // sets the LED on to whaveter value you give it. (R, G, B)
        sendToPushingBox(DEVID2);       // Calls the PushingBox function with the DEVID2 variable.
        RGB.control(false);             // Gives control of the RGB LED back to the Spark Core.
}

void doorBell(){
        digitalWrite(soundPin, HIGH);
        RGB.control(true);              // Steals control of the Spark Core's RGB LED
        RGB.color(222, 0 ,255);         // sets the LED on to whaveter value you give it. (R, G, B)
        sendToPushingBox(DEVID1);       // Calls the PushingBox function with the DEVID1 variable.
        digitalWrite(soundPin, LOW);
        RGB.control(false);             // Gives control of the RGB LED back to the Spark Core.
}

void sendToPushingBox(const char * devid)
{

    client.stop();
    if (client.connect(serverName, 80)) {
        client.print("GET /pushingbox?devid=");
        client.print(devid);
        client.println(" HTTP/1.1");
        client.print("Host: ");
        client.println(serverName);
        client.println("User-Agent: Spark");
        //client.println("Connection: close");
        client.println();
        client.flush();
    }
}

Credits

James Cadman

James Cadman

2 projects • 23 followers
A Maker Dad.

Comments