Servo myservo; int servoPin = A5; // variable to store servo pin int speakerPin = D0; // variable to store speaker pin // create an array for the notes in the melody: // C4,G3,G3,A3,G3,0,B3,C4 int melody[] = {1908,2551,2551,2273,2551,0,2024,1908}; // create an array for the duration of notes // note durations: 4 = quarter note, 8 = eighth note, etc.: int noteDurations[] = {4,8,8,4,4,4,4,4}; // setup function void setup() { myservo.attach(servoPin); // attach servo pin Particle.function("feed",triggerFeed); // declare feed funtion pinMode(speakerPin, OUTPUT); // attach speaker pin } void loop() { //do nothing in loop } // feed function // since feed can be invoked by 3 different methods (button, voice, schedule) // we need to account for 3 different commands int triggerFeed(String command) { // bfeed is fed by the button // sfeed is fed by schedule // vfeed is fed by voice command if (command=="bfeed" || command=="sfeed" || command=="vfeed") { for (int i=1; i<=3; i++){ playNotes(); } myservo.write(0); //start turning the servo delay(330); //how long the turn turns in ms (may need some adjusting) myservo.write(92); //stop turning servo setTime(); if (command=="bfeed"){ Particle.publish("Bella fed by button",Time.timeStr(),PRIVATE); }else if (command=="sfeed"){ Particle.publish("Bella fed by schedule",Time.timeStr(),PRIVATE); }else if (command=="vfeed"){ Particle.publish("Bella fed by voice command",Time.timeStr(),PRIVATE); } return 1; } } // play melody function void playNotes() { // iterate over the notes of the melody: for (int thisNote = 0; thisNote < 8; thisNote++) { // to calculate the note duration, take one second // divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1000/noteDurations[thisNote]; tone(speakerPin, melody[thisNote],noteDuration); // the note's duration + 30% int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); // stop the tone playing noTone(speakerPin); } } // time function sets the event time to CST which is UTC-5 during daylight savings, or else UTC-6 void setTime() { int dst=Time.isDST(); // check if daylight savings time is in effect if (dst=1){ Time.zone(-5); //set timezone to CDT }else Time.zone(-6); //set timezone CST }