inf sachen
This commit is contained in:
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user