Back to Parent

Servo myservo;// create servo object using the built-in Particle Servo Library

int servoPin = D0;  //declare variable for servo
int speakerPin = D3;

int command_int;     //variable to keep track number of times the senser detects magnet
extern int original = 110;
int redPin = A4;    // RED pin of the LED to PWM pin **A4**
int greenPin = D1;  // GREEN pin of the LED to PWM pin **D1**
int bluePin = D2;   // BLUE pin of the LED to PWM pin **D2**
int redValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int greenValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int blueValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255</td>

int buzzertone[] = {2273, 2000};

void setup()
 {
   //Sensor setup
   Serial.begin(9600);
   Particle.function("youtube", youtube);
   Particle.function("youtube2", youtube2);
   Particle.function("like", like);
   Particle.function("dis", dis);
   Particle.function("neu", neu);
   //LED setup
   // Set up our pins for output
   pinMode( redPin, OUTPUT);
   pinMode( greenPin, OUTPUT);
   pinMode( bluePin, OUTPUT);
   pinMode( speakerPin, OUTPUT );

   // turn them all off...
   analogWrite(redPin, redValue);
   analogWrite(greenPin, greenValue);
   analogWrite(bluePin, blueValue);

   //Servo setup
   analogWrite(greenPin, 50);
   delay(500);
   analogWrite(greenPin, 255);
   delay(500);
   myservo.attach(D0);      //Initialize the servo attached to pin D0
   myservo.write(0);        //set servo to initial position
   delay(5000);              //delay to give the servo time to move to its position
   analogWrite(redPin, 50);
   delay(500);
   analogWrite(redPin, 255);
   delay(500);
   //myservo.detach();        //detach the servo to prevent it from jittering
   myservo.write(100);        //set servo to initial position
   delay(2500);


 }

 void loop()
 {
   
 }

 // this function automagically gets called upon a matching POST request
 //ratio baseline has been LIFTED
 int youtube(String command){//turns in a ratio of num_like/num_dislike
   /*Serial.println(command);
   command_int = atoi(command);
   Serial.println(command_int); //ratio number
   return 10;*/
   uint16_t i;
   analogWrite(redPin, 50);
   delay(500);
   analogWrite(redPin, 255);
   delay(500);

   for (i=0; i< 5;i++){
     if((10*i+original)<=160){
       myservo.attach(servoPin);
       myservo.write((10*i+original));
       delay(500);
       myservo.detach();
     }
     else{
       myservo.attach(servoPin);
       myservo.write(158);
       delay(500);
       myservo.detach();
     }


   }
   if (i == 5){
     if(original<=110){
       myservo.attach(servoPin);
       myservo.write((10*i+original));
       delay(500);
       Serial.println("baseline-raised");
       Serial.println(original);
       original = original+10*i;
       Serial.println(original);
       myservo.detach();
     }
     else{
       myservo.attach(servoPin);
       myservo.write(158);
       delay(500);
       myservo.detach();
       original = 160;
       Serial.println(original);
     }


   }
 }

//ratio baseline has been DROPPED
 int youtube2(String command){

   uint16_t j;
   analogWrite(bluePin, 50);
   delay(500);
   analogWrite(bluePin, 255);
   delay(500);
   for (j=0; j< 5;j++){
     myservo.attach(servoPin);
     myservo.write((-j*10+original));
     delay(500);
     myservo.detach();

   }
   if (j == 5){
     if(original>=50){
       myservo.attach(servoPin);
       myservo.write((-j*10+original));
       delay(500);
       Serial.println("baseline-dropped");
       Serial.println(original);
       original = original-10*j;
       Serial.println(original);
       myservo.detach();
     }
     else{
       myservo.attach(servoPin);
       myservo.write(0);
       delay(500);
       myservo.detach();
       original = 0;
       Serial.println(original);
     }
   }
 }

 int like(String command){
    Serial.println("like");
    analogWrite(redPin, 200);
    delay(500);
    analogWrite(redPin, 255);
    delay(200);

 }

 int dis(String command){
    Serial.println("dislike");
    analogWrite(bluePin, 200);
    analogWrite(greenPin, 250);
    delay(500);
    analogWrite(bluePin, 255);
    analogWrite(greenPin, 255);
    delay(200);
 }

 int neu(String command){
    analogWrite(bluePin, 200);
    analogWrite(greenPin, 200);
    analogWrite(redPin, 200);
    delay(500);
    analogWrite(bluePin, 255);
    analogWrite(greenPin, 255);
    analogWrite(redPin, 255);
    delay(200);
    Serial.println("neutral");
 }
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0