From 31d360f2d90cd0be8d9898320293e19fb2990e05 Mon Sep 17 00:00:00 2001
From: 13035516 <13035516@student.uts.edu.au>
Date: Fri, 15 Nov 2019 17:55:41 -0800
Subject: [PATCH] first commit

---
 .gitignore         | 20 ++++++++++++++++++++
 Configuration.h    | 41 +++++++++++++++++++++++++++++++++++++++++
 Potentiometer.cpp  | 33 +++++++++++++++++++++++++++++++++
 Potentiometer.h    | 23 +++++++++++++++++++++++
 VibrationMotor.cpp | 38 ++++++++++++++++++++++++++++++++++++++
 VibrationMotor.h   | 24 ++++++++++++++++++++++++
 6 files changed, 179 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 Configuration.h
 create mode 100644 Potentiometer.cpp
 create mode 100644 Potentiometer.h
 create mode 100644 VibrationMotor.cpp
 create mode 100644 VibrationMotor.h

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..41bfeab
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,20 @@
+# Swap
+[._]*.s[a-v][a-z]
+[._]*.sw[a-p]
+[._]s[a-v][a-z]
+[._]sw[a-p]
+
+# Session
+Session.vim
+
+# Temporary
+.netrwhist
+*~
+# Auto-generated tag files
+tags
+
+# Ignored directories
+Output/
+Data/
+Input/
+Test/
diff --git a/Configuration.h b/Configuration.h
new file mode 100644
index 0000000..dde17c6
--- /dev/null
+++ b/Configuration.h
@@ -0,0 +1,41 @@
+/*****************************************************************************************************
+ * PIN LAYOUT
+ * This file is used by other classes to define the pins used for the hardware.
+ *****************************************************************************************************/
+#ifndef CONFIGURATION_H
+#define CONFIGURATION_H
+
+#include <Arduino.h>
+
+/* Runtime Configuration */
+#define DELAY               0
+
+/* Debug Options */
+#define DEBUG               0
+
+/* Serial Options */
+#define BAUDRATE            115200
+#define PING                '1'
+
+/* =================================== */
+/* Pin layout */
+/* =================================== */
+/* Motor Pins */
+#define VIBRATION_PIN      28
+
+/* Potentiometer Pins */
+#define POT0_PIN           A3
+
+/* LED Pins */
+#define LED_BUILTIN        13
+
+/* =================================== */
+/* Resolution */
+/* =================================== */
+#define ADC_RES             1024
+
+/* Buffer len */
+#define DEFAULT_BUFFER_LEN  2560
+#define COMBINATION_LEN     3
+
+#endif
diff --git a/Potentiometer.cpp b/Potentiometer.cpp
new file mode 100644
index 0000000..579b7c7
--- /dev/null
+++ b/Potentiometer.cpp
@@ -0,0 +1,33 @@
+#include "Potentiometer.h"
+
+Potentiometer::Potentiometer() {
+    pin = POT0_PIN;
+    pot_val = 0;
+}
+
+Potentiometer::Potentiometer(uint16_t _pin) {
+    pin = _pin;
+    pot_val = 0;
+}
+
+Potentiometer::~Potentiometer() {}
+
+void Potentiometer::Set_Pin(uint16_t _pin) {
+    pin = _pin;
+}
+
+void Potentiometer::Set_Pin_Mode() {
+    pinMode(pin, INPUT);
+}
+
+uint16_t Potentiometer::Get_Pin() {
+    return pin;
+}
+
+void Potentiometer::Read_Potentiometer() {
+    pot_val = analogRead(pin);
+}
+
+int Potentiometer::Get_Reading() {
+    return pot_val;
+}
diff --git a/Potentiometer.h b/Potentiometer.h
new file mode 100644
index 0000000..6e440f3
--- /dev/null
+++ b/Potentiometer.h
@@ -0,0 +1,23 @@
+#ifndef _POTENTIOMETER_H_
+#define _POTENTIOMETER_H_
+
+#include <stdio.h>
+#include "Configuration.h"
+
+class Potentiometer {
+    public:
+        Potentiometer();
+        Potentiometer(uint16_t _pin);
+        ~Potentiometer();
+        void Set_Pin(uint16_t _pin);
+        void Set_Pin_Mode();
+        uint16_t Get_Pin();
+        void Read_Potentiometer();
+        int Get_Reading();
+    private:
+        uint16_t pin;
+        int pot_val;
+
+};
+
+#endif
diff --git a/VibrationMotor.cpp b/VibrationMotor.cpp
new file mode 100644
index 0000000..179fd2a
--- /dev/null
+++ b/VibrationMotor.cpp
@@ -0,0 +1,38 @@
+#include "VibrationMotor.h"
+
+VibrationMotor::VibrationMotor() {
+    pin = VIBRATION_PIN;
+    amplitude = 0;
+}
+
+VibrationMotor::VibrationMotor(uint16_t _pin, int _amplitude) {
+    pin = _pin;
+    amplitude = _amplitude;
+}
+
+VibrationMotor::~VibrationMotor() {}
+
+void VibrationMotor::Set_Pin(uint16_t _pin) {
+    pin = _pin;
+}
+
+void VibrationMotor::Set_Pin_Mode() {
+    pinMode(pin, OUTPUT);
+}
+
+uint16_t VibrationMotor::Get_Pin() {
+    return pin;
+}
+
+void VibrationMotor::Set_Amplitude(int _adc) {
+    // read in between 0 and 1023, analogWrite values from 0 to 255
+    amplitude = _adc / 4;
+}
+
+int VibrationMotor::Get_Amplitude() {
+    return amplitude;
+}
+
+void VibrationMotor::Drive_Motor() {
+    analogWrite(pin, amplitude);
+}
diff --git a/VibrationMotor.h b/VibrationMotor.h
new file mode 100644
index 0000000..3aa0433
--- /dev/null
+++ b/VibrationMotor.h
@@ -0,0 +1,24 @@
+#ifndef _VIBRATIONMOTOR_H_
+#define _VIBRATIONMOTOR_H_
+
+#include <stdio.h>
+#include "Configuration.h"
+
+class VibrationMotor {
+    public:
+        VibrationMotor();
+        VibrationMotor(uint16_t _pin, int _amplitude);
+        ~VibrationMotor();
+        void Set_Pin(uint16_t _pin);
+        uint16_t Get_Pin();
+        void Set_Pin_Mode();
+        void Set_Amplitude(int _amplitude);
+        int Get_Amplitude();
+        void Drive_Motor();
+    private:
+        uint16_t pin;
+        int amplitude;
+
+};
+
+#endif
-- 
GitLab