summaryrefslogtreecommitdiff
path: root/datasources/arduino/arduinoAnalogSerial/analog.ino
diff options
context:
space:
mode:
authorEbus-at-dockstar <ebus@dockstar>2014-07-26 19:55:43 +0200
committerEbus-at-dockstar <ebus@dockstar>2014-07-26 19:55:43 +0200
commita8cd2ecf7387d7bbe16808ca0c7acdb04a4909cb (patch)
tree524672c3237be2552379f9d752184bd3cbf1d554 /datasources/arduino/arduinoAnalogSerial/analog.ino
parent3f5b5ff5e71cf078c2c04906bffa06f3a1050085 (diff)
downloadebus-alt-a8cd2ecf7387d7bbe16808ca0c7acdb04a4909cb.tar.gz
ebus-alt-a8cd2ecf7387d7bbe16808ca0c7acdb04a4909cb.zip
Revert "embed xexpr-path" restore datastore-leveldb and other stuff
This reverts commit f6675ccdd7a5997def3c4656f0e2c5dbbbed1fc8.
Diffstat (limited to 'datasources/arduino/arduinoAnalogSerial/analog.ino')
-rwxr-xr-xdatasources/arduino/arduinoAnalogSerial/analog.ino61
1 files changed, 61 insertions, 0 deletions
diff --git a/datasources/arduino/arduinoAnalogSerial/analog.ino b/datasources/arduino/arduinoAnalogSerial/analog.ino
new file mode 100755
index 0000000..47bf63d
--- /dev/null
+++ b/datasources/arduino/arduinoAnalogSerial/analog.ino
@@ -0,0 +1,61 @@
+// vim: filetype=cpp expandtab shiftwidth=4 softtabstop=4
+
+const int ledPin = 13; // select the pin for the LED
+
+const long ADC_REF_MV = 3300;
+const long ADC_MAX_STEP = 1024;
+const long OV_FACTOR = 4; // Op. Verstärker Faktor = 4; 10mV = 1dB
+
+void sendKeyValue(const char *key, const char *value) {
+ Serial.print(key);
+ Serial.print("=");
+ Serial.println(value);
+}
+
+void sendPinValue(int pin) {
+ long sensorValue,
+ sensorValueMV,
+ sensorValueDBA;
+ char buf[12];
+ char *sensorKey = "arduino.aX",
+ *sensorKeyMV = "arduino.aX.mv",
+ *sensorKeyDBA = "arduino.aX.dba";
+ int port = A0 + pin;
+
+ sensorValue = analogRead(port);
+ sensorKey[9] = '0' + pin;
+ snprintf(buf, 8, "%u", sensorValue);
+ sendKeyValue(sensorKey, buf);
+
+ sensorValueMV = sensorValue * (ADC_REF_MV*100/ADC_MAX_STEP);
+ sensorKeyMV[9] = '0' + pin;
+ snprintf(buf, 8, "%ld.%03ld", sensorValueMV/100, sensorValue%100);
+ sendKeyValue(sensorKeyMV, buf);
+
+ sensorValueDBA = sensorValueMV / OV_FACTOR;
+ sensorKeyDBA[9] = '0' + pin;
+ snprintf(buf, 12, "%ld.%04ld", sensorValueDBA/1000, sensorValueDBA%1000);
+ sendKeyValue(sensorKeyDBA, buf);
+}
+
+void setup() {
+ Serial.begin(115200);
+ // declare the ledPin as an OUTPUT:
+ pinMode(ledPin, OUTPUT);
+ // Reference is EXTERNAL (3v)
+ analogReference(EXTERNAL);
+}
+
+void loop() {
+ if (Serial.available() > 0) {
+ digitalWrite(ledPin, HIGH);
+
+ int pin = Serial.read();
+ while (Serial.available()) Serial.read();
+
+ sendPinValue(pin-'0');
+ Serial.flush();
+
+ digitalWrite(ledPin, LOW);
+ }
+}