Hi All,
I'm really new to Arduino and don't have to much coding experience. I've decided to give a try and build a Twitter controlled pumpkin using Temboo and Arduino Yun.
The code seems to be working except for one thing. The yellow LED that I wanted to use as a main light source for the pumpkin (in candle mode) is not working as planned. Would you be able to have a look on my code and help me figure this out please?
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information, as described below
#define CANDLELED 11
#define REDLED 2
#define BUZZER 7
#define BUZZER_FREQUENCY 38
#define FLICKER_INTERVAL 25
long previousMillis = 0;
String last_id;
unsigned char candeled_state;
int numRuns = 1; // Execution count, so this doesn't run forever
int maxRuns = 250; // Maximum number of times the Choreo should be executed
void setup() {
pinMode(CANDLELED, OUTPUT);
pinMode(REDLED, OUTPUT);
pinMode(BUZZER, OUTPUT);
Bridge.begin();
// Console.begin();
// while(!Console);
delay(1000);
}
void loop() {
{
if(candeled_state == 0) {
digitalWrite(CANDLELED, LOW);
digitalWrite(REDLED, HIGH);
tone(BUZZER, BUZZER_FREQUENCY);
delay(5000);
noTone(BUZZER);
digitalWrite(REDLED, LOW);
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > FLICKER_INTERVAL)
{
for(int i = 0; i < 100; i++)
previousMillis = currentMillis;
analogWrite(CANDLELED, random(0, 256));
}
}
else {
noTone(BUZZER);
digitalWrite(REDLED, LOW);
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > FLICKER_INTERVAL)
{
previousMillis = currentMillis;
analogWrite(CANDLELED, random(0, 256));
}
}
}
{
if (numRuns <= maxRuns) {
// Console.println("Running Tweets - Run #" + String(numRuns++));
TembooChoreo TweetsChoreo;
// Invoke the Temboo client
TweetsChoreo.begin();
// Set Temboo account credentials
TweetsChoreo.setAccountName(TEMBOO_ACCOUNT);
TweetsChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
TweetsChoreo.setAppKey(TEMBOO_APP_KEY);
// Set profile to use for execution
TweetsChoreo.setProfile("search");
// Identify the Choreo to run
TweetsChoreo.setChoreo("/Library/Twitter/Search/Tweets");
TweetsChoreo.addOutputFilter("id", "/[1]/id_str", "Response");
// tell the Process to run and wait for the results. The
// return code will tell us whether the Temboo client
// was able to send our request to the Temboo servers
unsigned int returnCode = TweetsChoreo.run();
// a response code of 0 means success; print the API response
if(returnCode == 0) {
// String author; // a String to hold the tweet author's name
// String tweet; // a String to hold the text of the tweet
String id;
// choreo outputs are returned as key/value pairs, delimited with
// newlines and record/field terminator characters, for example:
// Name1\n\x1F
// Value1\n\x1E
// Name2\n\x1F
// Value2\n\x1E
// see the examples at http://www.temboo.com/arduino for more details
// we can read this format into separate variables, as follows:
while(TweetsChoreo.available()) {
String name = TweetsChoreo.readStringUntil('\x1F');
name.trim();
// read the value of the output item
String data = TweetsChoreo.readStringUntil('\x1E');
data.trim();
// assign the value to the appropriate String
if (name == "id") {
id = data;
}
}
{
if((last_id != id) ) {
candeled_state = 0;
delay(5000);
candeled_state = 1;
}
else {
candeled_state = 1;
}
TweetsChoreo.close();
}
Console.println("Waiting...");
delay(60000); // wait 60 seconds between Tweets calls
}
}
}
}
I've built this using the code from here:
https://raw.githubusercontent.com/mrichardson23/PimpYourPumpkin/master/PimpYourPumpkin.pde
and here:
Thanks so much for all your help.
Martin