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);
|
||||
}
|
||||
Reference in New Issue
Block a user