Seperated potentiometer controlls
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the convention is to give header files names that end with `.h'.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||
4
include/potControlls.h
Normal file
4
include/potControlls.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
void potIncrement();
|
||||
void potDecrement();
|
||||
58
src/main.cpp
58
src/main.cpp
@@ -1,4 +1,5 @@
|
||||
#include <Arduino.h>
|
||||
#include <potControlls.h>
|
||||
|
||||
const int USER_STEPS = 2;
|
||||
const int STAFF_STEPS = 16;
|
||||
@@ -12,9 +13,7 @@ int lastButtonState = LOW;
|
||||
unsigned long lastDebounceTime = 0;
|
||||
unsigned long debounceDelay = 50;
|
||||
|
||||
void volumeUp();
|
||||
void volumeDown();
|
||||
bool debounceRead();
|
||||
bool debounceRead(int buttonPin);
|
||||
|
||||
void setup()
|
||||
{
|
||||
@@ -38,7 +37,7 @@ void setup()
|
||||
|
||||
for (int i = 0; i < 64; i++)
|
||||
{
|
||||
volumeUp();
|
||||
potIncrement();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +87,7 @@ void loop()
|
||||
{
|
||||
for (int i = 0; i < (userVolume - maxVolume); i++)
|
||||
{
|
||||
volumeDown();
|
||||
potDecrement();
|
||||
}
|
||||
|
||||
userVolume = maxVolume;
|
||||
@@ -118,7 +117,7 @@ void loop()
|
||||
|
||||
for (int i = 0; i < maxVolume; i++)
|
||||
{
|
||||
volumeUp();
|
||||
potIncrement();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -128,7 +127,7 @@ void loop()
|
||||
|
||||
for (int i = 0; i < oldUserVolume; i++)
|
||||
{
|
||||
volumeUp();
|
||||
potIncrement();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,7 +136,7 @@ void loop()
|
||||
// This is if the user is unmuted and is aksing to be muted
|
||||
for (int i = 0; i < 64; i++)
|
||||
{
|
||||
volumeDown();
|
||||
potDecrement();
|
||||
}
|
||||
|
||||
oldUserVolume = userVolume;
|
||||
@@ -162,7 +161,7 @@ void loop()
|
||||
|
||||
for (int i = 0; i < maxVolume; i++)
|
||||
{
|
||||
volumeUp();
|
||||
potIncrement();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -172,7 +171,7 @@ void loop()
|
||||
|
||||
for (int i = 0; i < oldUserVolume; i++)
|
||||
{
|
||||
volumeUp();
|
||||
potIncrement();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,7 +180,7 @@ void loop()
|
||||
// This is if the user is not lowered and is aksing to be lowered
|
||||
for (int i = 0; i < userVolume - 10; i++)
|
||||
{
|
||||
volumeDown();
|
||||
potDecrement();
|
||||
}
|
||||
|
||||
oldUserVolume = userVolume;
|
||||
@@ -197,7 +196,7 @@ void loop()
|
||||
{
|
||||
for (int i = 0; i < maxVolume - userVolume; i++)
|
||||
{
|
||||
volumeUp();
|
||||
potIncrement();
|
||||
}
|
||||
|
||||
userVolume = maxVolume;
|
||||
@@ -207,7 +206,7 @@ void loop()
|
||||
{
|
||||
for (int i = 0; i < USER_STEPS; i++)
|
||||
{
|
||||
volumeUp();
|
||||
potIncrement();
|
||||
}
|
||||
|
||||
userVolume += USER_STEPS;
|
||||
@@ -222,7 +221,7 @@ void loop()
|
||||
{
|
||||
for (int i = 0; i < userVolume; i++)
|
||||
{
|
||||
volumeDown();
|
||||
potDecrement();
|
||||
}
|
||||
|
||||
userVolume = 0;
|
||||
@@ -232,7 +231,7 @@ void loop()
|
||||
{
|
||||
for (int i = 0; i < USER_STEPS; i++)
|
||||
{
|
||||
volumeDown();
|
||||
potDecrement();
|
||||
}
|
||||
|
||||
userVolume -= USER_STEPS;
|
||||
@@ -241,35 +240,6 @@ void loop()
|
||||
}
|
||||
}
|
||||
|
||||
void volumeUp()
|
||||
{
|
||||
digitalWrite(9, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(10, LOW);
|
||||
delay(1);
|
||||
digitalWrite(9, LOW);
|
||||
delay(1);
|
||||
digitalWrite(9, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(10, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(9, LOW);
|
||||
digitalWrite(10, HIGH);
|
||||
}
|
||||
|
||||
void volumeDown()
|
||||
{
|
||||
digitalWrite(9, LOW);
|
||||
delay(1);
|
||||
digitalWrite(10, LOW);
|
||||
delay(1);
|
||||
digitalWrite(9, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(9, LOW);
|
||||
delay(1);
|
||||
digitalWrite(10, HIGH);
|
||||
}
|
||||
|
||||
bool debounceRead(int buttonPin)
|
||||
{
|
||||
int reading = digitalRead(buttonPin);
|
||||
|
||||
31
src/potControlls.cpp
Normal file
31
src/potControlls.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <Arduino.h>
|
||||
#include <potControlls.h>
|
||||
|
||||
void potIncrement()
|
||||
{
|
||||
digitalWrite(9, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(10, LOW);
|
||||
delay(1);
|
||||
digitalWrite(9, LOW);
|
||||
delay(1);
|
||||
digitalWrite(9, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(10, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(9, LOW);
|
||||
digitalWrite(10, HIGH);
|
||||
}
|
||||
|
||||
void potDecrement()
|
||||
{
|
||||
digitalWrite(9, LOW);
|
||||
delay(1);
|
||||
digitalWrite(10, LOW);
|
||||
delay(1);
|
||||
digitalWrite(9, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(9, LOW);
|
||||
delay(1);
|
||||
digitalWrite(10, HIGH);
|
||||
}
|
||||
Reference in New Issue
Block a user