#include <Servo.h>
int zpin = A1;
int accelerometer_z;
int i;
float zg;
Servo HL_servo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
HL_servo.attach(4); // attaches the servo on pin 20
}
void loop()
{
accelerometer_z = analogRead(zpin); //reads values from Z-pin & measures acceleration in Z direction
int z = map(accelerometer_z, 282, 418, -100, 100); //maps the extreme ends analog values from -100 to 100 for our understanding
float zg = (float)z/(100.00);
Serial.println(zg);
if(zg > 6.0){
delay(3100);
for(pos = 10; pos < 170; pos += 1) // goes from 10 degrees to 170 degrees
{ // in steps of 1 degree
HL_servo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
exit(1);
}