Skip to content

Instantly share code, notes, and snippets.

@jchuahtacc
Created January 18, 2017 23:53
Show Gist options
  • Save jchuahtacc/12149555b06290dffeed1d8b04b0255f to your computer and use it in GitHub Desktop.
Save jchuahtacc/12149555b06290dffeed1d8b04b0255f to your computer and use it in GitHub Desktop.
// 3_publish.ino
//
// Example robotics code for CODE @ TACC
// Summer 2016 robotics curriculum, available at:
//
// https://github.com/CODE-at-TACC/summer-2016
//
// Copyright 2016, Texas Advanced Computing Center
// GNU GPLv3 License
/******************************************
Included libraries
******************************************/
#include "codetacc-robotics/codetacc-robotics.h"
/******************************************
Variables
******************************************/
UltrasonicSensor ultrasonic = UltrasonicSensor(2, 4);
double distance = 0;
/******************************************
Custom functions
******************************************/
/******************************************
void setup()
Runs once upon startup
******************************************/
void setup() {
Particle.variable("distance", distance);
Particle.publish("hello");
}
/******************************************
void loop()
Runs forever
******************************************/
void loop() {
distance = ultrasonic.readCm();
// Add "if" code here
if (distance > 0 && distance < 30) {
Particle.publish("alert");
}
//
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment