#define Accel 2 #define led 1 int reading = 0; int avg = 0; int threshold = 100; void setup() { //pinMode(2, INPUT); pinMode(led, OUTPUT); } void loop() { reading = analogRead(1); if (avg == 0) avg = reading; avg = (avg + reading) /2; // Serial.println(avg); if ( abs(reading - avg) > threshold) { digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(led, LOW); // turn the LED off by making the voltage LOW delay(1000); } // // if (reading > avg + threshold) { // Serial.println("Shake"); // } delay(100); }