2014-05-22 14:17:33 +01:00
|
|
|
/*
|
|
|
|
|
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
|
|
|
|
|
* Copyright (c) 2014 Intel Corporation.
|
|
|
|
|
*
|
2019-05-09 09:47:11 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2018-01-24 15:09:29 +05:30
|
|
|
*
|
|
|
|
|
* Example usage: Generates PWM at a step rate of 0.01 continuously.
|
|
|
|
|
* Press Ctrl+C to exit
|
2014-05-22 14:17:33 +01:00
|
|
|
*/
|
|
|
|
|
|
2018-01-24 15:09:29 +05:30
|
|
|
/* standard headers */
|
|
|
|
|
#include <iostream>
|
2014-05-22 14:17:33 +01:00
|
|
|
#include <signal.h>
|
2018-01-24 15:09:29 +05:30
|
|
|
#include <stdlib.h>
|
2017-11-17 17:22:34 +05:30
|
|
|
#include <unistd.h>
|
2014-05-22 14:17:33 +01:00
|
|
|
|
2018-01-24 15:09:29 +05:30
|
|
|
/* mraa headers */
|
|
|
|
|
#include "mraa/common.hpp"
|
|
|
|
|
#include "mraa/pwm.hpp"
|
|
|
|
|
|
|
|
|
|
#define PWM_PORT 3
|
2014-05-22 14:17:33 +01:00
|
|
|
|
2018-01-24 15:09:29 +05:30
|
|
|
volatile sig_atomic_t flag = 1;
|
2014-05-22 14:17:33 +01:00
|
|
|
|
|
|
|
|
void
|
2018-01-24 15:09:29 +05:30
|
|
|
sig_handler(int signum)
|
2014-05-22 14:17:33 +01:00
|
|
|
{
|
2018-01-24 15:09:29 +05:30
|
|
|
if (signum == SIGINT) {
|
|
|
|
|
std::cout << "Exiting..." << std::endl;
|
|
|
|
|
flag = 0;
|
2014-05-22 14:17:33 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-23 14:39:12 +00:00
|
|
|
int
|
2018-01-24 15:09:29 +05:30
|
|
|
main(void)
|
2014-05-22 14:17:33 +01:00
|
|
|
{
|
2018-01-24 15:09:29 +05:30
|
|
|
float value = 0.0f;
|
|
|
|
|
|
2014-05-30 17:10:52 +01:00
|
|
|
signal(SIGINT, sig_handler);
|
2018-01-24 15:09:29 +05:30
|
|
|
|
2015-03-23 14:39:12 +00:00
|
|
|
//! [Interesting]
|
2018-01-24 15:09:29 +05:30
|
|
|
mraa::Pwm pwm(PWM_PORT);
|
|
|
|
|
std::cout << "Cycling PWM on IO3 (pwm3)" << std::endl;
|
2017-08-08 13:55:23 -07:00
|
|
|
pwm.enable(true);
|
2014-05-22 14:17:33 +01:00
|
|
|
|
2018-01-24 15:09:29 +05:30
|
|
|
while (flag) {
|
2014-05-22 14:17:33 +01:00
|
|
|
value = value + 0.01f;
|
2017-08-08 13:55:23 -07:00
|
|
|
pwm.write(value);
|
2014-05-22 14:17:33 +01:00
|
|
|
usleep(50000);
|
|
|
|
|
if (value >= 1.0f) {
|
|
|
|
|
value = 0.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-23 14:39:12 +00:00
|
|
|
//! [Interesting]
|
2014-05-22 14:17:33 +01:00
|
|
|
|
2018-01-24 15:09:29 +05:30
|
|
|
return EXIT_SUCCESS;
|
2014-05-22 14:17:33 +01:00
|
|
|
}
|