inf sachen
This commit is contained in:
18
INF/libraries/PCA9685/examples/FrequencySweep/Constants.cpp
Normal file
18
INF/libraries/PCA9685/examples/FrequencySweep/Constants.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constants.cpp
|
||||
//
|
||||
//
|
||||
// Authors:
|
||||
// Peter Polidoro peterpolidoro@gmail.com
|
||||
// ----------------------------------------------------------------------------
|
||||
#include "Constants.h"
|
||||
|
||||
|
||||
namespace constants
|
||||
{
|
||||
const uint8_t device_address = 0x40;
|
||||
const size_t output_enable_pin = 2;
|
||||
|
||||
const size_t loop_delay = 100;
|
||||
const uint16_t frequency_increment = 10;
|
||||
}
|
||||
21
INF/libraries/PCA9685/examples/FrequencySweep/Constants.h
Normal file
21
INF/libraries/PCA9685/examples/FrequencySweep/Constants.h
Normal file
@@ -0,0 +1,21 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constants.h
|
||||
//
|
||||
//
|
||||
// Authors:
|
||||
// Peter Polidoro peterpolidoro@gmail.com
|
||||
// ----------------------------------------------------------------------------
|
||||
#ifndef CONSTANTS_H
|
||||
#define CONSTANTS_H
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
namespace constants
|
||||
{
|
||||
extern const uint8_t device_address;
|
||||
extern const size_t output_enable_pin;
|
||||
|
||||
extern const size_t loop_delay;
|
||||
extern const uint16_t frequency_increment;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,41 @@
|
||||
#include <Arduino.h>
|
||||
#include <PCA9685.h>
|
||||
|
||||
#include "Constants.h"
|
||||
|
||||
|
||||
PCA9685 pca9685;
|
||||
|
||||
uint16_t frequency_min;
|
||||
uint16_t frequency_max;
|
||||
uint16_t frequency;
|
||||
|
||||
void setup()
|
||||
{
|
||||
pca9685.setupSingleDevice(Wire,constants::device_address);
|
||||
|
||||
pca9685.setupOutputEnablePin(constants::output_enable_pin);
|
||||
pca9685.enableOutputs(constants::output_enable_pin);
|
||||
|
||||
pca9685.setOutputsNotInverted();
|
||||
|
||||
uint16_t time_min = pca9685.getTimeMin();
|
||||
uint16_t time_max = pca9685.getTimeMax();
|
||||
pca9685.setAllChannelsOnAndOffTime(time_min,time_max/4);
|
||||
|
||||
frequency_min = pca9685.getFrequencyMin();
|
||||
frequency_max = pca9685.getFrequencyMax();
|
||||
|
||||
frequency = frequency_min;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (frequency > frequency_max)
|
||||
{
|
||||
frequency = frequency_min;
|
||||
}
|
||||
pca9685.setToFrequency(frequency);
|
||||
frequency += constants::frequency_increment;
|
||||
delay(constants::loop_delay);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constants.cpp
|
||||
//
|
||||
//
|
||||
// Authors:
|
||||
// Peter Polidoro peterpolidoro@gmail.com
|
||||
// ----------------------------------------------------------------------------
|
||||
#include "Constants.h"
|
||||
|
||||
|
||||
namespace constants
|
||||
{
|
||||
const uint8_t device_address = 0x40;
|
||||
const size_t output_enable_pin = 2;
|
||||
|
||||
const size_t loop_delay = 100;
|
||||
const uint16_t frequency = 200;
|
||||
const uint16_t time_increment = 100;
|
||||
|
||||
const uint8_t channel = 0;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constants.h
|
||||
//
|
||||
//
|
||||
// Authors:
|
||||
// Peter Polidoro peterpolidoro@gmail.com
|
||||
// ----------------------------------------------------------------------------
|
||||
#ifndef CONSTANTS_H
|
||||
#define CONSTANTS_H
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
namespace constants
|
||||
{
|
||||
extern const uint8_t device_address;
|
||||
extern const size_t output_enable_pin;
|
||||
|
||||
extern const size_t loop_delay;
|
||||
extern const uint16_t frequency;
|
||||
extern const uint16_t time_increment;
|
||||
|
||||
extern const uint8_t channel;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,41 @@
|
||||
#include <Arduino.h>
|
||||
#include <PCA9685.h>
|
||||
|
||||
#include "Constants.h"
|
||||
|
||||
|
||||
PCA9685 pca9685;
|
||||
|
||||
uint16_t time_min;
|
||||
uint16_t time_max;
|
||||
uint16_t off_time;
|
||||
|
||||
void setup()
|
||||
{
|
||||
pca9685.setupSingleDevice(Wire,constants::device_address);
|
||||
|
||||
pca9685.setupOutputEnablePin(constants::output_enable_pin);
|
||||
pca9685.enableOutputs(constants::output_enable_pin);
|
||||
|
||||
pca9685.setOutputsNotInverted();
|
||||
|
||||
pca9685.setToFrequency(constants::frequency);
|
||||
|
||||
time_min = pca9685.getTimeMin();
|
||||
time_max = pca9685.getTimeMax();
|
||||
|
||||
off_time = time_min;
|
||||
|
||||
pca9685.setChannelOnTime(constants::channel,time_min);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (off_time > time_max)
|
||||
{
|
||||
off_time = time_min;
|
||||
}
|
||||
pca9685.setChannelOffTime(constants::channel,off_time);
|
||||
off_time += constants::time_increment;
|
||||
delay(constants::loop_delay);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constants.cpp
|
||||
//
|
||||
//
|
||||
// Authors:
|
||||
// Peter Polidoro peterpolidoro@gmail.com
|
||||
// ----------------------------------------------------------------------------
|
||||
#include "Constants.h"
|
||||
|
||||
|
||||
namespace constants
|
||||
{
|
||||
const uint8_t device_addresses[DEVICE_COUNT] =
|
||||
{
|
||||
0x40,
|
||||
0x41,
|
||||
0x42
|
||||
};
|
||||
const uint8_t device_index = 0;
|
||||
|
||||
const size_t output_enable_pin = 2;
|
||||
|
||||
const size_t loop_delay = 100;
|
||||
const uint16_t frequency = 200;
|
||||
const uint16_t time_increment = 100;
|
||||
|
||||
const uint8_t channel = 0;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constants.h
|
||||
//
|
||||
//
|
||||
// Authors:
|
||||
// Peter Polidoro peterpolidoro@gmail.com
|
||||
// ----------------------------------------------------------------------------
|
||||
#ifndef CONSTANTS_H
|
||||
#define CONSTANTS_H
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
namespace constants
|
||||
{
|
||||
enum{DEVICE_COUNT=3};
|
||||
extern const uint8_t device_addresses[DEVICE_COUNT];
|
||||
extern const uint8_t device_index;
|
||||
|
||||
extern const size_t output_enable_pin;
|
||||
|
||||
extern const size_t loop_delay;
|
||||
extern const uint16_t frequency;
|
||||
extern const uint16_t time_increment;
|
||||
|
||||
extern const uint8_t channel;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,46 @@
|
||||
#include <Arduino.h>
|
||||
#include <PCA9685.h>
|
||||
|
||||
#include "Constants.h"
|
||||
|
||||
|
||||
PCA9685 pca9685;
|
||||
|
||||
uint16_t time_min;
|
||||
uint16_t time_max;
|
||||
uint16_t on_time;
|
||||
|
||||
void setup()
|
||||
{
|
||||
pca9685.setWire(Wire);
|
||||
for (uint8_t device_index=0; device_index<constants::DEVICE_COUNT; ++device_index)
|
||||
{
|
||||
pca9685.addDevice(constants::device_addresses[device_index]);
|
||||
}
|
||||
pca9685.resetAllDevices();
|
||||
|
||||
pca9685.setupOutputEnablePin(constants::output_enable_pin);
|
||||
pca9685.enableOutputs(constants::output_enable_pin);
|
||||
|
||||
pca9685.setAllDevicesOutputsNotInverted();
|
||||
|
||||
pca9685.setAllDevicesToFrequency(constants::frequency);
|
||||
|
||||
time_min = pca9685.getTimeMin();
|
||||
time_max = pca9685.getTimeMax();
|
||||
|
||||
on_time = time_min;
|
||||
|
||||
pca9685.setAllDeviceChannelsOffTime(PCA9685::DEVICE_ADDRESS_ALL,time_max);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (on_time > time_max)
|
||||
{
|
||||
on_time = time_min;
|
||||
}
|
||||
pca9685.setAllDeviceChannelsOnTime(constants::device_addresses[constants::device_index],on_time);
|
||||
on_time += constants::time_increment;
|
||||
delay(constants::loop_delay);
|
||||
}
|
||||
23
INF/libraries/PCA9685/examples/ServoController/Constants.cpp
Normal file
23
INF/libraries/PCA9685/examples/ServoController/Constants.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constants.cpp
|
||||
//
|
||||
//
|
||||
// Authors:
|
||||
// Peter Polidoro peterpolidoro@gmail.com
|
||||
// ----------------------------------------------------------------------------
|
||||
#include "Constants.h"
|
||||
|
||||
|
||||
namespace constants
|
||||
{
|
||||
const uint8_t device_address = 0x40;
|
||||
const size_t output_enable_pin = 2;
|
||||
|
||||
const size_t loop_delay = 100;
|
||||
|
||||
const uint8_t channel = 0;
|
||||
|
||||
const uint16_t servo_pulse_duration_min = 900;
|
||||
const uint16_t servo_pulse_duration_max = 2100;
|
||||
const uint16_t servo_pulse_duration_increment = 100;
|
||||
}
|
||||
26
INF/libraries/PCA9685/examples/ServoController/Constants.h
Normal file
26
INF/libraries/PCA9685/examples/ServoController/Constants.h
Normal file
@@ -0,0 +1,26 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constants.h
|
||||
//
|
||||
//
|
||||
// Authors:
|
||||
// Peter Polidoro peterpolidoro@gmail.com
|
||||
// ----------------------------------------------------------------------------
|
||||
#ifndef CONSTANTS_H
|
||||
#define CONSTANTS_H
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
namespace constants
|
||||
{
|
||||
extern const uint8_t device_address;
|
||||
extern const size_t output_enable_pin;
|
||||
|
||||
extern const size_t loop_delay;
|
||||
|
||||
extern const uint8_t channel;
|
||||
|
||||
extern const uint16_t servo_pulse_duration_min;
|
||||
extern const uint16_t servo_pulse_duration_max;
|
||||
extern const uint16_t servo_pulse_duration_increment;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,32 @@
|
||||
#include <Arduino.h>
|
||||
#include <PCA9685.h>
|
||||
|
||||
#include "Constants.h"
|
||||
|
||||
|
||||
PCA9685 pca9685;
|
||||
|
||||
uint16_t servo_pulse_duration;
|
||||
|
||||
void setup()
|
||||
{
|
||||
pca9685.setupSingleDevice(Wire,constants::device_address);
|
||||
|
||||
pca9685.setupOutputEnablePin(constants::output_enable_pin);
|
||||
pca9685.enableOutputs(constants::output_enable_pin);
|
||||
|
||||
pca9685.setToServoFrequency();
|
||||
|
||||
servo_pulse_duration = constants::servo_pulse_duration_min;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (servo_pulse_duration > constants::servo_pulse_duration_max)
|
||||
{
|
||||
servo_pulse_duration = constants::servo_pulse_duration_min;
|
||||
}
|
||||
pca9685.setChannelServoPulseDuration(constants::channel,servo_pulse_duration);
|
||||
servo_pulse_duration += constants::servo_pulse_duration_increment;
|
||||
delay(constants::loop_delay);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constants.cpp
|
||||
//
|
||||
//
|
||||
// Authors:
|
||||
// Peter Polidoro peterpolidoro@gmail.com
|
||||
// ----------------------------------------------------------------------------
|
||||
#include "Constants.h"
|
||||
|
||||
|
||||
namespace constants
|
||||
{
|
||||
const uint8_t device_address = 0x40;
|
||||
const size_t output_enable_pin = 2;
|
||||
|
||||
const size_t loop_delay = 8000;
|
||||
const uint16_t frequency = 200;
|
||||
const uint8_t channel = 0;
|
||||
|
||||
const Example examples[EXAMPLE_COUNT] =
|
||||
{
|
||||
{
|
||||
20.0, // DUTY_CYCLE
|
||||
10.0, // PERCENT_DELAY
|
||||
},
|
||||
{
|
||||
90.0, // DUTY_CYCLE
|
||||
90.0, // PERCENT_DELAY
|
||||
},
|
||||
{
|
||||
// Always ON
|
||||
100.0, // DUTY_CYCLE
|
||||
0.0, // PERCENT_DELAY
|
||||
},
|
||||
{
|
||||
// Always OFF
|
||||
0.0, // DUTY_CYCLE
|
||||
0.0, // PERCENT_DELAY
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constants.h
|
||||
//
|
||||
//
|
||||
// Authors:
|
||||
// Peter Polidoro peterpolidoro@gmail.com
|
||||
// ----------------------------------------------------------------------------
|
||||
#ifndef CONSTANTS_H
|
||||
#define CONSTANTS_H
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
namespace constants
|
||||
{
|
||||
extern const uint8_t device_address;
|
||||
extern const size_t output_enable_pin;
|
||||
|
||||
extern const size_t loop_delay;
|
||||
extern const uint16_t frequency;
|
||||
extern const uint8_t channel;
|
||||
|
||||
enum{EXAMPLE_COUNT=4};
|
||||
|
||||
struct Example
|
||||
{
|
||||
double duty_cycle;
|
||||
double percent_delay;
|
||||
};
|
||||
|
||||
extern const Example examples[EXAMPLE_COUNT];
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
#include <Arduino.h>
|
||||
#include <PCA9685.h>
|
||||
|
||||
#include "Constants.h"
|
||||
|
||||
|
||||
PCA9685 pca9685;
|
||||
|
||||
uint8_t example_index;
|
||||
|
||||
void setup()
|
||||
{
|
||||
pca9685.setupSingleDevice(Wire,constants::device_address);
|
||||
|
||||
pca9685.setupOutputEnablePin(constants::output_enable_pin);
|
||||
pca9685.enableOutputs(constants::output_enable_pin);
|
||||
|
||||
pca9685.setToFrequency(constants::frequency);
|
||||
|
||||
example_index = 0;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
delay(constants::loop_delay);
|
||||
if (example_index >= constants::EXAMPLE_COUNT)
|
||||
{
|
||||
example_index = 0;
|
||||
}
|
||||
constants::Example example = constants::examples[example_index++];
|
||||
|
||||
pca9685.setChannelDutyCycle(constants::channel,example.duty_cycle,example.percent_delay);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constants.cpp
|
||||
//
|
||||
//
|
||||
// Authors:
|
||||
// Peter Polidoro peterpolidoro@gmail.com
|
||||
// ----------------------------------------------------------------------------
|
||||
#include "Constants.h"
|
||||
|
||||
|
||||
namespace constants
|
||||
{
|
||||
const uint8_t device_address = 0x40;
|
||||
const size_t output_enable_pin = 2;
|
||||
|
||||
const size_t loop_delay = 8000;
|
||||
const uint16_t frequency = 200;
|
||||
const uint8_t channel = 0;
|
||||
|
||||
const Example examples[EXAMPLE_COUNT] =
|
||||
{
|
||||
{
|
||||
// ON_TIME < OFF_TIME
|
||||
511, // ON_TIME
|
||||
3071, // OFF_TIME
|
||||
},
|
||||
{
|
||||
// ON_TIME < OFF_TIME
|
||||
2047, // ON_TIME
|
||||
767, // OFF_TIME
|
||||
},
|
||||
{
|
||||
// Always ON
|
||||
4096, // ON_TIME
|
||||
0, // OFF_TIME
|
||||
},
|
||||
{
|
||||
// Always OFF
|
||||
0, // ON_TIME
|
||||
4096, // OFF_TIME
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constants.h
|
||||
//
|
||||
//
|
||||
// Authors:
|
||||
// Peter Polidoro peterpolidoro@gmail.com
|
||||
// ----------------------------------------------------------------------------
|
||||
#ifndef CONSTANTS_H
|
||||
#define CONSTANTS_H
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
namespace constants
|
||||
{
|
||||
extern const uint8_t device_address;
|
||||
extern const size_t output_enable_pin;
|
||||
|
||||
extern const size_t loop_delay;
|
||||
extern const uint16_t frequency;
|
||||
extern const uint8_t channel;
|
||||
|
||||
enum{EXAMPLE_COUNT=4};
|
||||
|
||||
struct Example
|
||||
{
|
||||
uint16_t on_time;
|
||||
uint16_t off_time;
|
||||
};
|
||||
|
||||
extern const Example examples[EXAMPLE_COUNT];
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
#include <Arduino.h>
|
||||
#include <PCA9685.h>
|
||||
|
||||
#include "Constants.h"
|
||||
|
||||
|
||||
PCA9685 pca9685;
|
||||
|
||||
uint8_t example_index;
|
||||
|
||||
void setup()
|
||||
{
|
||||
pca9685.setupSingleDevice(Wire,constants::device_address);
|
||||
|
||||
pca9685.setupOutputEnablePin(constants::output_enable_pin);
|
||||
pca9685.enableOutputs(constants::output_enable_pin);
|
||||
|
||||
pca9685.setToFrequency(constants::frequency);
|
||||
|
||||
example_index = 0;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
delay(constants::loop_delay);
|
||||
if (example_index >= constants::EXAMPLE_COUNT)
|
||||
{
|
||||
example_index = 0;
|
||||
}
|
||||
constants::Example example = constants::examples[example_index++];
|
||||
|
||||
pca9685.setChannelOnAndOffTime(constants::channel,example.on_time,example.off_time);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constants.cpp
|
||||
//
|
||||
//
|
||||
// Authors:
|
||||
// Peter Polidoro peterpolidoro@gmail.com
|
||||
// ----------------------------------------------------------------------------
|
||||
#include "Constants.h"
|
||||
|
||||
|
||||
namespace constants
|
||||
{
|
||||
const uint8_t device_address = 0x40;
|
||||
const size_t output_enable_pin = 2;
|
||||
|
||||
const size_t loop_delay = 8000;
|
||||
const uint16_t frequency = 200;
|
||||
const uint8_t channel = 0;
|
||||
|
||||
const Example examples[EXAMPLE_COUNT] =
|
||||
{
|
||||
{
|
||||
819, // PULSE_WIDTH
|
||||
409, // PHASE_SHIFT
|
||||
},
|
||||
{
|
||||
3686, // PULSE_WIDTH
|
||||
3685, // PHASE_SHIFT
|
||||
},
|
||||
{
|
||||
// Always ON
|
||||
4096, // PULSE_WIDTH
|
||||
0, // PHASE_SHIFT
|
||||
},
|
||||
{
|
||||
// Always OFF
|
||||
0, // PULSE_WIDTH
|
||||
0, // PHASE_SHIFT
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constants.h
|
||||
//
|
||||
//
|
||||
// Authors:
|
||||
// Peter Polidoro peterpolidoro@gmail.com
|
||||
// ----------------------------------------------------------------------------
|
||||
#ifndef CONSTANTS_H
|
||||
#define CONSTANTS_H
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
namespace constants
|
||||
{
|
||||
extern const uint8_t device_address;
|
||||
extern const size_t output_enable_pin;
|
||||
|
||||
extern const size_t loop_delay;
|
||||
extern const uint16_t frequency;
|
||||
extern const uint8_t channel;
|
||||
|
||||
enum{EXAMPLE_COUNT=4};
|
||||
|
||||
struct Example
|
||||
{
|
||||
uint16_t pulse_width;
|
||||
uint16_t phase_shift;
|
||||
};
|
||||
|
||||
extern const Example examples[EXAMPLE_COUNT];
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
#include <Arduino.h>
|
||||
#include <PCA9685.h>
|
||||
|
||||
#include "Constants.h"
|
||||
|
||||
|
||||
PCA9685 pca9685;
|
||||
|
||||
uint8_t example_index;
|
||||
|
||||
void setup()
|
||||
{
|
||||
pca9685.setupSingleDevice(Wire,constants::device_address);
|
||||
|
||||
pca9685.setupOutputEnablePin(constants::output_enable_pin);
|
||||
pca9685.enableOutputs(constants::output_enable_pin);
|
||||
|
||||
pca9685.setToFrequency(constants::frequency);
|
||||
|
||||
example_index = 0;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
delay(constants::loop_delay);
|
||||
if (example_index >= constants::EXAMPLE_COUNT)
|
||||
{
|
||||
example_index = 0;
|
||||
}
|
||||
constants::Example example = constants::examples[example_index++];
|
||||
|
||||
pca9685.setChannelPulseWidth(constants::channel,example.pulse_width,example.phase_shift);
|
||||
}
|
||||
22
INF/libraries/PCA9685/examples/TestSetAndGet/Constants.cpp
Normal file
22
INF/libraries/PCA9685/examples/TestSetAndGet/Constants.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constants.cpp
|
||||
//
|
||||
//
|
||||
// Authors:
|
||||
// Peter Polidoro peterpolidoro@gmail.com
|
||||
// ----------------------------------------------------------------------------
|
||||
#include "Constants.h"
|
||||
|
||||
|
||||
namespace constants
|
||||
{
|
||||
const uint8_t device_address = 0x40;
|
||||
const size_t output_enable_pin = 2;
|
||||
|
||||
const long baud = 115200;
|
||||
|
||||
const size_t loop_delay = 100;
|
||||
const uint16_t frequency = 200;
|
||||
const uint16_t time_increment = 400;
|
||||
const double epsilon = 0.001;
|
||||
}
|
||||
24
INF/libraries/PCA9685/examples/TestSetAndGet/Constants.h
Normal file
24
INF/libraries/PCA9685/examples/TestSetAndGet/Constants.h
Normal file
@@ -0,0 +1,24 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constants.h
|
||||
//
|
||||
//
|
||||
// Authors:
|
||||
// Peter Polidoro peterpolidoro@gmail.com
|
||||
// ----------------------------------------------------------------------------
|
||||
#ifndef CONSTANTS_H
|
||||
#define CONSTANTS_H
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
namespace constants
|
||||
{
|
||||
extern const uint8_t device_address;
|
||||
extern const size_t output_enable_pin;
|
||||
|
||||
extern const long baud;
|
||||
extern const size_t loop_delay;
|
||||
extern const uint16_t frequency;
|
||||
extern const uint16_t time_increment;
|
||||
extern const double epsilon;
|
||||
}
|
||||
#endif
|
||||
105
INF/libraries/PCA9685/examples/TestSetAndGet/TestSetAndGet.ino
Normal file
105
INF/libraries/PCA9685/examples/TestSetAndGet/TestSetAndGet.ino
Normal file
@@ -0,0 +1,105 @@
|
||||
#include <Arduino.h>
|
||||
#include <PCA9685.h>
|
||||
#include <Streaming.h>
|
||||
|
||||
#include "Constants.h"
|
||||
|
||||
|
||||
PCA9685 pca9685;
|
||||
|
||||
uint16_t time_min;
|
||||
uint16_t time_max;
|
||||
|
||||
uint8_t channel;
|
||||
|
||||
uint16_t on_time_set;
|
||||
uint16_t off_time_set;
|
||||
uint16_t on_time_get;
|
||||
uint16_t off_time_get;
|
||||
|
||||
uint16_t pulse_width_set;
|
||||
uint16_t phase_shift_set;
|
||||
uint16_t pulse_width_get;
|
||||
uint16_t phase_shift_get;
|
||||
|
||||
double duty_cycle_set;
|
||||
double percent_delay_set;
|
||||
double duty_cycle_get;
|
||||
double percent_delay_get;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(constants::baud);
|
||||
|
||||
pca9685.setupSingleDevice(Wire,constants::device_address);
|
||||
|
||||
pca9685.setupOutputEnablePin(constants::output_enable_pin);
|
||||
pca9685.enableOutputs(constants::output_enable_pin);
|
||||
|
||||
pca9685.setOutputsNotInverted();
|
||||
|
||||
pca9685.setToServoFrequency();
|
||||
|
||||
time_min = pca9685.getTimeMin();
|
||||
time_max = pca9685.getTimeMax();
|
||||
|
||||
channel = 0;
|
||||
on_time_set = time_min;
|
||||
off_time_set = time_max;
|
||||
}
|
||||
|
||||
void checkMatch(const char * s, bool match)
|
||||
{
|
||||
if (match)
|
||||
{
|
||||
Serial << s << " get matches set.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial << s << " get does not match set!\n";
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (on_time_set > off_time_set)
|
||||
{
|
||||
on_time_set = time_min;
|
||||
off_time_set = time_max;
|
||||
}
|
||||
for (uint8_t channel=0; channel < pca9685.getChannelCount(); ++channel)
|
||||
{
|
||||
Serial << "frequency: " << pca9685.getFrequency() << "\n";
|
||||
Serial << "channel: " << channel << ", on_time_set: " << on_time_set << ", off_time_set: " << off_time_set << "\n";
|
||||
pca9685.setChannelOnAndOffTime(channel,on_time_set,off_time_set);
|
||||
pca9685.getChannelOnAndOffTime(channel,on_time_get,off_time_get);
|
||||
checkMatch("ChannelOnAndOffTime",((on_time_set == on_time_get) && (off_time_set == off_time_get)));
|
||||
|
||||
pca9685.setChannelOnTime(channel,on_time_set);
|
||||
pca9685.getChannelOnTime(channel,on_time_get);
|
||||
checkMatch("ChannelOnTime",(on_time_set == on_time_get));
|
||||
|
||||
pca9685.setChannelOffTime(channel,off_time_set);
|
||||
pca9685.getChannelOffTime(channel,off_time_get);
|
||||
checkMatch("ChannelOffTime",(off_time_set == off_time_get));
|
||||
|
||||
pulse_width_set = off_time_set - on_time_set;
|
||||
phase_shift_set = on_time_set;
|
||||
Serial << "channel: " << channel << ", pulse_width_set: " << pulse_width_set << ", phase_shift_set: " << phase_shift_set << "\n";
|
||||
pca9685.setChannelPulseWidth(channel,pulse_width_set,phase_shift_set);
|
||||
pca9685.getChannelPulseWidth(channel,pulse_width_get,phase_shift_get);
|
||||
checkMatch("ChannelPulseWidth",((pulse_width_set == pulse_width_get) && (phase_shift_set == phase_shift_get)));
|
||||
|
||||
duty_cycle_set = (pulse_width_set * pca9685.getDutyCycleMax()) / pca9685.getTimeMax();
|
||||
percent_delay_set = (phase_shift_set * pca9685.getPercentDelayMax()) / pca9685.getTimeMax();
|
||||
Serial << "channel: " << channel << ", duty_cycle_set: " << duty_cycle_set << ", percent_delay_set: " << percent_delay_set << "\n";
|
||||
pca9685.setChannelDutyCycle(channel,duty_cycle_set,percent_delay_set);
|
||||
pca9685.getChannelDutyCycle(channel,duty_cycle_get,percent_delay_get);
|
||||
checkMatch("ChannelDutyCycle",((abs(duty_cycle_set - duty_cycle_get) < constants::epsilon) && (abs(percent_delay_set - percent_delay_get) < constants::epsilon)));
|
||||
|
||||
Serial << "\n";
|
||||
delay(constants::loop_delay);
|
||||
}
|
||||
on_time_set += constants::time_increment;
|
||||
off_time_set -= constants::time_increment;
|
||||
}
|
||||
Reference in New Issue
Block a user