Sunday, April 13, 2008

Tomorrow

milkcrate #23.

check the blog for updates.

4 comments:

Anonymous said...

Good luck Seb & Co. See you in the aftermath.
HM

me me said...

Hey Sebastian

I tried figuring out the 4021 coding but Im pretty sure I have no idea what Im doing - on both the max/msp and the arduino side... i pretty much used the arduino code from the site u gave me but im not sure I know what im doing on the max/msp side.


here are the two codes. - any direction would be great.

/////////////

#P user multiSlider 173 226 218 78 0. 1. 8 2681 15 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 156 167 48 9109513 zl group 8;
#P newex 156 104 45 9109513 metro 10;
#P message 156 78 14 9109513 1;
#P newex 156 51 45 9109513 loadbang;
#P message 30 71 26 9109513 print;
#P newex 156 137 61 9109513 serial g 9600;
#P connect 5 0 6 0;
#P connect 0 0 5 0;
#P connect 2 0 3 0;
#P connect 3 0 4 0;
#P connect 4 0 0 0;
#P connect 1 0 0 0;
#P window clipboard copycount 7;


////////////////////

//define where your pins are
int latchPin = 8;
int dataPin = 9;
int clockPin = 7;

//Define variables to hold the data
//for shift register.
//starting with a non-zero numbers can help
//troubleshoot
byte switchVar1 = 72; //01001000

byte lowcBitNum = 7;
byte dBitNum = 6;
byte eBitNum = 5;
byte fBitNum = 4;
byte gBitNum = 3;
byte aBitNum = 2;
byte bBitNum = 1;
byte highcNum = 0;

boolean dBit;


void setup() {
//start serial
Serial.begin(9600);

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

}

void loop() {

//Pulse the latch pin:
//set it to 1 to collect parallel data
digitalWrite(latchPin,1);
//set it to 1 to collect parallel data, wait
delayMicroseconds(20);
//set it to 0 to transmit data serially
digitalWrite(latchPin,0);

//while the shift register is in serial mode
//collect each shift register into a byte
//the register attached to the chip comes in first
switchVar1 = shiftIn(dataPin, clockPin);

//Print out the results.
//leading 0's at the top of the byte
//(7, 6, 5, etc) will be dropped before
//the first pin that has a high input
//reading
Serial.println(switchVar1, BIN);

//You can get a bit state through the subfunction
//written below by either...

//setting a boolean variable
dBit = getBit(switchVar1, dBitNum);

if (dBit) {
Serial.println("D");
}

//just validating a function (no new variable required)
if (getBit(switchVar1, aBitNum)) {
Serial.println("A");
}

//white space
Serial.println("-------------------");
//delay so all these print satements can keep up.
delay(500);

}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function
///// just needs the location of the data pin and the clock pin
///// it returns a byte with each bit in the byte corresponding
///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) {

//internal function setup
int i;
int temp = 0;
int pinState;
byte myDataIn = 0;

pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, INPUT);

//we will be holding the clock pin high 8 times (0,..,7) at the
//end of each time through the for loop

//at the begining of each loop when we set the clock low, it will
//be doing the necessary low to high drop to cause the shift
//register's DataPin to change state based on the value
//of the next bit in its serial information flow.
//The register transmits the information about the pins from pin 7 to pin 0
//so that is why our function counts down
for (i=7; i>=0; i--)
{
digitalWrite(myClockPin, 0);
delayMicroseconds(0.2);
temp = digitalRead(myDataPin);
if (temp) {
pinState = 1;
//set the bit to 0 no matter what
myDataIn = myDataIn | (1 << i);
}
else {
//turn it off -- only necessary for debuging
//print statement since myDataIn starts as 0
pinState = 0;
}

//Debuging print statements
//Serial.print(pinState);
//Serial.print(" ");
//Serial.println (dataIn, BIN);

digitalWrite(myClockPin, 1);

}
//debuging print statements whitespace
//Serial.println();
//Serial.println(myDataIn, BIN);
return myDataIn;
}

////// ----------------------------------------getBit
boolean getBit(byte myVarIn, byte whatBit) {
boolean bitState;
bitState = myVarIn & (1 << whatBit);
return bitState;
}


////// A little extra function...
////// ----------------------------------------setBit
byte setBit(byte myVarIn, byte whatBit, boolean s) {
boolean bitState;
if (s) {
myVarIn = myVarIn | (1 << whatBit);
} else {
myVarIn = myVarIn & ~(1 << whatBit);
}
return myVarIn;
}
///////////////////

Sebastian Tomczak said...

Stan, i am busy until tuesday or wednesday (doing a 24 hour music thing), so I won't have time to look into this until then. But if I forget, please, please prod me!

;-)

me me said...

Ok I will ask again on Wednesday good luck with the show.

stan