summaryrefslogtreecommitdiff
path: root/HelloWorld/ADXL335.cpp
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2021-12-18 11:45:26 +0200
committerYuval Adam <_@yuv.al>2021-12-18 11:45:26 +0200
commitc1331d40912bc808f927c2f742da44530039123e (patch)
treed4dbecd20686dd764569a7a900b4984c8e0e8346 /HelloWorld/ADXL335.cpp
parent74b082c851303ff0a87b492c5f3c40759d1fd40c (diff)
Add lots of graphics libs and show axl readings
Diffstat (limited to 'HelloWorld/ADXL335.cpp')
-rw-r--r--HelloWorld/ADXL335.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/HelloWorld/ADXL335.cpp b/HelloWorld/ADXL335.cpp
new file mode 100644
index 0000000..9abdb3f
--- /dev/null
+++ b/HelloWorld/ADXL335.cpp
@@ -0,0 +1,84 @@
+/*
+ ADXL335.h
+ Library for accelerometer_ADXL335
+
+ Copyright (c) 2013 seeed technology inc.
+ Author : FrankieChu
+ Create Time : Jan 2013
+ Change Log :
+
+ The MIT License (MIT)
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+
+#include <Arduino.h>
+#include "ADXL335.h"
+
+void ADXL335::pinsInit() {
+ pinMode(X_AXIS_PIN, INPUT);
+ pinMode(Y_AXIS_PIN, INPUT);
+ pinMode(Z_AXIS_PIN, INPUT);
+}
+void ADXL335::begin() {
+ pinsInit();
+ scale = (float)SENSITIVITY * ADC_AMPLITUDE / ADC_REF;
+}
+void ADXL335::getXYZ(int* x, int* y, int* z) {
+ *x = analogRead(X_AXIS_PIN);
+ *y = analogRead(Y_AXIS_PIN);
+ *z = analogRead(Z_AXIS_PIN);
+}
+void ADXL335::getAcceleration(float* ax, float* ay, float* az) {
+ int x, y, z;
+ float xvoltage, yvoltage, zvoltage;
+ getXYZ(&x, &y, &z);
+
+ xvoltage = (float)x * ADC_REF / ADC_AMPLITUDE;
+ yvoltage = (float)y * ADC_REF / ADC_AMPLITUDE;
+ zvoltage = (float)z * ADC_REF / ADC_AMPLITUDE;
+
+ *ax = (xvoltage - ZERO_X) / SENSITIVITY;
+ *ay = (yvoltage - ZERO_Y) / SENSITIVITY;
+ *az = (zvoltage - ZERO_Z) / SENSITIVITY;
+}
+float ADXL335::getAccelerationX() {
+ int x, y, z;
+ float xvoltage, ax;
+ getXYZ(&x, &y, &z);
+ xvoltage = (float)x * ADC_REF / ADC_AMPLITUDE;
+ ax = (xvoltage - ZERO_X) / SENSITIVITY;
+ return ax;
+}
+float ADXL335::getAccelerationY() {
+ int x, y, z;
+ float yvoltage, ay;
+ getXYZ(&x, &y, &z);
+ yvoltage = (float)y * ADC_REF / ADC_AMPLITUDE;
+ ay = (yvoltage - ZERO_Y) / SENSITIVITY;
+ return ay;
+}
+float ADXL335::getAccelerationZ() {
+ int x, y, z;
+ float zvoltage, az;
+ getXYZ(&x, &y, &z);
+ zvoltage = (float)z * ADC_REF / ADC_AMPLITUDE;
+ az = (zvoltage - ZERO_Z) / SENSITIVITY;
+ return az;
+}