I’ve successfully built and compiled JUCE on a raspberry pi b+ which works smooth. Now I'm trying to use WiringPi within JUCE with a knob/rotary encoder to display text on a lcd. Everything works but when I try to call wiringPi functions inside my juce app I get “undefined reference errors” to wiringPi.
My question is, how do I build WiringPi and Juce at the same time so that i can call wiringPi methods/functions inside of JUCE. Below is a snippet of my code
Here is the error im getting below:
Source/SynthUsingMidiInputTutorial_01.h:114: undefined reference to `wiringPiSetup'
Source/rotary_encoder.h:40: undefined reference to `digitalRead'
Source/SynthUsingMidiInputTutorial_01.h:122: undefined reference to `pinMode'
Source/SynthUsingMidiInputTutorial_01.h:125: undefined reference to `pullUpDnControl'
Source code:
//SynthUsingMidiInputTutorial_01.h
#include "rotary_encoder.h"
class SynthAudioSource : public AudioSource
{
public:
SynthAudioSource (MidiKeyboardState& keyState)
: keyboardState (keyState)
{
// add voices to our sampler
for (int i = 0; i < MAX_VOICES; i++)
{
synth.addVoice(new SamplerVoice());
}
// set up our AudioFormatManager class as detailed in the API docs
audioFormatManager.registerBasicFormats();
// now that we have our manager, lets read a simple file so we can pass it to our SamplerSound object.
File* file1 = new File("bass.wav");
ScopedPointer<AudioFormatReader> reader1 = audioFormatManager.createReaderFor(*file1);
File* file2 = new File("lead.wav");
ScopedPointer<AudioFormatReader> reader2 = audioFormatManager.createReaderFor(*file2);
File* file3 = new File("organ.wav");
ScopedPointer<AudioFormatReader> reader3 = audioFormatManager.createReaderFor(*file3);
BigInteger notes;
notes.setRange (0, 1, true);
SamplerSound::Ptr sound1 = new SamplerSound ("xx1", *reader1, notes, 0, 0.0, 1.0, 10.0);
synth.addSound (sound1);
BigInteger notes2;
notes2.setRange (1, 1, true);
SamplerSound::Ptr sound2 = new SamplerSound ("xx2", *reader2, notes2, 0, 0.0, 1.0, 10.0);
synth.addSound (sound2);
BigInteger notes3;
notes3.setRange (2, 1, true);
SamplerSound::Ptr sound3 = new SamplerSound ("xx3", *reader3, notes3, 0, 0.0, 1.0, 10.0);
synth.addSound (sound3);
int lcd; //Handle for LCD
wiringPiSetup(); //Initialise WiringPi
//Initialise LCD
if (lcd = lcdInit (2, 16,4, LCD_RS, LCD_E ,LCD_D4 , LCD_D5, LCD_D6,LCD_D7,0,0,0,0))
{
std::cout << "LcdInit failed!:";
}
pinMode(SwitchPin, INPUT);
pinMode(RotateAPin, INPUT);
pinMode(RotateBPin, INPUT);
pullUpDnControl(SwitchPin, PUD_UP);
if (wiringPiISR(SwitchPin, INT_EDGE_FALLING, &btnISR) < 0)
{
cout << "Unable to init ISR" << endl;
}
int tmp = 0;
while (1)
{
rotaryDeal();
if (tmp != globalCounter)
{
tmp = globalCounter;
if(globalCounter >= 10)
break;
}
}
lcdPosition(lcd,0,0); //Position cursor on the first line in the first column
lcdPuts(lcd, "Lead Bass:"); //Print the text on the LCD at the current cursor postion
}
And:
//rotary_encoder.h
#include <wiringPi>
static volatile int globalCounter = 0;
unsigned char flag;
unsigned char Last_RoB_Status;
unsigned char Current_RoB_Status;
void btnISR(void)
{
globalCounter = 0;
}
void rotaryDeal()
{
Last_RoB_Status = digitalRead(RotateBPin);
while (!digitalRead(RotateAPin))
{
Current_RoB_Status = digitalRead(RotateBPin);
flag = 1;
}
if (flag == 1)
{
flag = 0;
if ((Last_RoB_Status == 0) && (Current_RoB_Status == 1))
{
globalCounter++;
}
if ((Last_RoB_Status == 1) && (Current_RoB_Status == 0)) {
globalCounter--;
}
}
}