Created
January 18, 2017 23:53
-
-
Save jchuahtacc/12149555b06290dffeed1d8b04b0255f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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