what is wrong with this
hey guys wrote following code ,
code: [select]
#include "wire.h"
#include "i2cdev.h"
#include "mpu6050.h"
#define sen_input 10
#define led_alert 12
mpu6050 mpu;
int16_t ax, ay, az;
int16_t gx, gy, gz;
int valx;
int prevvalx;
int valy;
int prevvaly;
void setup()
{
serial.begin(9600);
pinmode(sen_input, input);
pinmode(led_alert, output);
serial.println("initialize mpu");
mpu.initialize();
serial.println(mpu.testconnection() ? "connected" : "connection failed");
serial.println('at+cmgf=1');
}
void loop()
{
mpu.getmotion6(&ax, &ay, &az, &gx, &gy, &gz);
prevvalx = valx;
valx = map(ax, 17000, -17000, 0, 179);
if ( prevvalx >= 100)
{
serial.println("at");
delay(1000);
serial.println("at+cmgf=1"); // send sms in text mode
delay(1000);
serial.println("at+cmgs=\"+91925252871180166\""); //change number , you'd receive message
delay(1000);
serial.print(" (attention required)"); // content of message
serial.write(26); // ctrl+z ascii code
delay(3);
}
prevvaly = valy;
valy = map(ay, -17000, 17000, 0, 179);
if ( prevvaly >= 100)
{
digitalwrite(led_alert,high);
serial.println("at");
delay(1000);
serial.println("at+cmgf=1"); // send sms in text mode
delay(1000);
serial.println("at+cmgs=\"+9198752521180166\""); //change number , you'd receive message
delay(1000);
serial.print(" (attention required)"); // content of message
serial.write(26); // ctrl+z ascii code
delay(30);
}
int thief;
while(1)
{
thief=digitalread(sen_input);
if(thief)
{
digitalwrite(led_alert,high);
serial.println("at");
delay(1000);
serial.println("at+cmgf=1"); // send sms in text mode
delay(1000);
serial.println("at+cmgs=\"+919871180166\""); //change number , you'd receive message
delay(1000);
serial.print(" (attention required)"); // content of message
serial.write(26); // ctrl+z ascii code
delay(30);
delay(1);
}
}
}
this code takes reading last loop (pin 10) , ignores first 2 should thnks in advance
code: [select]
while(1)
within microseconds of sketch starting, it's going while(1) loop , stay there until reset it. if first 2 conditions not met on first reading (and won't be), never looked @ again.
Arduino Forum > Using Arduino > Programming Questions > what is wrong with this
arduino
Comments
Post a Comment