Tuesday, November 17, 2009

Week10

DMSS5 - Wk10


//**************************************************************************//
int analogData; // outgoing ADC value
int digitalPin;
int i; //used for the loop
byte x = 0; //byte to store digital status


void setup() {
//setup serial baudrate is set at the highest speed for USB connection
Serial.begin(57600);
//enable digital pullups. All digital pins are set high
//and will only output change when connected to ground
for(i=2;i<8;++i)>
{
digitalPin = i;
pinMode(digitalPin, INPUT);
digitalWrite(digitalPin, HIGH); //enable internal pullups
}
}

//Main Loop
void loop() { //read the digital pins in one go
x = PIND;
x = x >> 2; // Shift by 2 to avoid TX and RX pins
Serial.print(x, BYTE);

/* get analog in, for the number enabled */
analogData = analogRead(0); // Read current analog pin value
Serial.print(analogData >> 7, BYTE); // shift high bits into output byte
Serial.print(analogData % 128, BYTE); // mod by 128 for the small byte

analogData = analogRead(1); // Read current analog pin value
Serial.print(analogData >> 7, BYTE); // shift high bits into output byte
Serial.print(analogData % 128, BYTE); // mod by 128 for the small byte

Serial.print(255, BYTE); // end of digital signifier
delay(10);

}




Sunday, November 1, 2009

Accelerometer and proximity reader

DMSS5 Wk8

This week we just got familiar and tested out the acceleometer and the proximity sensor. They wererelatively simple and the diagrams below pretty much explain it all: