David Washington
Published

Build a Super Bowl touchdown light with Spark and IFTTT

Light turns blue and green when there's a Seahawks touchdown and red and blue when there's a Patriots touchdown

Full instructions provided1,422
Build a Super Bowl touchdown light with Spark and IFTTT

Things used in this project

Story

Read more

Code

file_11104.txt

C/C++
void loop() {
    // turn all the leds red
    b.allLedsOn(255,0,0);
}

file_11105.txt

C/C++
void colorLeds(String color, uint8_t value) {
    if (color == "red") {
        b.allLedsOn(value,0,0);
    } else if (color == "blue") {
        b.allLedsOn(0,0,value);
    } else if (color == "green") {
         b.allLedsOn(0,value,0);
    } else if (color == "white") {
        b.allLedsOn(value,value,value);
    }
}

file_11106.txt

C/C++
void loop() {
    if (touchdownMode) {
        // Show green when there's a touchdown
        colorLeds("green", 255);
    } else {
        // Show dim white the rest of the time
        colorLeds("white", 100);
    }
}
void touchdown() {
    touchdownMode = true;
}

file_11107.txt

C/C++
void setup() {
    // The REST API that we expose to enter touchdown mode
    Spark.function("touchdown", touchdown);
}

file_11108.txt

C/C++
POST /v1/devices/{DEVICE_ID}/led
# EXAMPLE REQUEST IN TERMINAL
# Core ID is 0123456789abcdef
# Your access token is 123412341234
curl https://api.spark.io/v1/devices/0123456789abcdef/touchdown \
-d access_token=123412341234

file_11110.txt

C/C++
int led = D7;
int button = D6;
 
char msg[] = "@dwcares hello world"; 
#include <string.h> 
#define LIB_DOMAIN "arduino-tweet.appspot.com" 
#define TOKEN "TWITTER_DEV_TOKEN"
 
TCPClient client;
 
void setup() {
    pinMode(led, OUTPUT);
    pinMode(button, INPUT_PULLUP);
}
 
void loop() {
    if (digitalRead(button) == LOW) {
        sendTweet(msg);
    }
    else if(digitalRead(button) == HIGH) {
        digitalWrite(led, LOW);
    }
}
 
void sendTweet(char* message) {
    delay(1000); 
    digitalWrite(led, HIGH);
    client.connect(LIB_DOMAIN, 80); 
    client.println("POST /update HTTP/1.0"); 
    client.println("Host: " LIB_DOMAIN); 
    client.print("Content-Length: "); 
    client.println(strlen(message)+strlen(TOKEN)+14); 
    client.println(); 
    client.print("token="); 
    client.print(TOKEN); 
    client.print("&status="); 
    client.println(message); 
    client.flush();
    delay(100);
    client.stop();
}

Credits

David Washington

David Washington

1 project • 3 followers

Comments