PHOBoS
Joined: Jan 14, 2010 Posts: 5591 Location: Moon Base
Audio files: 705
|
Posted: Wed Apr 04, 2018 2:37 pm Post subject:
Arduino and shiftregisters Subject description: controlling the 74HCT595 |
|
|
Since easter I started using my first Arduino which is a nano V3 (chinese clone).
To expand the inputs and outputs and make it easier to control things I made an interface a while ago.
It was originally created to use with a PIC to contol lights, but turned out to be useful for controlling synths
and of course I can just as easily use an arduino for it.
So I tested it and controlling the outputs worked right away but I had problems with the inputs. After messing
around with the code for a couple of hours I went back to using a PIC to see if the interface was still working.
I did initially have some problems and I don't know if there might have been some corroded connectors but
I got it to work.
I went back to the arduino and noticed that the values for the inputs I was reading where 1 to high.
(0 was 1, 1 was 2, etc.). I searched around a bit and found a replacement code for the shiftIn function.
Code: | uint8_t naShiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) {
uint8_t value = 0;
uint8_t i;
for (i = 0; i < 8; ++i) {
// digitalWrite(clockPin, HIGH); // old location of clock HIGH
if (bitOrder == LSBFIRST)
value |= digitalRead(dataPin) << i;
else
value |= digitalRead(dataPin) << (7 - i);
digitalWrite(clockPin, HIGH); // new location of clock HIGH
digitalWrite(clockPin, LOW);
}
return value;
} |
I found it here and it points to a github link but that is no longer vallid.
So if you run into a similar problem this might solve it. _________________ "My perf, it's full of holes!"
http://phobos.000space.com/
SoundCloud BandCamp MixCloud Stickney Synthyards Captain Collider Twitch YouTube |
|