Gripporillat
Well-known member
Hi everybody!
I'm trying to pass an object by reference to another object but I'm afraid I somehow didn't get, how to do it.
Error message:
Code:
SkyPoti.h:
SkyPoti.cpp:
SkyFlash.h:
SkyFlash.cpp:
I hope it is readable. Thank you in Advance!
I'm trying to pass an object by reference to another object but I'm afraid I somehow didn't get, how to do it.
Error message:
Arduino: 1.8.8 (Windows 10), TD: 1.45, Board: "Teensy 3.5, MIDI, 120 MHz, Faster, US English"
Miditest2:6: error: no matching function for call to 'SkyFlash::SkyFlash(SkyPoti*, int)'
SkyFlash flash1(&poti1, 0);
^
In file included from */SkyController.h:5:0,
from *\Miditest2.ino:1:
*/SkyFlash.h:12:2: note: candidate: SkyFlash::SkyFlash(SkyPoti&, int)
SkyFlash(SkyPoti& Poti, int pin);
^
*/SkyFlash.h:12:2: note: no known conversion for argument 1 from 'SkyPoti*' to 'SkyPoti&'
*/SkyFlash.h:10:7: note: candidate: constexpr SkyFlash::SkyFlash(const SkyFlash&)
class SkyFlash {
^
*/SkyFlash.h:10:7: note: candidate expects 1 argument, 2 provided
*/SkyFlash.h:10:7: note: candidate: constexpr SkyFlash::SkyFlash(SkyFlash&&)
*/SkyFlash.h:10:7: note: candidate expects 1 argument, 2 provided
no matching function for call to 'SkyFlash::SkyFlash(SkyPoti*, int)'
Code:
Code:
#include "SkyController.h"
byte MIDIchannel = 1;
SkyPoti poti1(A0, 1, MIDIchannel);
SkyPoti poti2(A1, 2, MIDIchannel);
SkyFlash flash1(&poti1, 0);
void setup() {
}
void loop() {
poti1.send();
poti2.send();
flash1.send();
}
SkyPoti.h:
Code:
#ifndef SkyPoti_h
#define SkyPoti_h
#include "Arduino.h"
class SkyPoti
{
public:
SkyPoti(int pin, int number, byte channel);
void send();
void flash(bool on);
bool flashed;
int number;
private:
int _value;
int _pin;
int _newvalue;
int read();
int _newread;
int _divider;
byte _channel;
};
#endif
SkyPoti.cpp:
Code:
#include "Arduino.h"
#include "SkyPoti.h"
//Constructor
SkyPoti::SkyPoti(int pin, int number, byte channel) {
pinMode(pin, INPUT);
_pin = pin;
_value = 0;
number = number;
_channel = channel;
_newread;
_divider = 1023/127;
flashed = false;
}
//reads pin, averages signal, converts into MIDI value and returns value
int SkyPoti::read() {
_newread = analogRead(_pin);
if (_newread < _divider/2) {
return 0;
} else if (_newread % _divider == 0) {
return _newread / _divider;
} else {
return _value;
}
}
//checks for modulation, registers it and sends it if flashbutton is not active
void SkyPoti::send() {
_newvalue = read();
if (_newvalue != _value) {
if (!flashed) {
usbMIDI.sendControlChange(number, _newvalue, _channel);
}
_value = _newvalue;
}
}
//flashbutton
void SkyPoti::flash(on) {
if (on) {
flashed = true;
usbMIDI.sendControlChange(number, 127, _channel);
} else {
flashed = false;
usbMIDI.sendControlChange(number, _value, _channel);
}
}
SkyFlash.h:
Code:
#ifndef SkyFlash_h
#define SkyFlash_h
#include "Arduino.h"
#include "SkyPoti.h"
class SkyFlash {
public:
SkyFlash(SkyPoti& Poti, int pin);
void send();
private:
SkyPoti& poti;
};
#endif
SkyFlash.cpp:
Code:
#include "Arduino.h"
#include "SkyFlash.h"
#include "SkyPoti.h"
#include "Bounce.h"
//Constructor
SkyFlash::SkyFlash(SkyPoti& Poti, int pin) : Bounce(pin, 10) {
poti = Poti;
pinMode(pin, INPUT_PULLUP);
}
//flash that thing!
void SkyFlash::send() {
Bounce::update();
if (Bounce::fallingEdge()) {
poti->flash(true);
} else if (Bounce::risingEdge()) {
poti->flash(false);
}
}
I hope it is readable. Thank you in Advance!