Skip to content

Instantly share code, notes, and snippets.

@tedbauer
Last active July 19, 2017 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tedbauer/9da8a0a7a6c1a1fb7a861b7120145a01 to your computer and use it in GitHub Desktop.
Save tedbauer/9da8a0a7a6c1a1fb7a861b7120145a01 to your computer and use it in GitHub Desktop.
int sPin = A5; // Pin for the servo signal input
int buttonPin = D0; // Pin for the button input
Servo serv; // Instance of Servo object; takes care of low-level servo communication
void setup() {
serv.attach(sPin); // Tells the Servo object which pin the servo is connected to
// Allows us to use the button pin for input.
// Read about "pull up" resistors here: http://playground.arduino.cc/CommonTopics/PullUpDownResistor
pinMode(buttonPin, INPUT_PULLUP);
// Subscribe to other Photon's events: call wave function whenever other Photon
// publishes an event.
Particle.subscribe("wave_0000000002", wave);
}
// this function loops as long as the Photon is on.
void loop() {
// store current reading of button pin
int bState = digitalRead(buttonPin);
// If it's "LOW", we publish a wave event, so the other Photon will "wave".
// Note that we are interested in when it is LOW, and not HIGH, because
// of the notion of the "pull up" resistor.
if (bState == LOW) {
// Publish event for other photon.
Particle.publish("wave_0000000001", "on");
delay(3700); // Let the other Photon finish its sweep before we publish another wave.
// This is not particularly elegant. If the internet connection is weak, this could
// cause a new wave to be triggered in the middle of an old one, causing erratic
// waving behaviour.
}
}
// Perform a full sweep of the "wave".
// Variable j determines how many sweeps to perform in one wave.
// Modify the values inside the parantheses following the two "delay"s to adjust the wave speed.
// Modify the value i to adjust which angle to perform the sweep to.
void wave(const char *event, const char *data) {
for (int j = 0; j < 2; j++) {
for (int i = 0; i < 180; i++) {
serv.write(i);
delay(5);
}
for (int i = 180; i > 0; i-=1) {
serv.write(i);
delay(5);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment