Hussain in the membrane

no shiftin in arduino… what the truck?!

Posted in thesis by teenybreeny on March 25, 2009

So, I am trying to get digital binary numbers from a compass sensor to read into Arduino, except there IS NO SHIFTIN FUNCTION, so I have to create my own function for this. Almost there. Today in Adv. Physical Computing, I figured out how to do this with a Piso Shift Register. SOON! I promise, SOON! I will be getting to the point where the compass sensor can talk to Max to create an interesting output.

In the meantime, enjoy the code. Use it, abuse it, live it, love it:

//**************************************************************//
// Name : Piso readings //
// Author : Ambreen Hussain //
// Date : 9 March 2009 //
// Version : 1.0 //
// Notes : Code for reading digital output that receives a //
// : binary input //
//****************************************************************

//Pin connected to for dataOut
int dataPin = 13;
////Pin connected to dataIn
int clockPin = 12;
//Pin connected to clockPin
int enablePin = 11;

//variable setup
int incomingByte;
int n = 0;

void setup() {
//set pins to output because they are addressed in the main loop
pinMode(dataPin, INPUT);
pinMode(clockPin, OUTPUT);
pinMode(enablePin, OUTPUT);
Serial.begin(9600);
digitalWrite (clockPin, HIGH);
digitalWrite (enablePin, HIGH);
}

void loop() {

compassGetBinary();

// send print data in:
Serial.println(incomingByte, BIN);

//delay 500 milliseconds before next reading:
delay(500);

}

void compassGetBinary () {

// drafted code for resetting/enabling
digitalWrite(enablePin, LOW);
digitalWrite(enablePin, HIGH);

for (int i = 7; i > -1; i–) {

n = digitalRead(dataPin);
bitWrite(incomingByte, i, n);
digitalWrite (clockPin, LOW);
digitalWrite(clockPin, HIGH);
delay (1);
//digitalWrite(clockPin, HIGH);

}
return;
}

Leave a Reply