2015-01-13 14:01:28 -07:00
|
|
|
/*
|
|
|
|
|
* Author: Jon Trulson <jtrulson@ics.com>
|
|
|
|
|
* Copyright (c) 2015 Intel Corporation.
|
|
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* This program and the accompanying materials are made available under the
|
|
|
|
|
* terms of the The MIT License which is available at
|
|
|
|
|
* https://opensource.org/licenses/MIT.
|
2015-01-13 14:01:28 -07:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2015-01-13 14:01:28 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <signal.h>
|
2017-08-30 15:00:29 -07:00
|
|
|
|
2016-04-25 14:27:51 -07:00
|
|
|
#include "groveledbar.hpp"
|
2017-08-30 15:00:29 -07:00
|
|
|
#include "upm_utilities.h"
|
2015-01-13 14:01:28 -07:00
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
int shouldRun = true;
|
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
void
|
|
|
|
|
sig_handler(int signo)
|
2015-01-13 14:01:28 -07:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
if (signo == SIGINT)
|
|
|
|
|
shouldRun = false;
|
2015-01-13 14:01:28 -07:00
|
|
|
}
|
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
int
|
|
|
|
|
main()
|
2015-01-13 14:01:28 -07:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
signal(SIGINT, sig_handler);
|
2015-01-13 14:01:28 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
2015-01-13 14:01:28 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// Instantiate a GroveLEDBar, we use D8 for the data, and D9 for the
|
|
|
|
|
// clock. This was tested with a Grove LED bar.
|
|
|
|
|
upm::GroveLEDBar bar(8, 9);
|
2016-01-29 17:02:35 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
while (shouldRun) {
|
|
|
|
|
// count up from green to red
|
|
|
|
|
for (int i = 0; i <= 10; i++) {
|
|
|
|
|
bar.setBarLevel(i, true);
|
|
|
|
|
upm_delay_us(100000);
|
2015-01-13 14:01:28 -07:00
|
|
|
}
|
2017-08-30 15:00:29 -07:00
|
|
|
upm_delay(1);
|
2015-01-13 14:01:28 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// count down from red to green
|
|
|
|
|
for (int i = 0; i <= 10; i++) {
|
|
|
|
|
bar.setBarLevel(i, false);
|
|
|
|
|
upm_delay_us(100000);
|
2015-01-13 14:01:28 -07:00
|
|
|
}
|
2017-08-30 15:00:29 -07:00
|
|
|
upm_delay(1);
|
2015-01-13 14:01:28 -07:00
|
|
|
}
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
2015-01-13 14:01:28 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << "Exiting..." << endl;
|
|
|
|
|
// turn off the LED's
|
|
|
|
|
bar.setBarLevel(0);
|
2015-01-13 14:01:28 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
return 0;
|
2015-01-13 14:01:28 -07:00
|
|
|
}
|