No Description

adafruitss.cxx 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Author: Stan Gifford <stan@gifford.id.au>
  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. /**
  25. * Description
  26. * Demo program for Adafruit 16 channel servo shield/controller
  27. * Physical setup for tests is a single servo attached to one channel.
  28. * Note - when 3 or more GWS servos attached results unpredictable.
  29. * Adafruit do recommend a Cap be installed on the board which should alleviate the issue.
  30. * I (and Adafruit) are unable to give any Capacitor sizing data.
  31. */
  32. #include <iostream>
  33. #include "adafruitss.h"
  34. #include <unistd.h>
  35. using namespace std;
  36. int main() {
  37. int n;
  38. //! [Interesting]
  39. upm::adafruitss* servos = new upm::adafruitss(6,0x40);
  40. for (;;)
  41. {
  42. cout << "Setting all to 0" << endl;
  43. for (n = 0; n < 16; n++)
  44. servos->servo(n, 1, 0); // GWS Mini Servo = Type 1.
  45. usleep(1000000); // Wait 1 second
  46. cout << "Setting all to 45" << endl;
  47. for (n = 0; n < 16; n++)
  48. servos->servo(n, 1, 45);
  49. usleep(1000000); // Wait 1 second
  50. cout << "Setting all to 90" << endl;
  51. for (n = 0; n < 16; n++)
  52. servos->servo(n, 1, 90);
  53. usleep(1000000); // Wait 1 second
  54. cout << "Setting all to 135" << endl;
  55. for (n = 0; n < 16; n++)
  56. servos->servo(n, 1, 135);
  57. usleep(1000000); // Wait 1 second
  58. cout << "Setting all to 180" << endl;
  59. for (n = 0; n < 16; n++)
  60. servos->servo(n, 1, 160);
  61. usleep(2000000); // Wait 1 second
  62. }
  63. //! [Interesting]
  64. return 0;
  65. }