mirror of
https://github.com/erik-toth/audio-synth.git
synced 2025-12-06 11:20:02 +00:00
Software Upload 2
Firmware-Header ist fertig und kann nun zur Implementation zur DA verwendet werden. Anbei ist ein Beispiel der Verwendung!
This commit is contained in:
@@ -50,31 +50,31 @@ void Keyboard::begin()
|
||||
void Keyboard::update()
|
||||
{
|
||||
unsigned long now = millis();
|
||||
for(uint8_t i = 0; i < _nCols; i++)
|
||||
for(uint8_t col = 0; col < _nCols; col++)
|
||||
{
|
||||
digitalWrite(_pinsCol[i], HIGH);
|
||||
for(uint8_t j = 0; j < _nRows; ++j)
|
||||
digitalWrite(_pinsCol[col], HIGH);
|
||||
for(uint8_t row = 0; row < _nRows; ++row)
|
||||
{
|
||||
bool reading = (digitalRead(_pinsRow[j]) == HIGH);
|
||||
bool reading = (digitalRead(_pinsRow[row]) == HIGH);
|
||||
|
||||
if(reading != _keyStateLatest[i][j])
|
||||
if(reading != _keyStateLatest[row][col])
|
||||
{
|
||||
_keyStateLatest[i][j] = reading;
|
||||
_lastChangeTime[i][j] = now;
|
||||
_keyStateLatest[row][col] = reading;
|
||||
_lastChangeTime[row][col] = now;
|
||||
}
|
||||
|
||||
if((now - _lastChangeTime[i][j]) > MS_DEBOUNCE)
|
||||
if((now - _lastChangeTime[row][col]) > MS_DEBOUNCE)
|
||||
{
|
||||
if(reading != _keyState[i][j])
|
||||
if(reading != _keyState[row][col])
|
||||
{
|
||||
_keyState[i][j] = reading;
|
||||
_keyState[row][col] = reading;
|
||||
|
||||
if(reading) _addActiveKey(i, j);
|
||||
else _removeActiveKey(i, j);
|
||||
if(reading) _addActiveKey(row, col);
|
||||
else _removeActiveKey(row, col);
|
||||
}
|
||||
}
|
||||
}
|
||||
digitalWrite(_pinsCol[i], LOW);
|
||||
digitalWrite(_pinsCol[col], LOW);
|
||||
}
|
||||
if((_nActiveKeys == 1) && _inQueue(NOT_A_KEY)) _nActiveKeys = 0;
|
||||
}
|
||||
@@ -169,4 +169,67 @@ void Keyboard::_removeActiveKey(uint8_t row, uint8_t col)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @param dac Adafruit_MCP4728 object
|
||||
* @param wire TwoWire object
|
||||
* @param nCV Number of CV-Gates
|
||||
* @param cvChannelMap Maps CV-Gate-Index to a MCP4728 output-channel
|
||||
* @param keyToVoltage One dimensional array of size row times col
|
||||
* @param row Keyboard matrix rows
|
||||
* @param col Keyboard matrix cols
|
||||
*/
|
||||
CV::CV(Adafruit_MCP4728 *dac, TwoWire *wire, uint8_t nCV, MCP4728_channel_t *cvChannelMap, uint16_t *keyToVoltage, uint8_t row, uint8_t col)
|
||||
{
|
||||
_dac = dac;
|
||||
_wire = wire;
|
||||
_nCV = nCV;
|
||||
_row = row;
|
||||
_col = col;
|
||||
_keyToVoltage = keyToVoltage;
|
||||
|
||||
for(uint8_t i = 0; i < N_MAX_DAC_CH; i++)
|
||||
{
|
||||
_cvChannelMap[i] = i < _nCV ? cvChannelMap[i] : (MCP4728_channel_t)(0);
|
||||
}
|
||||
}
|
||||
|
||||
bool CV::begin(uint8_t pinSDA, uint8_t pinSCL)
|
||||
{
|
||||
if((_wire->begin(pinSDA, pinSCL) && _dac->begin(96U, _wire)))
|
||||
{
|
||||
clearAll();
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
void CV::setVoltage(uint8_t cvIndex, uint16_t mV)
|
||||
{
|
||||
if(cvIndex >= _nCV) return;
|
||||
MCP4728_channel_t ch = _cvChannelMap[cvIndex];
|
||||
_dac->setChannelValue(ch, map(mV, 0, 2048, 0, 4095), MCP4728_VREF_INTERNAL);
|
||||
}
|
||||
|
||||
void CV::setVoltage(uint8_t cvIndex, Key k)
|
||||
{
|
||||
if(cvIndex >= _nCV) return;
|
||||
if(isNotKey(k)) setVoltage(cvIndex, 0);
|
||||
setVoltage(cvIndex, _keyToVoltage[_getKeyToVoltageIndex(k)]);
|
||||
}
|
||||
|
||||
void CV::clearAll()
|
||||
{
|
||||
for(uint8_t i = 0; i < _nCV; i++) setVoltage(i, 0);
|
||||
}
|
||||
|
||||
uint8_t CV::_getKeyToVoltageIndex(uint8_t row, uint8_t col)
|
||||
{
|
||||
return (row*_col + col);
|
||||
}
|
||||
|
||||
uint8_t CV::_getKeyToVoltageIndex(Key k)
|
||||
{
|
||||
return (k.row*_col + k.col);
|
||||
}
|
||||
Reference in New Issue
Block a user