Saturday, April 30, 2011

Between going to Belize and classwork, the Arduino FCB1010 clone was put on the back burner for a few months. Sorry about the lack of updates.

So recently, I got to work on making the setup a bit more compact and add more to it in the process. I'm designing everything to use as few i/o pins as possible to the Arduino. Instead of using the MEGA2560 as I did before, I am designing all of this to work with an Arduino Pro Mini 328 which is basically like a postage stamp when compared to the behemoth I'm using now with the proof of concept.

With the image, you may have also noticed the LED display. Sparkfun has an awesome LED display  that is controlled via serial. I would gladly give up a TX pin for that. Once all of the kinks are worked out of the code, I will no longer need both TX and RX lines. For the sake of just getting things working, this won't really be gone over too much until the final version of everything.

The Hardware

Since the tutorials are readily available for both the 595  (shift out: Serial->Parallel) and the 4021 (Shift in: Parallel->Serial) I thought there was no sense in re-inventing the wheel. So here is the crappily Fritzed physical layout of everything.

The Code

This is really a combination of the two tutorial code examples. The clock is shared between the two circuits. All it does at the moment is when my hillbilly wire switch sends a pin between one of the 4021's and a 330ohm resistor to 5v, a corresponding LED turns on in the other circuit. You can monitor what is going on with the serial monitor. I just have the same thing being sent to the LED display at the moment.

#include <stdio.h>
//define where your pins are
int latchPin = 4;
int dataPin = 3;
int clockPin = 6;
int led_latchPin = 2;
int led_dataPin = 5;
int led[9];
char inputString[2];
int selected=1;
int bank=1;

byte switchVar1 = 72;
byte switchVar2 = 159;

int switch_selected[] = { 8, 7, 6, 5, 4, 3, 2, 1};

void setup() {
//start serial

//define pin modes
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, INPUT);
pinMode(led_latchPin, OUTPUT);
pinMode(led_dataPin, OUTPUT);

led[1] = 8;
led[2] = 9;
led[3] = 10;
led[4] = 11;
led[5] = 12;
led[6] = 13;
led[7] = 14;
led[8] = 15;
led[9] = 0;
led[10] = 1;
registerWrite(8, HIGH);
Serial.print(0x76, BYTE);

void loop() {




switchVar1 = shiftIn(dataPin, clockPin);
switchVar2 = shiftIn(dataPin, clockPin);

for (int n=0; n<=7; n++) { if (switchVar1 != 0){ if (switchVar1 & (1 << n) ){ Serial.print(0x76, BYTE); delay(20); if (switch_selected[n] < 6){ selected = switch_selected[n]; Serial.print(bank); Serial.print("_"); Serial.print(selected); }else{ selected = switch_selected[n]-5; Serial.print(bank+1); Serial.print("_"); Serial.print(selected); } registerWrite(led[switch_selected[n]], HIGH); } } } for (int n=0; n<=7; n++) { if (switchVar2 != 0){ if (switchVar2 & (1 << n) ){ if (switchVar2 >= 64){
Serial.print(0x76, BYTE);
selected = switch_selected[n]+3;
registerWrite(led[switch_selected[n]+8], HIGH);
else if(switchVar2 == 32){
if(bank == 25){
Serial.print(0x76, BYTE);
registerWrite(led[1], HIGH);
else if(switchVar2 == 16){
if(bank == 1){
Serial.print(0x76, BYTE);
registerWrite(led[1], HIGH);


byte shiftIn(int myDataPin, int myClockPin) {
int i;
int temp = 0;
int pinState;
byte myDataIn = 0;

pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, INPUT);
for (i=7; i>=0; i--)
digitalWrite(myClockPin, 0);
temp = digitalRead(myDataPin);
if (temp) {
pinState = 1;
myDataIn = myDataIn | (1 << i); } else { pinState = 0; } digitalWrite(myClockPin, 1); } return myDataIn; } void registerWrite(int whichPin, int whichState) { unsigned int bitsToSend = 0; digitalWrite(led_latchPin, LOW); bitWrite(bitsToSend, whichPin, whichState); byte registerOne = highByte(bitsToSend); byte registerTwo = lowByte(bitsToSend); shiftOut(led_dataPin, clockPin, MSBFIRST, registerTwo); shiftOut(led_dataPin, clockPin, MSBFIRST, registerOne); digitalWrite(led_latchPin,HIGH); }

Peppered in there is the code for making the LED display work. Best of luck to you.

Still to Come

Adding MIDI functionality
Custom PCB etching
Wiring, soldering tedium


Post a Comment

Subscribe to RSS Feed Follow me on Twitter!