Keine Beschreibung

pca9685.cxx 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Author: Jon Trulson <jtrulson@ics.com>
  3. * Copyright (c) 2015 Intel Corporation.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. #include <unistd.h>
  25. #include <signal.h>
  26. #include <iostream>
  27. #include "pca9685.h"
  28. using namespace std;
  29. int main(int argc, char **argv)
  30. {
  31. //! [Interesting]
  32. // Instantiate an PCA9685 on I2C bus 0
  33. upm::PCA9685 *leds = new upm::PCA9685(PCA9685_I2C_BUS,
  34. PCA9685_DEFAULT_I2C_ADDR);
  35. // put device to sleep
  36. leds->setModeSleep(true);
  37. // setup a period of 50Hz
  38. leds->setPrescaleFromHz(50);
  39. // wake device up
  40. leds->setModeSleep(false);
  41. // Setup a 50% duty cycle -- on time at 0, off time at 2048 (4096 / 2)
  42. // Set for all channels
  43. leds->ledOnTime(PCA9685_ALL_LED, 0);
  44. leds->ledOffTime(PCA9685_ALL_LED, 2048);
  45. // but, turn channel 3 full off and channel 4 full on
  46. cout << "Turning channel 3 off, and channel 4 on." << endl;
  47. cout << "All other channels will be PWM'd at a 50% duty cycle." << endl;
  48. leds->ledFullOff(3, true);
  49. leds->ledFullOn(4, true);
  50. // now, just sleep for 5 seconds, reset channels 3 and 4, and exit.
  51. cout << "Sleeping for 5 seconds..." << endl;
  52. sleep(5);
  53. cout << "Exiting..." << endl;
  54. // clear the bits we set earlier
  55. leds->ledFullOff(3, false);
  56. leds->ledFullOn(4, false);
  57. //! [Interesting]
  58. delete leds;
  59. return 0;
  60. }