I wasn't able to figure out the ShiftIn/ShiftOut loopback configuration, but I managed to get multiple inputs working with a mcp23017. That said, I'm trying to use Shift Register Out to control the leds in the buttons but I think I am frying the 74hn595s (or something). It seems to flash twice, and then it doesn't flash anymore. It also doesn't seem to be flashing at the right times, almost like it's flashing the LED every time it changes which led should be lit. When I try a new IC, it flashes 2 or 3 times and then it stops. Am I doing something wrong?
I've verified that connecting the LED directly to vcc works.
I'm using this example:
/*
____ _____ _ _
| __ )| ____| | / \
| _ \| _| | | / _ \
| |_) | |___| |___ / ___ \
|____/|_____|_____/_/ \_\
http://bela.io
*/
#include <Bela.h>
#include <vector>
#include <libraries/ShiftRegister/ShiftRegister.h>
// Array for storing the values that are written to the register.
std::vector<bool> data = {1, 0, 1, 0, 1, 0, 1, 0};
//Connects to pin DS of 74HC595
unsigned int dataPin = 6;
//Connects to pin SH_CP of 74HC595
unsigned int clockPin = 7;
//Connects to pin ST_CP of 74HC595
unsigned int latchPin = 10;
// For cycling through the LEDs
int gCounter = 0;
const int gIntervalSamples = 2000; // samples between updates of the LEDs
unsigned int litLED = 0;
ShiftRegisterOut shiftRegister;
bool setup(BelaContext *context, void *userData)
{
shiftRegister.setup({.data = dataPin, .clock = clockPin, .latch = latchPin}, data.size());
return true;
}
void render(BelaContext *context, void *userData)
{
for(unsigned int n = 0; n < context->digitalFrames; ++n)
{
shiftRegister.process(context, n);
// once all previous data has been shifted out,
// start sending new data
if(shiftRegister.dataReady())
shiftRegister.setData(data);
// Cycle through LEDs, updating the data that is sent out every gIntervalSamples samples
if(gIntervalSamples == gCounter) {
for (unsigned int j = 0; j < data.size(); ++j){
// Start with all LEDs clear
data[j] = 0;
}
// only set one LED at a time
data[litLED] = 1;
++litLED;
if(litLED >= data.size())
litLED = 0;
gCounter = 0;
rt_printf("Interval passed, litLED %d\n", litLED);
}
++gCounter;
}
}
void cleanup(BelaContext *context, void *userData)
{
}
Connections on the Shift Register:
Pin 16 (vcc) -> vcc
Pin 15 -> N/A
Pin 14 (A) -> Bela pin 6
Pin 13 (output enable)-> ground
Pin 12 (latch clock) -> Bela pin 10
Pin 11 (shift clock) -> Bela pin 7
Pin 10 -> N/A
Pin 9 -> N/A
Pin 8 -> gnd
Pin 7 - 2 -> N/A
Pin 1 -> LED +