Time to learn C now. Managing to control LED's via GPIO no problem using a separate pins, but I wanted to learn how to use shift registers.
I found an instructable on using them to drive LED's which I thought was perfect, so I bought a bundle of 74HC164N shift registers so the tutorial uses so there was less things to go wrong.
However, the python code didn't work for some reason, everything was wired exactly as it is online but not working.
I then seen that wiringPi has a Shift library, so I tried to use that to get the LEDs to flash just once, but the code I wrote(which compiles fine) just doesn't work at all. Not a hint of working.
I read that the unused input must be set high, so it is and all the rest is set as outputs.
Can someone please explain how to get these things working, as I'm clearly missing out something. I tried copying the Python script and rewriting it in C myself, and had a few flickers, but nothing like the instructable shows.
http://www.instructables.com/id/Using-a-shift-register-with-Raspberry-Pi/
Here is the crap code.
- Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <wiringPi.h>
#include <wiringShift.h>
#include <stdint.h>
int inputA = 15;
int inputB = 16;
int clock = 9;
int clear = 7;
setupPins(){
pinMode(inputA, OUTPUT);
pinMode(inputB, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(clear, OUTPUT);
digitalWrite(inputB, HIGH);
digitalWrite(clear, HIGH);
delay(10);
digitalWrite(clear, LOW);
}
int main (void){
if (wiringPiSetup () == -1){
exit (1);
}
setupPins();
int running = 1;
int i = 1;
while (running = 1){
shiftOut(inputA, clock, LSBFIRST, i);
delay(1500);
i++;
}
}