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