Hey guys i hate this weird issue that i just cant seem to solve and it's driving me crazy. Im making my first project for the Arduino which will use classes/self made library. I made a function to shift my bit in a 74HC595 register. I will have to make a custom function to clock 9 registers at the same time, but decided first to make a prototype made of 1 register. When i use the code below it all works nicely, making the LEDs at the end of the register run on and off.
digitalWrite(latch1, LOW);
digitalWrite(clk1, LOW);
digitalWrite(data1, HIGH);
digitalWrite(clk1, HIGH);
digitalWrite(latch1, HIGH);
delay(500);
digitalWrite(latch1, LOW);
digitalWrite(clk1, LOW);
digitalWrite(data1, LOW);
digitalWrite(clk1, HIGH);
digitalWrite(latch1, HIGH);
delay(500);
However when i use a method from my library it doesn't respond at all. This is what I made so far for the library (below). Can someone tell me what's the dumb thing im doing here?It looks like the whole thing freezes and nothing moves, just stays in its last state before the new code was uploaded and started. I never programmed in Arduino before and don't know the fine details, I just know the standard C++ and Java. Thx in advance!
class Reg{
private:
int clockPin;
int latchPin;
int dataPin;
public:
Reg(int clk, int latch, int data);
void shift(boolean a);
void reset();
void show();
};
Reg::Reg(int clk, int latch, int data){
pinMode(clk, OUTPUT);
pinMode(latch, OUTPUT);
pinMode(data, OUTPUT);
digitalWrite(clk, 0);
digitalWrite(latch, 0);
digitalWrite(data, 0);
reset();
}
void Reg::shift(boolean a){
digitalWrite(latchPin, LOW);
digitalWrite(clockPin, LOW);
if(a){
digitalWrite(dataPin, HIGH);
}else{
digitalWrite(dataPin, LOW);
}
digitalWrite(clockPin, HIGH);
digitalWrite(latchPin, HIGH);
}
void Reg::reset(){
for(int i = 0; i < 8; i++){
shift(0);
}
}
void Reg::show(){
digitalWrite(this->latchPin, HIGH);
digitalWrite(this->latchPin, LOW);
}
Reg reg1(clk1, latch1, data1);
Reg reg2(clk2, latch2, data2);
void setup() {
}
void loop() {
reg1.shift(1);
delay(500);
reg1.shift(0);
delay(500);
}
EDIT: BTW im aware that the code doesn't use its full functionality and some things are reduntant like the initialization in the constructor. Its a work in progress and first want to know why its not working at all.