diff --git a/earthquake/earthquake.ino b/earthquake/earthquake.ino
index 89eb10abfe89b9c92db1bbe5ea1b64e3689d7d4b..c9b115fc283c849f1b1f6755f1b85272e703bbe8 100644
--- a/earthquake/earthquake.ino
+++ b/earthquake/earthquake.ino
@@ -5,13 +5,6 @@
#include "Wire.h"
#endif
-/*--------------------
- * WiFi Configuration
- *--------------------*/
-
-#define SSID "hm" //SSID
-#define PASS "abcdefgh" //Password
-
/*--------------------
* Pin const
*--------------------*/
@@ -77,7 +70,6 @@ volatile bool mpuInterrupt = false; // indicates whether MPU interrupt pin has g
* Declaration
*--------------------*/
-boolean connectWiFi();
void dmpDataReady();
void toggleButtonInit();
void sevenSegmentInit();
@@ -95,11 +87,6 @@ void gyroOff();
void setup() {
Serial.begin(115200);
- while(!Serial);
- Serial.println("AT");
-
- while(!connectWiFi());
- Serial.println("CONNECT");
// Toggle button
toggleButtonInit();
@@ -107,10 +94,6 @@ void setup() {
// Seven Segment
sevenSegmentInit();
- lastSeismoDetected = -10000;
- loopNumber = 0;
- amplitude = 0;
-
// LCD
lcdInit();
@@ -122,25 +105,6 @@ void setup() {
void loop() {
loopNumber++;
- // //LCD
- // lcd.print(" circuit digest");//print name
- // lcd.setCursor(0, 1); // set the cursor to column 0, line 2
- // lcd.print("ic tronic");//print name
- // delay(250);//delay of 0.75sec
- // lcd.scrollDisplayLeft();//shifting data on LCD
- // lcd.setCursor(0, 0);// set the cursor to column 0, line1
-
- // int measurement = analogRead(seismicPin);
- // float seismoMag = measurement / 2000000000.0 * 5.0;
- // Serial.print("measurment = "); Serial.println(measurement);
- // Serial.print("magnitude = "); Serial.println(seismoMag);
- // if (seismoMag > 2 && loopNumber - lastSeismoDetected > 10000) {
- // lastSeismoDetected = loopNumber;
- // // detected
- // // send post to http://jauhararifin.cf:8888/api/earthquakes
- // // header : content-type = application/x-www-form-urlencoded
- // // data = "lat=1&long=1&date=2016-12-06 PM 22:03:36.000Z&strength=" + seismoMag
- // }
reading = digitalRead(inPin);
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH)
@@ -165,31 +129,10 @@ void loop() {
* Implementation
*--------------------*/
-boolean connectWiFi() {
- Serial.println("AT+CWMODE=1");
- delay(2000);
- String cmd = "AT+CWJAP=\"";
- cmd += SSID;
- cmd += "\",\"";
- cmd += PASS;
- cmd += "\"";
- Serial.println(cmd);
- delay(5000);
- if (Serial.find((char*)"OK"))
- {
- return true;
- }
- else
- {
- return false;
- }
-}
-
void dmpDataReady() {
mpuInterrupt = true;
}
-
void toggleButtonInit(){
pinMode(inPin, INPUT);
pinMode(outPin, OUTPUT);
@@ -207,10 +150,9 @@ void lcdInit(){}
void gyroInit(){
magnitudeC = 0;
- // join I2C bus (I2Cdev library doesn't do this automatically)
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
- Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having compilation difficulties
+ Wire.setClock(400000);
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup(400, true);
#endif
@@ -231,29 +173,21 @@ void gyroInit(){
mpu.setXGyroOffset(220);
mpu.setYGyroOffset(76);
mpu.setZGyroOffset(-85);
- mpu.setZAccelOffset(1788); // 1688 factory default for my test chip
- // make sure it worked (returns 0 if so)
+ mpu.setZAccelOffset(1788);
if (devStatus == 0) {
- // turn on the DMP, now that it's ready
Serial.println(F("Enabling DMP..."));
mpu.setDMPEnabled(true);
- // enable Arduino interrupt detection
Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)..."));
attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), dmpDataReady, RISING);
mpuIntStatus = mpu.getIntStatus();
- // set our DMP Ready flag so the main loop() function knows it's okay to use it
Serial.println(F("DMP ready! Waiting for first interrupt..."));
dmpReady = true;
- // get expected DMP packet size for later comparison
packetSize = mpu.dmpGetFIFOPacketSize();
} else {
// ERROR!
- // 1 = initial memory load failed
- // 2 = DMP configuration updates failed
- // (if it's going to break, usually the code will be 1)
Serial.print(F("DMP Initialization failed (code "));
Serial.print(devStatus);
Serial.println(F(")"));
@@ -278,7 +212,7 @@ bool isChange(){
int dz = abs(aaWorldPrev[i].z - aaWorld.z);
bool isChange = (dx > offset || dy > offset || dz > offset);
if(isChange){
- double amplitudeNow = sqrt(pow(dx,2)+pow(dy,2)+pow(dz,2))*1000;
+ double amplitudeNow = sqrt(pow(dx,2)+pow(dy,2)+pow(dz,2))/1000;
amplitude = ((amplitudeNow>amplitude || amplitude==0.0)?amplitudeNow:amplitude);
return true;
}
@@ -288,7 +222,7 @@ bool isChange(){
double magnitudeConvert() {
// assume the epicentral distance is 0.5km
- return log10(amplitude)-0.83+1.73*log10(0.5);
+ return ((amplitude>9)?9:amplitude);
}
void displaySevenSegment(int val){
@@ -298,10 +232,10 @@ void displaySevenSegment(int val){
}
void ledActive(){
- Serial.print("LED : ");
- Serial.println(magnitudeC);
+// Serial.print("LED : ");
+// Serial.println(magnitudeC);
int fadeValue = floor(((float)magnitudeC/10)*255);
- Serial.print("Fade Value : "); Serial.println(fadeValue);
+// Serial.print("Fade Value : "); Serial.println(fadeValue);
analogWrite(ledPin, fadeValue);
}
@@ -311,32 +245,25 @@ void ledDeactive(){
void gyroOn(){
if (!dmpReady) return;
- while (!mpuInterrupt && fifoCount < packetSize); // wait for MPU interrupt or extra packet(s) available
+ while (!mpuInterrupt && fifoCount < packetSize);
mpuInterrupt = false;
mpuIntStatus = mpu.getIntStatus();
fifoCount = mpu.getFIFOCount();
- if ((mpuIntStatus & 0x10) || fifoCount == 1024) { // check for overflow
+ if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
mpu.resetFIFO();
Serial.println(F("FIFO overflow!"));
} else if (mpuIntStatus & 0x02) {
- while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount(); // wait for correct available data length, should be a VERY short wait
+ while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
- mpu.getFIFOBytes(fifoBuffer, packetSize); // read a packet from FIFO
+ mpu.getFIFOBytes(fifoBuffer, packetSize);
fifoCount -= packetSize;
- // display initial world-frame acceleration, adjusted to remove gravity and rotated based on known orientation from quaternion
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetAccel(&aa, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
mpu.dmpGetLinearAccelInWorld(&aaWorld, &aaReal, &q);
- Serial.print("aworld\t");
- Serial.print(aaWorld.x);
- Serial.print("\t");
- Serial.print(aaWorld.y);
- Serial.print("\t");
- Serial.println(aaWorld.z);
// blink LED to indicate activity
changeShift();
@@ -348,6 +275,12 @@ void gyroOn(){
displaySevenSegment(magnitudeC%10);
ledActive();
} else {
+ Serial.print("aworld\t");
+ Serial.print(aaWorld.x);
+ Serial.print("\t");
+ Serial.print(aaWorld.y);
+ Serial.print("\t");
+ Serial.println(aaWorld.z);
ledDeactive();
amplitude = 0;
displaySevenSegment(0);