Eugene Mwangi
/
mbed-os-example-ble-WEIGHT-public
test code
Diff: source/main.cpp
- Revision:
- 83:dc516d289cc0
- Parent:
- 82:d40c223b65f9
--- a/source/main.cpp Tue Jun 25 10:05:54 2019 +0000 +++ b/source/main.cpp Wed Jun 26 03:34:13 2019 +0000 @@ -19,10 +19,10 @@ #include "ble/BLE.h" #include "WEIGHTService.h" #include "pretty_printer.h" -#include "hx711.h" +#include "Hx711.h" -HX711 scale(D5, D4); -float calibration_factor = 100; +Hx711 scale(D4, D5); //D4 is connected to clock. D5 is conected to data. +float calibration_factor = -1.0f; Serial pc(USBTX, USBRX); // USB Serial Terminal @@ -35,7 +35,7 @@ WEIGHTDemo(BLE &ble, events::EventQueue &event_queue) : _ble(ble), _event_queue(event_queue), -// _alive_led(LED1, 1), + _alive_led(LED1, 0), _weight_uuid(WEIGHTService::WEIGHT_SERVICE_UUID), _weight_service(NULL), _adv_data_builder(_adv_buffer) { } @@ -74,7 +74,10 @@ pc.printf("Ensure that there is no weight on the floor.\n"); - scale.tare(); + int offset = (int)scale.read(); + scale.set_offset(offset); + printf("Reading: %d \n",offset); + scale.set_scale(calibration_factor); start_advertising(); } @@ -127,18 +130,17 @@ { if (_ble.gap().getState().connected) { -// _alive_led = !_alive_led; - scale.setScale(calibration_factor); -// _current_weight = scale.getGram(); - _current_weight = 456.87; + _alive_led = !_alive_led; + _current_weight = scale.read(); +// _current_weight = 456.87; WeightType_t weight; weight.integer = (int32_t)_current_weight; float f_decimal = _current_weight - weight.integer; weight.decimal = (uint8_t)(f_decimal* 100.0f); -// if(_current_weight <= 0.00f) -// { -// _current_weight = 0.00; -// } + if(_current_weight <= 0.00f) + { + _current_weight = 0.00; + } _weight_service->updateWeight(_current_weight); pc.printf("Reading of float: %.2f\n", _current_weight); pc.printf("Reading of structure: %d.%d\n", weight.integer,weight.decimal); @@ -160,7 +162,7 @@ private: BLE &_ble; events::EventQueue &_event_queue; -// DigitalOut _alive_led; + DigitalOut _alive_led; UUID _weight_uuid; float _current_weight;