mirror of
https://github.com/ShikyC/Taiko-Drum-Controller-Arduino.git
synced 2024-11-23 22:10:58 +01:00
Add delay mechanism back
This commit is contained in:
parent
0056f09789
commit
e085187f46
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
build/
|
build/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
.DS_Store
|
@ -1,10 +1,10 @@
|
|||||||
#define CHANNELS 4
|
#define CHANNELS 4
|
||||||
#define SAMPLE_CACHE_LENGTH 32 // Must be power of 2 (8, 16, etc.); See cache.h for implementation
|
#define SAMPLE_CACHE_LENGTH 16 // Must be power of 2 (8, 16, etc.); See cache.h for implementation
|
||||||
#define HIT_THRES 750 // The thresholds are also dependent on SAMPLE_CACHE_LENGTH, if you
|
#define HIT_THRES 750 // The thresholds are also dependent on SAMPLE_CACHE_LENGTH, if you
|
||||||
#define RESET_THRES 300 // changed SAMPLE_CACHE_LENGTH, you must also adjust thresholds
|
#define RESET_THRES 100 // changed SAMPLE_CACHE_LENGTH, you must also adjust thresholds
|
||||||
#define SAMPLING_PERIOD 1000 // Sampling period in microseconds (us), 1000us = 1ms = 0.001s
|
#define SAMPLING_PERIOD 500 // Sampling period in microseconds, 500us = 0.5ms = 2000Hz
|
||||||
|
|
||||||
#define DEBUG 1
|
#define DEBUG 0
|
||||||
|
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "keyboard.h"
|
#include "keyboard.h"
|
||||||
@ -16,9 +16,9 @@ unsigned long lastPower[CHANNELS];
|
|||||||
bool triggered;
|
bool triggered;
|
||||||
unsigned long triggeredTime[CHANNELS];
|
unsigned long triggeredTime[CHANNELS];
|
||||||
|
|
||||||
const byte inPins[] = {35, 34, 39, 36}; // L don, L kat, R don, R kat
|
const byte inPins[] = {36, 39, 34, 35}; // L don, L kat, R don, R kat
|
||||||
const byte outPins[] = {25, 26, 27, 14}; // LED visualization (optional)
|
const byte outPins[] = {25, 26, 27, 14}; // LED visualization (optional)
|
||||||
const char* outKeys[] = {"f", "d", "j", "k"}; // L don, L kat, R don, R kat
|
const char outKeys[] = {'f', 'd', 'j', 'k'}; // L don, L kat, R don, R kat
|
||||||
|
|
||||||
float sensitivity[] = {1.0, 1.0, 1.0, 1.0};
|
float sensitivity[] = {1.0, 1.0, 1.0, 1.0};
|
||||||
|
|
||||||
@ -36,12 +36,13 @@ void setup() {
|
|||||||
power[i] = 0;
|
power[i] = 0;
|
||||||
lastPower[i] = 0;
|
lastPower[i] = 0;
|
||||||
triggered = false;
|
triggered = false;
|
||||||
|
pinMode(inPins[i], INPUT);
|
||||||
pinMode(outPins[i], OUTPUT);
|
pinMode(outPins[i], OUTPUT);
|
||||||
}
|
}
|
||||||
lastTime = 0;
|
|
||||||
maxIndex = -1;
|
maxIndex = -1;
|
||||||
maxPower = 0;
|
maxPower = 0;
|
||||||
xTaskCreate(bluetoothTask, "bluetooth", 20000, NULL, 5, NULL);
|
xTaskCreate(bluetoothTask, "bluetooth", 20000, NULL, 5, NULL);
|
||||||
|
lastTime = micros();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@ -74,7 +75,7 @@ void loop() {
|
|||||||
digitalWrite(outPins[maxIndex], HIGH);
|
digitalWrite(outPins[maxIndex], HIGH);
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
if (isBleConnected) {
|
if (isBleConnected) {
|
||||||
typeText(outKeys[maxIndex]);
|
typeChar(outKeys[maxIndex]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -82,9 +83,9 @@ void loop() {
|
|||||||
Serial.print("\n");
|
Serial.print("\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// unsigned int frameTime = micros() - lastTime;
|
unsigned int frameTime = micros() - lastTime;
|
||||||
// lastTime = micros();
|
if (frameTime < SAMPLING_PERIOD) {
|
||||||
// if (frameTime < SAMPLING_PERIOD) {
|
delayMicroseconds(SAMPLING_PERIOD - frameTime);
|
||||||
// delayMicroseconds(SAMPLING_PERIOD - frameTime);
|
}
|
||||||
// }
|
lastTime = micros();
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
// Bluetooth keyboard implemetation by manuelbl:
|
// Bluetooth keyboard implemetation by manuelbl:
|
||||||
// https://gist.github.com/manuelbl/66f059effc8a7be148adb1f104666467
|
// https://gist.github.com/manuelbl/66f059effc8a7be148adb1f104666467
|
||||||
|
|
||||||
@ -216,4 +215,18 @@ void typeText(const char* text) {
|
|||||||
|
|
||||||
delay(5);
|
delay(5);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void typeChar(char c) {
|
||||||
|
uint8_t val = (uint8_t)c;
|
||||||
|
KEYMAP map = keymap[val];
|
||||||
|
InputReport report = {.modifiers = map.modifier,
|
||||||
|
.reserved = 0,
|
||||||
|
.pressedKeys = {map.usage, 0, 0, 0, 0, 0}};
|
||||||
|
input->setValue((uint8_t*)&report, sizeof(report));
|
||||||
|
input->notify();
|
||||||
|
delay(1);
|
||||||
|
input->setValue((uint8_t*)&NO_KEY_PRESSED, sizeof(NO_KEY_PRESSED));
|
||||||
|
input->notify();
|
||||||
|
delay(1);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user