Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update chapter-4/EMFDetector

  • Loading branch information...
commit 2f463790705c3b9e0421cef785199249cc8262e9 1 parent 4002022
@ejgertz authored
Showing with 195 additions and 13 deletions.
  1. +195 −13 chapter-4/EMFDetector
View
208 chapter-4/EMFDetector
@@ -1,28 +1,210 @@
-// Arduino Electromagnetic Interference Detector
-// Code modified by Patrick Di Justo, based on
+// Arduino Electromagnetic interference detector
+// Code modified by PAtrick Di Justo, based on
// Aaron ALAI EMF Detector April 22nd 2009 VERSION 1.0
// aaronalai1@gmail.com
//
-// The only output of this version is sound.
+// This outputs sound and numeric data to the 4char
-int inPin = 5;
-int val = 0;
+#include <SoftwareSerial.h>
+#define SerialIn 2
+#define SerialOut 7
+
+
+#define wDelay 900
+
+
+byte thou=0;
+byte hund=0;
+byte tens=0;
+byte ones=0;
+
+
+int inPin = 5;
+int val = 0;
+
+SoftwareSerial mySerialPort(SerialIn, SerialOut);
void setup()
{
- // So simple there's nothing to set up!
+
+
+ pinMode(SerialOut, OUTPUT);
+ pinMode(SerialIn, INPUT);
+
+
+mySerialPort.begin(19200);
+mySerialPort.print("vv");
+
+
+
+
+mySerialPort.print("xxxx");
+delay(wDelay);
+mySerialPort.print("----");
+delay(wDelay);
+mySerialPort.print("8888");
+delay(wDelay);
+mySerialPort.print("xxxx");
+delay(wDelay);
+
+
+
+
+ Serial.begin(9600);
+
}
+
void loop()
{
-
- val = analogRead(inPin);
-
- Serial.println(val);
- val = map(val, 1, 100, 1, 2048);
- tone(9,val,10);
-
+
+ val = analogRead(inPin);
+
+ Serial.println(val);
+ dispData(val);
+ val = map(val, 1, 100, 1, 2048);
+ tone(9,val,10);
+
}
+
+
+
+void dispData(int i)
+{
+
+
+char c = ' ';
+
+ones=0;
+tens=0;
+hund=0;
+thou=0;
+
+
+
+if((i<-999) || (i>9999))
+ {
+ mySerialPort.print("ERRx");
+ return;
+ }
+
+
+mySerialPort.print("w");
+
+int sign = i;
+i = abs(i);
+
+ones = i%10;
+if(i>=10) tens = ((i%100)-ones)/10;
+if(i>=100) hund = ((i%1000)-(tens*10)-ones)/100;
+if(i>=1000) thou = ((i%10000)-(hund*100)-(tens*10)-ones)/1000;
+
+
+
+
+if (thou>0)
+ {
+ mySerialPort.print(thou);
+ mySerialPort.print(hund);
+ mySerialPort.print(tens);
+ mySerialPort.print(ones);
+ return;
+ }
+
+
+if ((hund>0)&& (sign<0))
+ {
+ mySerialPort.print("-");
+ mySerialPort.print(hund);
+ mySerialPort.print(tens);
+ mySerialPort.print(ones);
+ Serial.print((int)hund);
+ Serial.print((int)tens);
+ Serial.print((int)ones);
+ Serial.print(c);
+ return;
+ }
+
+
+
+if (hund>0)
+ {
+ mySerialPort.print(hund);
+ mySerialPort.print(tens);
+ mySerialPort.print(ones);
+ mySerialPort.print(c);
+ Serial.print((int)hund);
+ Serial.print((int)tens);
+ Serial.print((int)ones);
+ Serial.print(c);
+ return;
+ }
+
+
+if ((tens>0) && (sign<0))
+ {
+ mySerialPort.print("-");
+ mySerialPort.print(tens);
+ mySerialPort.print(ones);
+ mySerialPort.print(c);
+ Serial.print("-");
+ Serial.print((int)tens);
+ Serial.print((int)ones);
+ Serial.print(c);
+
+
+
+
+ return;
+ }
+
+
+if (tens>0)
+ {
+ mySerialPort.print(tens);
+ mySerialPort.print(ones);
+ mySerialPort.print("x");
+ mySerialPort.print(c);
+ Serial.print((int)tens);
+ Serial.print((int)ones);
+ Serial.print("x");
+ Serial.print(c);
+
+
+
+
+ return;
+ }
+
+
+ if((ones>0) && (sign<0))
+ {
+ mySerialPort.print("-");
+ mySerialPort.print(ones);
+ mySerialPort.print("x");
+ mySerialPort.print(c);
+ Serial.print("-");
+ Serial.print((int)ones);
+ Serial.print("x");
+ Serial.print(c);
+ return;
+ }
+
+
+
+ if(ones>0)
+ {
+ mySerialPort.print("x");
+ mySerialPort.print(ones);
+ mySerialPort.print("x");
+ mySerialPort.print(c);
+ Serial.print("x");
+ Serial.print((int)ones);
+ Serial.print("x");
+ Serial.print(c);
+ return;
+ }
+}

0 comments on commit 2f46379

Please sign in to comment.
Something went wrong with that request. Please try again.