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