Compare commits
7 Commits
main
...
developmen
| Author | SHA1 | Date | |
|---|---|---|---|
| 57a7528ba3 | |||
| 7d31db7fcb | |||
| 02a9c782c2 | |||
| 4a4a66f0d4 | |||
| d68882b301 | |||
| 744d148581 | |||
| 0cc6f49130 |
@@ -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();
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -66,4 +99,43 @@ bool Reader::debounceReadNC(int buttonPin)
|
||||
lastButtonStateNC = reading;
|
||||
}
|
||||
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,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);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
11
test/README
11
test/README
@@ -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
|
||||
43
test/test_user_functions.cpp
Normal file
43
test/test_user_functions.cpp
Normal 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() {}
|
||||
Reference in New Issue
Block a user