Hi Folks,
I have one problem left, that is I can't access variable KeyPressed.
C:\Users\jmazu\OneDrive\Documents\Arduino\SwitchTest/SwitchTest.ino:71: undefined reference to sControlKeys::KeyPressed' C:\Users\jmazu\AppData\Local\Temp\cc8eq38u.ltrans0.ltrans.o: In function Initialise':
C:\Users\jmazu\OneDrive\Documents\Arduino\SwitchTest/SwitchTest.ino:63: undefined reference to `sControlKeys::KeyPressed'
Any ideas?
FYI: I'm using a structure so I can encapsulate everything to do with the Control Switches. There will only be one instance.
#define O_PIN_CLOCK 22
#define O_PIN_LATCH 23
#define I_PIN_DATA 24
#define I_PIN_RUN_STATUS 25
#define I_PIN_KEY_PRESSED 26
int Index;
int Value;
int Mask;
struct sControlKeys {
#define CLOCK_LOW false
#define CLOCK_HIGH true
#define SERIAL_MODE false
#define PARALLEL_MODE true
private:
//Arduino Digital Pins.
int _O_Pin_Clock; // Output - Clocks the shift register. Low to High is the active clock edge.
int _O_Pin_Latch; // Output - Sets the mode of the shift Register. Parallel: High. Shift: Low
int _I_Pin_Data; // Input - Receives a bit (Q8) from the shift register.
int _I_Pin_Run_Status; // Input - State of the Run/Stop switch. Run: High. Low: Stop.
int _I_Pin_Key_Pressed; // Input - Receives a positive pulse whenever a key is pressed.
volatile static boolean KeyPressed;
public:
// ********* Informs the sructure which pins to use. **********
void SetPin_Clock(int PinNumber) {
_O_Pin_Clock = PinNumber;
}
void SetPin_Latch(int PinNumber) {
_O_Pin_Latch = PinNumber;
}
void SetPin_Data(int PinNumber) {
_I_Pin_Data = PinNumber;
}
void SetPin_RunStatus(int PinNumber) {
_I_Pin_Run_Status = PinNumber;
}
void SetPin_KeyPressed(int PinNumber) {
_I_Pin_Key_Pressed = PinNumber;
}
void Initialise(void) {
// Assigns the pin numbers
pinMode(_O_Pin_Clock, OUTPUT);
pinMode(_O_Pin_Latch, OUTPUT);
pinMode(_I_Pin_Data, INPUT);
pinMode(_I_Pin_Run_Status, INPUT);
pinMode(_I_Pin_Key_Pressed, INPUT);
digitalWrite(_O_Pin_Clock, CLOCK_LOW); // Clock low.
digitalWrite(_O_Pin_Latch, PARALLEL_MODE); // Shift register in parallel load mode.
KeyPressed = false;
attachInterrupt(digitalPinToInterrupt(_I_Pin_Key_Pressed), KeyPressedISR, RISING);
}
// Handles the key pressed interrupt.
static void KeyPressedISR(void) {
KeyPressed = true;
}
int ReadControlSwitches(void) {
//Latch the data.
digitalWrite(O_PIN_LATCH, SERIAL_MODE);
//Read the data.
Value = 0;
Mask = 0b00100000;
for (Index = 1; Index <= 6; Index++) {
if (digitalRead(I_PIN_DATA) != 0)
Value |= Mask;
// Cycle the clock.
digitalWrite(O_PIN_CLOCK, CLOCK_HIGH);
digitalWrite(O_PIN_CLOCK, CLOCK_LOW);
// Left shift one place
Mask = Mask >> 1;
}
// Put the shift register into parallel load mode.
digitalWrite(O_PIN_LATCH, PARALLEL_MODE);
return Value;
}
} ControlKeys;
//**********************************************************************//
void setup() {
ControlKeys.SetPin_Clock(O_PIN_CLOCK);
ControlKeys.SetPin_Latch(O_PIN_LATCH);
ControlKeys.SetPin_Data(I_PIN_DATA);
ControlKeys.SetPin_RunStatus(I_PIN_RUN_STATUS);
ControlKeys.SetPin_KeyPressed(I_PIN_KEY_PRESSED);
ControlKeys.Initialise();
Serial.begin(9600);
}
void loop() {
ControlKeys.ReadControlKeys();
Serial.println();
Serial.print("h");
Serial.print(Value, HEX);
delay(2000);
}