Compare commits

7 Commits

Author SHA1 Message Date
57a7528ba3 Added function to reset potentiometer
All checks were successful
Generate Documentation / build (push) Successful in 15s
2025-11-02 14:18:01 +01:00
7d31db7fcb Added function to set pin modes 2025-11-02 14:15:46 +01:00
02a9c782c2 Removed reader class
All checks were successful
Generate Documentation / build (push) Successful in 15s
2025-11-02 14:10:50 +01:00
4a4a66f0d4 Fixed issues with test framework
All checks were successful
Generate Documentation / build (push) Successful in 12s
2025-11-02 14:05:32 +01:00
d68882b301 Added testing framework
All checks were successful
Generate Documentation / build (push) Successful in 36s
2025-11-02 13:46:48 +01:00
744d148581 Changed debounce delay
All checks were successful
Generate Documentation / build (push) Successful in 26s
2025-11-01 19:35:31 +01:00
0cc6f49130 Added comments
All checks were successful
Generate Documentation / build (push) Successful in 21s
2025-11-01 19:20:01 +01:00
7 changed files with 155 additions and 59 deletions

View File

@@ -1,16 +1,31 @@
#pragma once
class Reader
{
private:
unsigned long lastDebounceTime = 0;
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);
public:
bool debounceReadNO(int buttonPin);
bool 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);
/**
* @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();

View File

@@ -1,6 +1,6 @@
#pragma once
const int DEBOUNCE_DELAY = 200;
const int DEBOUNCE_DELAY = 250;
const int USER_STEPS = 2;
const int STAFF_STEPS = 16;

View File

@@ -1,8 +1,34 @@
/**
* @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 <commonFunctions.h>
#include <potControlls.h>
#include <constants.h>
bool Reader::debounceReadNO(int buttonPin)
unsigned long lastDebounceTime = 0;
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);
@@ -35,7 +61,14 @@ bool Reader::debounceReadNO(int buttonPin)
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);
@@ -67,3 +100,42 @@ bool Reader::debounceReadNC(int buttonPin)
}
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();
}
}

View File

@@ -10,34 +10,10 @@ int maxVolume = 64;
int userVolume = 64;
int oldUserVolume = userVolume;
Reader reader;
void setup()
{
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);
// Reset the potentiometer
for (int i = 0; i < 64; i++)
{
potIncrement();
}
setPinModes();
resetPotentiometer();
}
void loop()
@@ -45,39 +21,39 @@ void loop()
updateLeds(maxVolume);
// SW1 - Staff Volume Up
if (reader.debounceReadNC(BTN_STAFF_UP))
if (debounceReadNC(BTN_STAFF_UP))
{
staffVolumeUp(&maxVolume);
}
// SW2 - Staff Volume Down
if (reader.debounceReadNC(BTN_STAFF_DWN))
if (debounceReadNC(BTN_STAFF_DWN))
{
staffVolumeDown(&maxVolume, &userVolume, &oldUserVolume);
}
// Remote D - Mute
if (reader.debounceReadNO(REMOTE_D))
if (debounceReadNO(REMOTE_D))
{
mute(&userVolume, &oldUserVolume, maxVolume);
}
// Remote A - Significantly Lower Volume
if (reader.debounceReadNO(REMOTE_A))
if (debounceReadNO(REMOTE_A))
{
lowerVolume(&userVolume, &oldUserVolume, maxVolume);
}
// Remote B - Volume Up
// Make sure we are not is a state of mute or lowered
if (reader.debounceReadNO(REMOTE_B) && !(oldUserVolume > userVolume))
if (debounceReadNO(REMOTE_B) && !(oldUserVolume > userVolume))
{
volumeUp(&userVolume, &oldUserVolume, maxVolume);
}
// Remote C - Volume Down
// Make sure we are not is a state of mute or lowered
if (reader.debounceReadNO(REMOTE_C) && !(oldUserVolume > userVolume))
if (debounceReadNO(REMOTE_C) && !(oldUserVolume > userVolume))
{
volumeDown(&userVolume, &oldUserVolume);
}

View File

@@ -25,6 +25,7 @@ void mute(int *userVolume, int *oldUserVolume, int maxVolume)
if (*oldUserVolume > *userVolume)
{
// This is if the user is muted and is asking to be unmuted
// Check if max volume has been lowered since mute
if (*oldUserVolume > maxVolume)
{

View File

@@ -1,11 +0,0 @@
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

View File

@@ -0,0 +1,43 @@
#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() {}