#include int number_in; Servo servo10, servo11; // create servo object to control a servo // a maximum of eight servo objects can be created int pos = 0; // variable to store the servo position int neutral, positive, negative, sentiment; void moveEarsHarmoniously(int sent,int pos, int neg, int neu){ for(pos = 0; pos < 120; pos += 1) // goes from 0 degrees to 180 degrees { // in steps of 1 degree servo10.write(pos); // tell servo to go to position in variable 'pos' delay(30); // waits 15ms for the servo to reach the position } for(pos = 120; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees { servo10.write(pos); // tell servo to go to position in variable 'pos' delay(30); // waits 15ms for the servo to reach the position } delay(500); } void moveEarsViolently(int sent,int pos, int neg, int neu){ int ang; for(ang = 0; ang < neg*3; ang += 1) // goes from 0 degrees to 180 degrees { // in steps of 1 degree servo11.write(ang); // tell servo to go to position in variable 'pos' delay(5); // waits 15ms for the servo to reach the position } for(ang = neg*3; ang>=1; ang-=1) // goes from 180 degrees to 0 degrees { servo11.write(ang+neg); // tell servo to go to position in variable 'pos' delay(5); // waits 15ms for the servo to reach the position } for(ang = 0; ang < neg*3; ang += 1) // goes from 0 degrees to 180 degrees { // in steps of 1 degree servo11.write(ang); // tell servo to go to position in variable 'pos' delay(5); // waits 15ms for the servo to reach the position } for(ang = neg*3; ang>=1; ang-=1) // goes from 180 degrees to 0 degrees { servo11.write(ang+neg); // tell servo to go to position in variable 'pos' delay(5); // waits 15ms for the servo to reach the position } } void setup() { // pinMode(ledPin, OUTPUT); Serial.begin(9600); servo10.attach(10); // attaches the servo on pin 10 to the servo object - harmonious servo11.attach(11); // attaches the servo on pin 10 to the servo object - violent servo10.write(90); // attaches the servo on pin 10 to the servo object - harmonious servo11.write(90); // attaches the servo on pin 10 to the servo object - violent } void loop() { //Serial.println(Serial.available()); if(Serial.available() > 0) { number_in = Serial.read(); Serial.println("is available"); Serial.println(number_in); if(number_in == 112){ //p // its the positive number of tweets positive = Serial.read(); Serial.println(positive, DEC); } if(number_in == 115){ //s // its the sentiment index of tweets sentiment = Serial.read(); Serial.println(sentiment, DEC); } if(number_in == 103){ // negative - g // its the negative number of tweets negative = Serial.read(); Serial.println(negative); } if(number_in == 110){ //neutral - n // its the neutral number of tweets neutral = Serial.read(); Serial.println(neutral); moveEarsViolently(sentiment,positive, negative, neutral); moveEarsHarmoniously(sentiment,positive, negative, neutral); moveEarsViolently(sentiment,positive, negative, neutral); moveEarsViolently(sentiment,positive, negative, neutral); moveEarsViolently(sentiment,positive, negative, neutral); } } else{ Serial.println("Still waiting for serial"); } delay(500); number_in = 0; }