Skip to content

Instantly share code, notes, and snippets.

@Craigson
Created September 30, 2014 15:25
Show Gist options
  • Save Craigson/782d6bd26be01ef38b94 to your computer and use it in GitHub Desktop.
Save Craigson/782d6bd26be01ef38b94 to your computer and use it in GitHub Desktop.
Serial Communication with Processing (ADXL335 Accelerometer)
const int buttonPin = 2;
void setup(){
Serial.begin(9600);
pinMode(buttonPin, INPUT);
establishContact();
}
void loop(){
if (Serial.available() > 0) {
int inByte = Serial.read();
//take reading for x-axis
int sensorValue = analogRead(A0);
Serial.print(sensorValue);
Serial.print(",");
//take reading for x-axis
sensorValue = analogRead(A1);
Serial.print(sensorValue);
Serial.print(",");
//take reading for x-axis
sensorValue = digitalRead(buttonPin);
Serial.println(sensorValue);
}
}
void establishContact(){
while (Serial.available() <= 0){
Serial.println("hello"); //send a starting message
delay(300);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment