refactor: put pad reading logic into dedicated file
This commit is contained in:
parent
8c3b5a0134
commit
fc4aa72d5f
40
src/input/pad_reader.cpp
Normal file
40
src/input/pad_reader.cpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include <audio/tone_generator.hpp>
|
||||||
|
|
||||||
|
#ifndef ANALOG_INPUT_PIN
|
||||||
|
#define ANALOG_INPUT_PIN A0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace PadReader
|
||||||
|
{
|
||||||
|
void handlePadInputs(void *pvParameters);
|
||||||
|
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
pinMode(ANALOG_INPUT_PIN, INPUT);
|
||||||
|
|
||||||
|
xTaskCreate(handlePadInputs, "handlePadInputs", 2048, NULL, 1, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void handlePadInputs(void *pvParameters)
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
int max = 0;
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
int value = analogRead(ANALOG_INPUT_PIN);
|
||||||
|
if (!ToneGenerator::isToneOn() && value > 0)
|
||||||
|
{
|
||||||
|
ToneGenerator::setToneOn(true);
|
||||||
|
}
|
||||||
|
if (value > max)
|
||||||
|
{
|
||||||
|
max = value;
|
||||||
|
}
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
8
src/input/pad_reader.hpp
Normal file
8
src/input/pad_reader.hpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#ifndef DRUMZ_INPUT_PAD_READER_HPP
|
||||||
|
#define DRUMZ_INPUT_PAD_READER_HPP
|
||||||
|
|
||||||
|
namespace PadReader {
|
||||||
|
void init();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DRUMZ_INPUT_PAD_READER_HPP
|
||||||
40
src/main.cpp
40
src/main.cpp
@ -3,30 +3,26 @@
|
|||||||
#define SCREEN_WIDTH 320
|
#define SCREEN_WIDTH 320
|
||||||
#define SCREEN_HEIGHT 240
|
#define SCREEN_HEIGHT 240
|
||||||
|
|
||||||
#define ENCODER_BUTTON_PIN = 14;
|
#define ENCODER_BUTTON_PIN 14;
|
||||||
#define ENCODER_A_PIN = 12;
|
#define ENCODER_A_PIN 12;
|
||||||
#define ENCODER_B_PIN = 13;
|
#define ENCODER_B_PIN 13;
|
||||||
|
|
||||||
#define ANALOG_OUTPUT_PIN = 25;
|
#define ANALOG_OUTPUT_PIN 25;
|
||||||
|
#define ANALOG_INPUT_PIN 34;
|
||||||
|
|
||||||
#include <ui/display.hpp>
|
#include <ui/display.hpp>
|
||||||
#include <input/encoder.hpp>
|
#include <input/encoder.hpp>
|
||||||
|
#include <input/pad_reader.hpp>
|
||||||
#include <audio/tone_generator.hpp>
|
#include <audio/tone_generator.hpp>
|
||||||
|
|
||||||
const int ONBOARD_LED_PIN = 2;
|
const int ONBOARD_LED_PIN = 2;
|
||||||
const int ANALOG_INPUT_PIN = 34;
|
|
||||||
|
|
||||||
void handle_pad_inputs(void *pvParameters);
|
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
pinMode(ONBOARD_LED_PIN, OUTPUT);
|
pinMode(ONBOARD_LED_PIN, OUTPUT);
|
||||||
pinMode(ANALOG_INPUT_PIN, INPUT);
|
|
||||||
|
|
||||||
|
|
||||||
xTaskCreate(handle_pad_inputs, "handle_pad_inputs", 2048, NULL, 1, NULL);
|
|
||||||
|
|
||||||
|
PadReader::init();
|
||||||
Encoder::init();
|
Encoder::init();
|
||||||
Display::init();
|
Display::init();
|
||||||
|
|
||||||
@ -39,25 +35,3 @@ void loop()
|
|||||||
Display::update();
|
Display::update();
|
||||||
delay(5);
|
delay(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_pad_inputs(void *pvParameters)
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
int max = 0;
|
|
||||||
for (int i = 0; i < 100; i++)
|
|
||||||
{
|
|
||||||
int value = analogRead(ANALOG_INPUT_PIN);
|
|
||||||
if (!ToneGenerator::isToneOn() && value > 0)
|
|
||||||
{
|
|
||||||
ToneGenerator::setToneOn(true);
|
|
||||||
}
|
|
||||||
if (value > max)
|
|
||||||
{
|
|
||||||
max = value;
|
|
||||||
}
|
|
||||||
delay(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user