когда я загружаю это на свою плату, я получаю пин-карту, не найденную для периферийной ошибки. Я провел некоторое исследование по этой проблеме ( Одна из страниц, которые я посетил ), и я думаю, что понимаю проблему, однако все контакты, которые я использую, поддерживают именно то, что я их прошу. Эта проблема возникла только после того, как я преобразовал свой код из процедурного в объектно-ориентированный (я должен сделать это, чтобы правильно реализовать планирование).
У меня такое ощущение, что это связано с тем, как я инициализирую их в списке инициализатора члена конструктора, поскольку я не до конца понимаю, как это работает (я довольно новичок в C ++).
в моей программе есть другие классы, но они следуют той же структуре, что и мой класс UpdateOutput.
Заранее благодарим за любые советы.
int main() {
printf("inside main");
DigitalOut led1(LED1);
AnalogOut Vout(A0);
UpdateOutput wave;
SensorData inputs;
Timer time;
enum waves {OFF = 0, SINE, TRIANGLE, SAW, SQUARE};
int waveType = OFF;
float sonarCorrection = inputs.calibrateSonar();//makes a measurement of the acatual run time of the sonar code
float topFrequency = 1047.0f; //the highest frequency the synth will play
float upperSonarThreshold = 1000.0f; //the furthest distance the sonar will register
float lowerSonarThreshold = 100.0f; //the closest distance the sonar will measure
float period = 2272.73f;
//replace with:
//float period = inputs.getFrequency(float lowerThreshold, float upperThreshold, int correction, float topFrequency);
//after bug fixes have been applied
led1 = 1; //turn on led1 to show code is running properly
time.reset();
time.start();
int tmr = time.read_us();
//test loop before thredding is applied
while(true)
{
waveType = SINE; //keep synth producing a sine wave for testing
tmr = time.read_us();
switch(waveType)
{
case OFF:
Vout = 0.0f;
break;
case SINE:
Vout = wave.sinWave(tmr , period);
break;
case TRIANGLE:
Vout = wave.triangleWave(tmr , period);
break;
case SAW:
Vout = wave.sawWave(tmr, period);
break;
case SQUARE:
Vout = wave.squareWave(tmr, period);
break;
default:
waveType = TRIANGLE;
break;
}//end of wave type switch case
}
}
Обновление класса вывода:
class UpdateOutput{
public:
//constructor for class, with member initializer list
UpdateOutput(): runLed(LED2), clipLed(LED3), dac(D13)
{}
float sinWave(int tmr, float period);
float sawWave(int tmr, float period);
float triangleWave(int tmr, float period);
float squareWave(int tmr, float period);
private:
//class attributes
DigitalOut runLed;
DigitalOut clipLed;
AnalogOut dac;
//extern float frequency(float lowerThreshold, float upperThreshold, int correction);
bool waveState = 0;
//float lastVout;
};
пример функции в классе UpdateOutputs
float UpdateOutput::squareWave(int tmr, float period){
float Vout = 0.0f;
//float period5 = period/1.587401052;
float resultingWave;
float x = (float)(tmr % (int)period)/period;
if (x > 0.5f){
resultingWave = 1.0f;
}
else{
Vout = 0.0f;
}
Vout = (resultingWave/WAVE_DEVIDOR)+(0.25f); //translate wave to work between 0 and 1 rather than -1 and 1
if (Vout > 1){
clipLed = 1;
Vout = 1.0f;
}
else if (Vout < 0.0f){
clipLed = 1;
Vout = 0.0f;
}
//printf("Vout = %5.3f\n\r", Vout);
return Vout;
}//end of squareWave