Compare commits
3 Commits
developmen
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| c6f4ebae13 | |||
| df56e7f4c8 | |||
| f81f22797e |
@@ -1,31 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/**
|
class Reader
|
||||||
* @brief Function used to read state of a normally open(LOW) button
|
{
|
||||||
*
|
private:
|
||||||
* @param buttonPin The pin of the button
|
unsigned long lastDebounceTime = 0;
|
||||||
* @return true
|
bool lastButtonStateNO = LOW;
|
||||||
* @return false
|
bool buttonStateNO = HIGH;
|
||||||
*/
|
bool lastButtonStateNC = HIGH;
|
||||||
bool debounceReadNO(int buttonPin);
|
bool buttonStateNC = LOW;
|
||||||
|
int lastPin;
|
||||||
|
|
||||||
/**
|
public:
|
||||||
* @brief Function used to read state of a normally closed(HIGH) button
|
bool debounceReadNO(int buttonPin);
|
||||||
*
|
bool debounceReadNC(int buttonPin);
|
||||||
* @param buttonPin The pin of the button
|
};
|
||||||
* @return true
|
|
||||||
* @return false
|
|
||||||
*/
|
|
||||||
bool debounceReadNC(int buttonPin);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sets all the pins to their correct modes
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void setPinModes();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Resets the potentiometer by setting the wiper all the way to the A pin
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void resetPotentiometer();
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
const int DEBOUNCE_DELAY = 250;
|
const int DEBOUNCE_DELAY = 200;
|
||||||
|
|
||||||
const int USER_STEPS = 2;
|
const int USER_STEPS = 2;
|
||||||
const int STAFF_STEPS = 16;
|
const int STAFF_STEPS = 16;
|
||||||
|
|||||||
@@ -1,34 +1,8 @@
|
|||||||
/**
|
|
||||||
* @file commonFunctions.cpp
|
|
||||||
* @author Lyubomir Penev (me@lpenev.com, 571147@student.fontys.nl)
|
|
||||||
* @brief This file contains all the functions used to read buttons
|
|
||||||
* @version 0.1
|
|
||||||
* @date 2025-10-31
|
|
||||||
*
|
|
||||||
* @copyright Copyright (c) 2025
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <commonFunctions.h>
|
#include <commonFunctions.h>
|
||||||
#include <potControlls.h>
|
|
||||||
#include <constants.h>
|
#include <constants.h>
|
||||||
|
|
||||||
unsigned long lastDebounceTime = 0;
|
bool Reader::debounceReadNO(int buttonPin)
|
||||||
bool lastButtonStateNO = LOW;
|
|
||||||
bool buttonStateNO = HIGH;
|
|
||||||
bool lastButtonStateNC = HIGH;
|
|
||||||
bool buttonStateNC = LOW;
|
|
||||||
int lastPin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Function used to read state of a normally open(LOW) button
|
|
||||||
*
|
|
||||||
* @param buttonPin The pin of the button
|
|
||||||
* @return true
|
|
||||||
* @return false
|
|
||||||
*/
|
|
||||||
bool debounceReadNO(int buttonPin)
|
|
||||||
{
|
{
|
||||||
bool reading = digitalRead(buttonPin);
|
bool reading = digitalRead(buttonPin);
|
||||||
|
|
||||||
@@ -61,14 +35,7 @@ bool debounceReadNO(int buttonPin)
|
|||||||
return buttonPressed;
|
return buttonPressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
bool Reader::debounceReadNC(int buttonPin)
|
||||||
* @brief Function used to read state of a normally closed(HIGH) button
|
|
||||||
*
|
|
||||||
* @param buttonPin The pin of the button
|
|
||||||
* @return true
|
|
||||||
* @return false
|
|
||||||
*/
|
|
||||||
bool debounceReadNC(int buttonPin)
|
|
||||||
{
|
{
|
||||||
bool reading = digitalRead(buttonPin);
|
bool reading = digitalRead(buttonPin);
|
||||||
|
|
||||||
@@ -100,42 +67,3 @@ bool debounceReadNC(int buttonPin)
|
|||||||
}
|
}
|
||||||
return buttonPressed;
|
return buttonPressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sets all the pins to their correct modes
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void setPinModes()
|
|
||||||
{
|
|
||||||
pinMode(LED_HIGH, OUTPUT); // Green
|
|
||||||
pinMode(LED_MED, OUTPUT); // Red LED (D4)
|
|
||||||
pinMode(LED_LOW, OUTPUT); // Green LED
|
|
||||||
|
|
||||||
pinMode(BTN_STAFF_UP, INPUT); // SW1
|
|
||||||
pinMode(BTN_STAFF_DWN, INPUT); // SW2
|
|
||||||
|
|
||||||
// RF Receiver
|
|
||||||
pinMode(REMOTE_A, INPUT); // Remote Button A
|
|
||||||
pinMode(REMOTE_B, INPUT); // Remote Button B
|
|
||||||
pinMode(REMOTE_C, INPUT); // Remote Button C
|
|
||||||
pinMode(REMOTE_D, INPUT); // Remote Button D
|
|
||||||
|
|
||||||
// Potentiometer
|
|
||||||
pinMode(POT_CS, OUTPUT); // D10 - CS
|
|
||||||
pinMode(POT_UD, OUTPUT); // D9 - U/D
|
|
||||||
digitalWrite(POT_CS, HIGH);
|
|
||||||
digitalWrite(POT_UD, LOW);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Resets the potentiometer by setting the wiper all the way to the A pin
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void resetPotentiometer()
|
|
||||||
{
|
|
||||||
// Reset the potentiometer
|
|
||||||
for (int i = 0; i < 64; i++)
|
|
||||||
{
|
|
||||||
potIncrement();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
40
src/main.cpp
40
src/main.cpp
@@ -10,10 +10,34 @@ int maxVolume = 64;
|
|||||||
int userVolume = 64;
|
int userVolume = 64;
|
||||||
int oldUserVolume = userVolume;
|
int oldUserVolume = userVolume;
|
||||||
|
|
||||||
|
Reader reader;
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
setPinModes();
|
pinMode(LED_HIGH, OUTPUT); // Green
|
||||||
resetPotentiometer();
|
pinMode(LED_MED, OUTPUT); // Red LED (D4)
|
||||||
|
pinMode(LED_LOW, OUTPUT); // Green LED
|
||||||
|
|
||||||
|
pinMode(BTN_STAFF_UP, INPUT); // SW1
|
||||||
|
pinMode(BTN_STAFF_DWN, INPUT); // SW2
|
||||||
|
|
||||||
|
// RF Receiver
|
||||||
|
pinMode(REMOTE_A, INPUT); // Remote Button A
|
||||||
|
pinMode(REMOTE_B, INPUT); // Remote Button B
|
||||||
|
pinMode(REMOTE_C, INPUT); // Remote Button C
|
||||||
|
pinMode(REMOTE_D, INPUT); // Remote Button D
|
||||||
|
|
||||||
|
// Potentiometer
|
||||||
|
pinMode(POT_CS, OUTPUT); // D10 - CS
|
||||||
|
pinMode(POT_UD, OUTPUT); // D9 - U/D
|
||||||
|
digitalWrite(POT_CS, HIGH);
|
||||||
|
digitalWrite(POT_UD, LOW);
|
||||||
|
|
||||||
|
// Reset the potentiometer
|
||||||
|
for (int i = 0; i < 64; i++)
|
||||||
|
{
|
||||||
|
potIncrement();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
@@ -21,39 +45,39 @@ void loop()
|
|||||||
updateLeds(maxVolume);
|
updateLeds(maxVolume);
|
||||||
|
|
||||||
// SW1 - Staff Volume Up
|
// SW1 - Staff Volume Up
|
||||||
if (debounceReadNC(BTN_STAFF_UP))
|
if (reader.debounceReadNC(BTN_STAFF_UP))
|
||||||
{
|
{
|
||||||
staffVolumeUp(&maxVolume);
|
staffVolumeUp(&maxVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SW2 - Staff Volume Down
|
// SW2 - Staff Volume Down
|
||||||
if (debounceReadNC(BTN_STAFF_DWN))
|
if (reader.debounceReadNC(BTN_STAFF_DWN))
|
||||||
{
|
{
|
||||||
staffVolumeDown(&maxVolume, &userVolume, &oldUserVolume);
|
staffVolumeDown(&maxVolume, &userVolume, &oldUserVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remote D - Mute
|
// Remote D - Mute
|
||||||
if (debounceReadNO(REMOTE_D))
|
if (reader.debounceReadNO(REMOTE_D))
|
||||||
{
|
{
|
||||||
mute(&userVolume, &oldUserVolume, maxVolume);
|
mute(&userVolume, &oldUserVolume, maxVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remote A - Significantly Lower Volume
|
// Remote A - Significantly Lower Volume
|
||||||
if (debounceReadNO(REMOTE_A))
|
if (reader.debounceReadNO(REMOTE_A))
|
||||||
{
|
{
|
||||||
lowerVolume(&userVolume, &oldUserVolume, maxVolume);
|
lowerVolume(&userVolume, &oldUserVolume, maxVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remote B - Volume Up
|
// Remote B - Volume Up
|
||||||
// Make sure we are not is a state of mute or lowered
|
// Make sure we are not is a state of mute or lowered
|
||||||
if (debounceReadNO(REMOTE_B) && !(oldUserVolume > userVolume))
|
if (reader.debounceReadNO(REMOTE_B) && !(oldUserVolume > userVolume))
|
||||||
{
|
{
|
||||||
volumeUp(&userVolume, &oldUserVolume, maxVolume);
|
volumeUp(&userVolume, &oldUserVolume, maxVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remote C - Volume Down
|
// Remote C - Volume Down
|
||||||
// Make sure we are not is a state of mute or lowered
|
// Make sure we are not is a state of mute or lowered
|
||||||
if (debounceReadNO(REMOTE_C) && !(oldUserVolume > userVolume))
|
if (reader.debounceReadNO(REMOTE_C) && !(oldUserVolume > userVolume))
|
||||||
{
|
{
|
||||||
volumeDown(&userVolume, &oldUserVolume);
|
volumeDown(&userVolume, &oldUserVolume);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ void mute(int *userVolume, int *oldUserVolume, int maxVolume)
|
|||||||
if (*oldUserVolume > *userVolume)
|
if (*oldUserVolume > *userVolume)
|
||||||
{
|
{
|
||||||
// This is if the user is muted and is asking to be unmuted
|
// This is if the user is muted and is asking to be unmuted
|
||||||
|
|
||||||
// Check if max volume has been lowered since mute
|
// Check if max volume has been lowered since mute
|
||||||
if (*oldUserVolume > maxVolume)
|
if (*oldUserVolume > maxVolume)
|
||||||
{
|
{
|
||||||
|
|||||||
11
test/README
Normal file
11
test/README
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
This directory is intended for PlatformIO Test Runner and project tests.
|
||||||
|
|
||||||
|
Unit Testing is a software testing method by which individual units of
|
||||||
|
source code, sets of one or more MCU program modules together with associated
|
||||||
|
control data, usage procedures, and operating procedures, are tested to
|
||||||
|
determine whether they are fit for use. Unit testing finds problems early
|
||||||
|
in the development cycle.
|
||||||
|
|
||||||
|
More information about PlatformIO Unit Testing:
|
||||||
|
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
#include <Arduino.h>
|
|
||||||
#include <unity.h>
|
|
||||||
|
|
||||||
void setUp(void)
|
|
||||||
{
|
|
||||||
// set stuff up here
|
|
||||||
}
|
|
||||||
|
|
||||||
void tearDown(void)
|
|
||||||
{
|
|
||||||
// clean stuff up here
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_function_should_doBlahAndBlah(void)
|
|
||||||
{
|
|
||||||
TEST_ASSERT_TRUE(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_function_should_doAlsoDoBlah(void)
|
|
||||||
{
|
|
||||||
TEST_ASSERT_TRUE(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
int runUnityTests(void)
|
|
||||||
{
|
|
||||||
UNITY_BEGIN();
|
|
||||||
RUN_TEST(test_function_should_doBlahAndBlah);
|
|
||||||
RUN_TEST(test_function_should_doAlsoDoBlah);
|
|
||||||
return UNITY_END();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For Arduino framework
|
|
||||||
*/
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
// Wait ~2 seconds before the Unity test runner
|
|
||||||
// establishes connection with a board Serial interface
|
|
||||||
delay(2000);
|
|
||||||
|
|
||||||
runUnityTests();
|
|
||||||
}
|
|
||||||
void loop() {}
|
|
||||||
Reference in New Issue
Block a user