int ledPin = D0;
long frameCount = 0;
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int Input = 0;
int pos = 0; // variable to store the servo position
int ErrectDuraction = 7000;
int ErrectPos = 170;
int RestingPos = 80;
void setup() {
Particle.subscribe("new_tweet", readTweet);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
Serial.println("begin");
pinMode(D1, OUTPUT);
myservo.attach(D1); // attaches the servo on pin 0 to the servo object
myservo.write(RestingPos);
delay(500);
myservo.detach(); // attaches the servo on pin 0 to the servo object
}
void loop() {
if (frameCount % 10000 == 0) {
Serial.print("checking in: ");
Serial.println(frameCount);
}
frameCount++;
}
void readTweet(const char *event, const char *data) {
Serial.println("read tweet");
const char* wordList[] = {"alternative facts", "atheism", "censorship",
"civil rights", "climate change", "drug legalization",
"energy crisis", "extremism", "foreign aid",
"gay rights", "hacking", "health insurance", "immigration", "labor unions",
"minimum wage", "nuclear energy", "offshore drilling", "privacy", "racial profiling", "social security",
"stem cells","women's rights","fat","Pig","Dog","Slob","Disgusting animal","ass","wife","women","nail","dating","skin","sex","flirt","make out","sexual","attractive"
"unattractive","husband","bimbo","fat","crooked","pussy","miss","Miss USA","black"
};
int spaceIndex = -1;
int startIndex = 0;
String tweetWord = "";
String tweetList[50];
int wordNum = 0;
String dataa = String(data);
Serial.println("started");
if (dataa.indexOf(" ", startIndex) == -1) {
Serial.println(dataa);
} else {
while(dataa.indexOf(" ", startIndex) != -1) {
spaceIndex = dataa.indexOf(" ", startIndex);
tweetWord = dataa.substring(startIndex, spaceIndex);
tweetList[wordNum] = tweetWord;
startIndex = spaceIndex + 1;
wordNum++;
}
}
int breakNum = 0;
Serial.println(wordNum);
for (int i = 0; i < wordNum; i++) {
for (int j = 0; j < sizeof(wordList); j++){
if (Contains(wordList[j], tweetList[i])) {
Serial.println("KEYWORD");
digitalWrite(ledPin, HIGH);
myservo.attach(D1); // attaches the servo on pin 0 to the servo object
//hardcode jitter
myservo.write(ErrectPos*1); // tell servo to go to position in variable 'pos'
delay(800);
myservo.write(ErrectPos*1.2); // tell servo to go to position in variable 'pos'
myservo.write(ErrectPos*1.3); // tell servo to go to position in variable 'pos'
delay(800);
myservo.write(ErrectPos*1.1); // tell servo to go to position in variable 'pos'
myservo.write(ErrectPos*1.4); // tell servo to go to position in variable 'pos'
delay(250);
myservo.write(ErrectPos*1.0); // tell servo to go to position in variable 'pos'
delay(250);
myservo.write(ErrectPos*1.5); // tell servo to go to position in variable 'pos'
delay(250);
myservo.write(ErrectPos*1.0); // tell servo to go to position in variable 'pos'
myservo.write(ErrectPos*1.2); // tell servo to go to position in variable 'pos'
myservo.write(ErrectPos*1.3); // tell servo to go to position in variable 'pos'
delay(800);
myservo.write(ErrectPos*1.1); // tell servo to go to position in variable 'pos'
myservo.write(ErrectPos*1.4); // tell servo to go to position in variable 'pos'
delay(250);
myservo.write(ErrectPos*1.0); // tell servo to go to position in variable 'pos'
delay(250);
myservo.write(ErrectPos*1.0); // tell servo to go to position in variable 'pos'
delay(250);
myservo.write(ErrectPos*1.5); // tell servo to go to position in variable 'pos'
delay(250);
myservo.write(ErrectPos*1.0); // tell servo to go to position in variable 'pos'
delay(250);
myservo.write(ErrectPos*1.5); // tell servo to go to position in variable 'pos'
delay(250);
myservo.write(ErrectPos*1.0); // tell servo to go to position in variable 'pos'
myservo.write(ErrectPos*1.2); // tell servo to go to position in variable 'pos'
myservo.write(ErrectPos*1.3); // tell servo to go to position in variable 'pos'
delay(800);
myservo.write(ErrectPos*1.1); // tell servo to go to position in variable 'pos'
myservo.write(ErrectPos*1.4); // tell servo to go to position in variable 'pos'
delay(250);
myservo.write(ErrectPos*1.0); // tell servo to go to position in variable 'pos'
myservo.write(ErrectPos*1.2); // tell servo to go to position in variable 'pos'
myservo.write(ErrectPos*1.3); // tell servo to go to position in variable 'pos'
delay(800);
myservo.write(ErrectPos*1.1); // tell servo to go to position in variable 'pos'
myservo.write(ErrectPos*1.4); // tell servo to go to position in variable 'pos'
delay(250);
//Hardcode animation end
myservo.write(RestingPos); // tell servo to go to position in variable 'pos'
delay(100);
myservo.detach(); // attaches the servo on pin 0 to the servo object
breakNum++;
break;
}
if (breakNum > 0) {
break;
}
}
if (breakNum > 0) {
break;
}
}
delay(1000);
digitalWrite(ledPin, LOW);
}
//http://stackoverflow.com/questions/5029612/how-to-match-text-in-string-in-arduino
//determines if one string is inside another
bool Contains(String s, String search) {
int max = s.length() - search.length();
for (int i = 0; i <= max; i++) {
if (s.substring(i) == search) return true; // or i
}
return false; //or -1
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .