Skip to content
Snippets Groups Projects
Commit a886d900 authored by Raymond Chia's avatar Raymond Chia
Browse files

update to dipswith code

parent 54678fa5
No related merge requests found
......@@ -29,6 +29,11 @@
/* LED Pins */
#define LED_BUILTIN 13
/* SWITCH Pins */
#define SWITCH_PIN1 30
#define SWITCH_PIN2 32
#define SWITCH_PIN3 34
/* =================================== */
/* Resolution */
/* =================================== */
......
#include "DIPSwitch.h"
DIPSwitch::DIPSwitch() {
pin = POT0_PIN;
pot_val = 0;
}
DIPSwitch::DIPSwitch() {}
DIPSwitch::~DIPSwitch() {}
DIPSwitch::DIPSwitch(uint16_t _pin) {
pin = _pin;
pot_val = 0;
pin_val = false;
}
DIPSwitch::~DIPSwitch() {}
void DIPSwitch::Set_Pin(uint16_t _pin) {
pin = _pin;
}
......@@ -25,9 +22,9 @@ uint16_t DIPSwitch::Get_Pin() {
}
void DIPSwitch::Read_DIPSwitch() {
pot_val = analogRead(pin);
pin_val = digitalRead(pin);
}
bool DIPSwitch::Get_Reading() {
return pot_val;
return pin_val;
}
......@@ -7,8 +7,8 @@
class DIPSwitch {
public:
DIPSwitch();
DIPSwitch(uint16_t _pin);
~DIPSwitch();
DIPSwitch(uint16_t _pin);
void Set_Pin(uint16_t _pin);
uint16_t Get_Pin();
void Set_Pin_Mode();
......
#include "Configuration.h"
#include "Potentiometer.h"
#include "DIPSwitch.h"
#include "VibrationMotor.h"
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int vibration_output;
int pot_val;
VibrationMotor VibeMotor(LED_BUILTIN, 0);
Potentiometer Pot(POT0_PIN);
DIPSwitch DSwitch[3];
void setup() {
Serial.begin(BAUDRATE);
Pot.Set_Pin_Mode();
VibeMotor.Set_Pin_Mode();
vibration_output = 0;
VibeMotor.Set_Amplitude(vibration_output);
DSwitch[0].Set_Pin(SWITCH_PIN1);
DSwitch[1].Set_Pin(SWITCH_PIN2);
DSwitch[2].Set_Pin(SWITCH_PIN3);
for(int i = 0; i < 3; i++) {
DSwitch[i].Set_Pin_Mode();
}
Serial.println("Pot Pin: " + String(POT0_PIN) + "\tVibe Pin : " +
String(LED_BUILTIN));
}
void loop() {
for(int i = 0; i < 3; i++) {
DSwitch[i].Read_DIPSwitch();
}
Pot.Read_Potentiometer();
pot_val = Pot.Get_Reading();
VibeMotor.Set_Amplitude(pot_val);
VibeMotor.Drive_Motor();
vibration_output = VibeMotor.Get_Amplitude();
Serial.println("pot_val: " + String(pot_val) +
"\tvibe_out: " + String(vibration_output));
delay(DELAY);
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment