Yeah, so here’s the code for my ping sensor project.
I’ve even got some sensor reading smoothing in there since this sensor is a bit temperamental. The functions you should check out are avgReading()
, readPingSensor()
, ping()
, microsecondsToInches()
and microsecondsToCentimeteres()
/**
******************************************************************************
* @file photon-desk.cpp
* @authors TJ Hunter
* @version V1.0.0
* @date 22-Oct-2015
* @brief Adjust the height of your geekdesk over WiFi using a Particle Photon
******************************************************************************
Copyright (c) 2015 TJ Hunter. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see <http://www.gnu.org/licenses/>.
******************************************************************************
This file has been truncated. show original
This code started out from @BDub ’s work from this thread: Simple Photon Ping Sensor (HC-SR04)
3 Likes