mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 09:21:12 +03:00
@ -33,46 +33,47 @@ int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate a Water Flow Sensor on digital pin D2
|
||||
upm::WFS* flow = new upm::WFS(2);
|
||||
|
||||
// set the flow counter to 0 and start counting
|
||||
flow->clearFlowCounter();
|
||||
flow->startFlowCounter();
|
||||
// Instantiate a Water Flow Sensor on digital pin D2. This must
|
||||
// be an interrupt capable pin.
|
||||
upm::WFS* flow = new upm::WFS(2);
|
||||
|
||||
while (shouldRun)
|
||||
// set the flow counter to 0 and start counting
|
||||
flow->clearFlowCounter();
|
||||
flow->startFlowCounter();
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
// we grab these (,illis and flowCount) just for display
|
||||
// purposes in this example
|
||||
uint32_t millis = flow->getMillis();
|
||||
uint32_t flowCount = flow->flowCounter();
|
||||
// we grab these (millis and flowCount) just for display
|
||||
// purposes in this example
|
||||
uint32_t millis = flow->getMillis();
|
||||
uint32_t flowCount = flow->flowCounter();
|
||||
|
||||
float fr = flow->flowRate();
|
||||
float fr = flow->flowRate();
|
||||
|
||||
// output milliseconds passed, flow count, and computed flow rate
|
||||
cout << "Millis: " << millis << " Flow Count: " << flowCount;
|
||||
cout << " Flow Rate: " << fr << " LPM" << endl;
|
||||
// output milliseconds passed, flow count, and computed flow rate
|
||||
cout << "Millis: " << millis << " Flow Count: " << flowCount;
|
||||
cout << " Flow Rate: " << fr << " LPM" << endl;
|
||||
|
||||
// best to gather data for at least one second for reasonable
|
||||
// results.
|
||||
sleep(2);
|
||||
// best to gather data for at least one second for reasonable
|
||||
// results.
|
||||
sleep(2);
|
||||
}
|
||||
|
||||
flow->stopFlowCounter();
|
||||
flow->stopFlowCounter();
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete flow;
|
||||
return 0;
|
||||
delete flow;
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user