Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Cayenne-MQTT-mbed Servo nfc X_NUCLEO_IDW01M1v2 NetworkSocketAPI 13
Revision 13:7b3b429e9731, committed 2019-09-07
- Comitter:
- kapitaninternet
- Date:
- Sat Sep 07 08:57:23 2019 +0000
- Parent:
- 12:32dbf8ff8d80
- Child:
- 14:c5aab7546de9
- Commit message:
- added humidity + servo control
Changed in this revision
--- a/Servo.h Thu Sep 05 20:00:08 2019 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,98 +0,0 @@
-/* mbed R/C Servo Library
- * Copyright (c) 2007-2010 sford, cstyles
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef MBED_SERVO_H
-#define MBED_SERVO_H
-
-#include "mbed.h"
-
-/** Servo control class, based on a PwmOut
- *
- * Example:
- * @code
- * // Continuously sweep the servo through it's full range
- * #include "mbed.h"
- * #include "Servo.h"
- *
- * Servo myservo(p21);
- *
- * int main() {
- * while(1) {
- * for(int i=0; i<100; i++) {
- * myservo = i/100.0;
- * wait(0.01);
- * }
- * for(int i=100; i>0; i--) {
- * myservo = i/100.0;
- * wait(0.01);
- * }
- * }
- * }
- * @endcode
- */
-class Servo {
-
-public:
- /** Create a servo object connected to the specified PwmOut pin
- *
- * @param pin PwmOut pin to connect to
- */
- Servo(PinName pin);
-
- /** Set the servo position, normalised to it's full range
- *
- * @param percent A normalised number 0.0-1.0 to represent the full range.
- */
- void write(float percent);
-
- /** Read the servo motors current position
- *
- * @param returns A normalised number 0.0-1.0 representing the full range.
- */
- float read();
-
- /** Set the servo position
- *
- * @param degrees Servo position in degrees
- */
- void position(float degrees);
-
- /** Allows calibration of the range and angles for a particular servo
- *
- * @param range Pulsewidth range from center (1.5ms) to maximum/minimum position in seconds
- * @param degrees Angle from centre to maximum/minimum position in degrees
- */
- void calibrate(float range = 0.0005, float degrees = 45.0);
-
- /** Shorthand for the write and read functions */
- Servo& operator= (float percent);
- Servo& operator= (Servo& rhs);
- operator float();
-
-protected:
- PwmOut _pwm;
- float _range;
- float _degrees;
- float _p;
-};
-
-#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Servo.lib Sat Sep 07 08:57:23 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/simon/code/Servo/#4aa22c5b87a1
--- a/main.cpp Thu Sep 05 20:00:08 2019 +0000
+++ b/main.cpp Sat Sep 07 08:57:23 2019 +0000
@@ -8,7 +8,6 @@
#include "NDefLib/NDefNfcTag.h"
#include "NDefLib/RecordType/RecordURI.h"
#include "Servo.h"
-
/* Instantiate the expansion board */
static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5);
@@ -132,7 +131,8 @@
case 4:
// Set the onboard LED state & actuator PIN
myLed = atoi(message.getValue());
-
+ wait(0.1);
+ myservo = myservo <= 0 ? 0.5 : -0.05;
actuatorPin2 = atoi(message.getValue());
// Publish the updated LED state
if ((error = mqttClient.publishData(DATA_TOPIC, message.channel, NULL, NULL, message.getValue())) != CAYENNE_SUCCESS) {
@@ -210,7 +210,7 @@
int error = 0;
uint8_t id;
- float value1, value2;
+ float value1, value2, value3;
// char buffer1[32], buffer2[32];
/* Enable all sensors */
@@ -220,6 +220,7 @@
press_temp->read_id(&id);
hum_temp->get_temperature(&value1);
+ hum_temp->get_humidity(&value3);
// press_temp->get_temperature(&value1);
press_temp->get_pressure(&value2);
// printf("LPS22HB: [temp] %7s C, [press] %s mbar\r\n", print_double(buffer1, value1), print_double(buffer2, value2));
@@ -228,6 +229,10 @@
if ((error = mqttClient.publishData(DATA_TOPIC, 1, TYPE_TEMPERATURE, UNIT_CELSIUS, value1)) != CAYENNE_SUCCESS) {
printf("Publish temperature failed, error: %d\n", error);
}
+
+ if ((error = mqttClient.publishData(DATA_TOPIC, 5, TYPE_RELATIVE_HUMIDITY, UNIT_PERCENT, value3)) != CAYENNE_SUCCESS) {
+ printf("Publish humidity failed, error: %d\n", error);
+ }
if ((error = mqttClient.publishData(DATA_TOPIC, 3, TYPE_VOLTAGE, UNIT_VOLTS, voltage_read)) != CAYENNE_SUCCESS) {
printf("Publish voltage failed, error: %d\n", error);
@@ -255,10 +260,6 @@
// Set the default function that receives Cayenne messages.
mqttClient.setDefaultMessageHandler(messageArrived);
- for(float p=0; p<1.0; p += 0.2) {
- myservo = p;
- wait(1.5);
-}
// Connect to Cayenne.
if (connectClient() == CAYENNE_SUCCESS) {