starting final code : Keyboard class
This commit is contained in:
Binary file not shown.
Binary file not shown.
+511
-484
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1 @@
|
|||||||
<<<<<<< HEAD
|
|
||||||
5b5b88025335f306e0a3618fe34989e446b2df4b
|
5b5b88025335f306e0a3618fe34989e446b2df4b
|
||||||
=======
|
|
||||||
c10474de9f98698a47fa86c8fcae8d408ed852d7
|
|
||||||
>>>>>>> a60abe1c71fdccfddb532c4d4cf5d21b381f314a
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef _KEYBOARD_H_
|
||||||
|
#define _KEYBOARD_H_
|
||||||
|
|
||||||
|
class Keyboard {
|
||||||
|
public:
|
||||||
|
Keyboard();
|
||||||
|
~Keyboard();
|
||||||
|
|
||||||
|
int getKey();
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
+22
-12
@@ -1,28 +1,38 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
// #include <Multiplexer.h>
|
|
||||||
#include <MIDI_Controller.h>
|
#include <MIDI_Controller.h>
|
||||||
|
|
||||||
#define s * 1000
|
#define s * 1000
|
||||||
#define TOTAL_LINES 4
|
|
||||||
|
|
||||||
/* Pins */
|
/* Pins */
|
||||||
/* - analogs */
|
/* GPIO (I2C) */
|
||||||
unsigned char muxSignal{A1};
|
const unsigned char gpio_int{0};
|
||||||
/* - digitals */
|
const unsigned char sda{2};
|
||||||
int muxSelector[TOTAL_LINES]{18, 14, 15, 16};
|
const unsigned char scl{3};
|
||||||
|
/* Multiplexer */
|
||||||
|
#define MUX_ADDRSIZE 5
|
||||||
|
const unsigned char mux_sig{A10};
|
||||||
|
const unsigned char mux_addr[MUX_ADDRSIZE]{15, 21, 20, 19, 18};
|
||||||
|
/* ShiftRegister (OUT) */
|
||||||
|
#define SHIFT_OUTPUTSIZE 4
|
||||||
|
const unsigned char shift_data{14};
|
||||||
|
const unsigned char shift_latch{16};
|
||||||
|
const unsigned char shift_clock{1};
|
||||||
|
/* keyboard (IN) */
|
||||||
|
#define KEYBOARD_SIZE 6
|
||||||
|
const unsigned char keyboard[KEYBOARD_SIZE]{4, 5, 6, 7, 8, 9};
|
||||||
|
|
||||||
/* Components */
|
/* Components */
|
||||||
// Multiplexer m(muxSignal, TOTAL_LINES, muxSelector);
|
/* GPIO (I2C) */
|
||||||
AnalogMultiplex multiplexer(A1, {18, 14, 15, 16});
|
/* Multiplexer */
|
||||||
|
AnalogMultiplex multiplexer(mux_sig, mux_addr);
|
||||||
|
/* ShiftRegister (OUT) */
|
||||||
|
ShiftRegisterOut shiftRegister(shift_data, shift_clock, shift_latch, MSBFIRST, SHIFT_OUTPUTSIZE);
|
||||||
|
/* keyboard (IN) */
|
||||||
|
|
||||||
/* Midi links */
|
/* Midi links */
|
||||||
//USBDebugMIDI_Interface midiInterface(115200);
|
//USBDebugMIDI_Interface midiInterface(115200);
|
||||||
|
|
||||||
Analog potentiometers[] = {
|
Analog potentiometers[] = {
|
||||||
{multiplexer.pin(0), MIDI_CC::Channel_Volume, 1},
|
|
||||||
{multiplexer.pin(1), MIDI_CC::Channel_Volume, 2},
|
|
||||||
{multiplexer.pin(2), MIDI_CC::Channel_Volume, 3},
|
|
||||||
{multiplexer.pin(3), MIDI_CC::Channel_Volume, 4},
|
|
||||||
{multiplexer.pin(4), MIDI_CC::Channel_Volume, 5},
|
{multiplexer.pin(4), MIDI_CC::Channel_Volume, 5},
|
||||||
{multiplexer.pin(5), MIDI_CC::Channel_Volume, 6},
|
{multiplexer.pin(5), MIDI_CC::Channel_Volume, 6},
|
||||||
{multiplexer.pin(6), MIDI_CC::Channel_Volume, 7},
|
{multiplexer.pin(6), MIDI_CC::Channel_Volume, 7},
|
||||||
|
|||||||
@@ -0,0 +1,182 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
// #include <Multiplexer.h>
|
||||||
|
#include <MIDI_Controller.h>
|
||||||
|
|
||||||
|
#define s * 1000
|
||||||
|
#define TOTAL_LINES 4
|
||||||
|
|
||||||
|
/* Pins */
|
||||||
|
/* - analogs */
|
||||||
|
unsigned char muxSignal{A1};
|
||||||
|
/* - digitals */
|
||||||
|
int muxSelector[TOTAL_LINES]{18, 14, 15, 16};
|
||||||
|
|
||||||
|
/* Components */
|
||||||
|
// Multiplexer m(muxSignal, TOTAL_LINES, muxSelector);
|
||||||
|
AnalogMultiplex multiplexer(A1, {18, 14, 15, 16});
|
||||||
|
|
||||||
|
/* Midi links */
|
||||||
|
//USBDebugMIDI_Interface midiInterface(115200);
|
||||||
|
|
||||||
|
Analog potentiometers[] = {
|
||||||
|
{multiplexer.pin(0), MIDI_CC::Channel_Volume, 1},
|
||||||
|
{multiplexer.pin(1), MIDI_CC::Channel_Volume, 2},
|
||||||
|
{multiplexer.pin(2), MIDI_CC::Channel_Volume, 3},
|
||||||
|
{multiplexer.pin(3), MIDI_CC::Channel_Volume, 4},
|
||||||
|
{multiplexer.pin(4), MIDI_CC::Channel_Volume, 5},
|
||||||
|
{multiplexer.pin(5), MIDI_CC::Channel_Volume, 6},
|
||||||
|
{multiplexer.pin(6), MIDI_CC::Channel_Volume, 7},
|
||||||
|
{multiplexer.pin(7), MIDI_CC::Channel_Volume, 8}
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Values */
|
||||||
|
int val[16];
|
||||||
|
int ref[16];
|
||||||
|
|
||||||
|
uint8_t readCapacitivePin(int pinToMeasure);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
while (Serial.available() == 0){
|
||||||
|
delay(.5 s);
|
||||||
|
}
|
||||||
|
// for (size_t i = 0; i < 4; i++) {
|
||||||
|
// ref[i] = multiplexer.analogRead(i);
|
||||||
|
// }
|
||||||
|
ref[8] = readCapacitivePin(2);
|
||||||
|
pinMode(0, OUTPUT);
|
||||||
|
pinMode(1, OUTPUT);
|
||||||
|
pinMode(9, OUTPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
long loopAverage = 0;
|
||||||
|
long lastLoop = 0;
|
||||||
|
bool on = false;
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// long start = millis();
|
||||||
|
// for (size_t i = 0; i < 4; i++) {
|
||||||
|
// val[i] = multiplexer.analogRead(i);
|
||||||
|
// if (val[i] != ref[i]) {
|
||||||
|
// Serial.print("p[");
|
||||||
|
// Serial.print(i, DEC);
|
||||||
|
// Serial.print("] = ");
|
||||||
|
// Serial.println(val[i], DEC);
|
||||||
|
// ref[i] = val[i];
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
val[8] = readCapacitivePin(2);
|
||||||
|
if (abs(val[8] - ref[8]) >= 2) {
|
||||||
|
if (val[8] > ref[8]) {
|
||||||
|
// Serial.print("loop() time : ");
|
||||||
|
// Serial.println(lastLoop, DEC);
|
||||||
|
// Serial.print("average : ");
|
||||||
|
// Serial.println(loopAverage, DEC);
|
||||||
|
Serial.println(val[8], DEC);
|
||||||
|
}
|
||||||
|
ref[8] = val[8];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// if (val[0] >= 500) {
|
||||||
|
// digitalWrite(0, HIGH);
|
||||||
|
// } else {
|
||||||
|
// digitalWrite(0, LOW);
|
||||||
|
// }
|
||||||
|
if (val[2] >= 500) {
|
||||||
|
digitalWrite(1, HIGH);
|
||||||
|
} else {
|
||||||
|
digitalWrite(1, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
analogWrite(9, val[0] * 256 / 1024);
|
||||||
|
|
||||||
|
MIDI_Controller.refresh();
|
||||||
|
// lastLoop = millis() - start;
|
||||||
|
// loopAverage = (loopAverage + lastLoop) / 2;
|
||||||
|
//delay(.5 s);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t readCapacitivePin(int pinToMeasure) {
|
||||||
|
// Variables used to translate from Arduino to AVR pin naming
|
||||||
|
volatile uint8_t* port;
|
||||||
|
volatile uint8_t* ddr;
|
||||||
|
volatile uint8_t* pin;
|
||||||
|
|
||||||
|
// Here we translate the input pin number from
|
||||||
|
// Arduino pin number to the AVR PORT, PIN, DDR,
|
||||||
|
// and which bit of those registers we care about.
|
||||||
|
|
||||||
|
byte bitmask;
|
||||||
|
port = portOutputRegister(digitalPinToPort(pinToMeasure));
|
||||||
|
ddr = portModeRegister(digitalPinToPort(pinToMeasure));
|
||||||
|
bitmask = digitalPinToBitMask(pinToMeasure);
|
||||||
|
pin = portInputRegister(digitalPinToPort(pinToMeasure));
|
||||||
|
|
||||||
|
// Discharge the pin first by setting it low and output
|
||||||
|
*port &= ~(bitmask);
|
||||||
|
*ddr |= bitmask;
|
||||||
|
delay(1);
|
||||||
|
uint8_t SREG_old = SREG; //back up the AVR Status Register
|
||||||
|
// Prevent the timer IRQ from disturbing our measurement
|
||||||
|
noInterrupts();
|
||||||
|
|
||||||
|
// Make the pin an input with the internal pull-up on
|
||||||
|
*ddr &= ~(bitmask);
|
||||||
|
*port |= bitmask;
|
||||||
|
|
||||||
|
// Now see how long the pin to get pulled up. This manual unrolling of the loop
|
||||||
|
// decreases the number of hardware cycles between each read of the pin,
|
||||||
|
// thus increasing sensitivity.
|
||||||
|
uint8_t cycles = 17;
|
||||||
|
|
||||||
|
if (*pin & bitmask) {
|
||||||
|
cycles = 0;
|
||||||
|
} else if (*pin & bitmask) {
|
||||||
|
cycles = 1;
|
||||||
|
} else if (*pin & bitmask) {
|
||||||
|
cycles = 2;
|
||||||
|
} else if (*pin & bitmask) {
|
||||||
|
cycles = 3;
|
||||||
|
} else if (*pin & bitmask) {
|
||||||
|
cycles = 4;
|
||||||
|
} else if (*pin & bitmask) {
|
||||||
|
cycles = 5;
|
||||||
|
} else if (*pin & bitmask) {
|
||||||
|
cycles = 6;
|
||||||
|
} else if (*pin & bitmask) {
|
||||||
|
cycles = 7;
|
||||||
|
} else if (*pin & bitmask) {
|
||||||
|
cycles = 8;
|
||||||
|
} else if (*pin & bitmask) {
|
||||||
|
cycles = 9;
|
||||||
|
} else if (*pin & bitmask) {
|
||||||
|
cycles = 10;
|
||||||
|
} else if (*pin & bitmask) {
|
||||||
|
cycles = 11;
|
||||||
|
} else if (*pin & bitmask) {
|
||||||
|
cycles = 12;
|
||||||
|
} else if (*pin & bitmask) {
|
||||||
|
cycles = 13;
|
||||||
|
} else if (*pin & bitmask) {
|
||||||
|
cycles = 14;
|
||||||
|
} else if (*pin & bitmask) {
|
||||||
|
cycles = 15;
|
||||||
|
} else if (*pin & bitmask) {
|
||||||
|
cycles = 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
// End of timing-critical section; turn interrupts back on if they were on before, or leave them off if they were off before
|
||||||
|
SREG = SREG_old;
|
||||||
|
|
||||||
|
// Discharge the pin again by setting it low and output
|
||||||
|
// It's important to leave the pins low if you want to
|
||||||
|
// be able to touch more than 1 sensor at a time - if
|
||||||
|
// the sensor is left pulled high, when you touch
|
||||||
|
// two sensors, your body will transfer the charge between
|
||||||
|
// sensors.
|
||||||
|
*port &= ~(bitmask);
|
||||||
|
*ddr |= bitmask;
|
||||||
|
return cycles;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user