155 lines
4.4 KiB
C++
155 lines
4.4 KiB
C++
#include <Wire.h>
|
|
//#include <MIDI.h>
|
|
|
|
int CTS[7] = {A0, A1, A2, A3, A4, A5, A6};
|
|
int INT[7] = {50, 46, 44, 42, 40, 38, 34};
|
|
#define pad 0
|
|
#define blue 2
|
|
#define green 3
|
|
#define red 4
|
|
|
|
uint32_t time1;
|
|
boolean flag = true;
|
|
|
|
//// Settings for MIDI library v4.0 an upper
|
|
//struct MySettings : public midi::DefaultSettings{
|
|
// static const bool UseRunningStatus = false; // Messes with my old equipment!
|
|
//};
|
|
|
|
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial, MIDI, MySettings);
|
|
|
|
void slaveSend(uint8_t channel, uint8_t reg) {
|
|
Wire.beginTransmission(channel); //start transmission to device
|
|
Wire.write(reg); // write value to write
|
|
Wire.endTransmission(); //end transmission
|
|
}
|
|
|
|
void rgbPad(uint8_t channel, uint8_t r, uint8_t g, uint8_t b){
|
|
Wire.beginTransmission(channel); //start transmission to device
|
|
Wire.write(2); // write value to write
|
|
Wire.write(r); // write value to write
|
|
Wire.write(g); // write value to write
|
|
Wire.write(b); // write value to write
|
|
Wire.endTransmission(); //end transmission
|
|
}
|
|
|
|
|
|
void rgbDing(uint8_t r, uint8_t g, uint8_t b){
|
|
analogWrite(red, r);
|
|
analogWrite(green, g);
|
|
analogWrite(blue, b);
|
|
}
|
|
|
|
uint16_t Sensor[8][5] = {{0,0,0,0,0},
|
|
{0,0,0,0,0},
|
|
{0,0,0,0,0},
|
|
{0,0,0,0,0},
|
|
{0,0,0,0,0},
|
|
{0,0,0,0,0},
|
|
{0,0,0,0,0},
|
|
{0,0,0,0,0}};
|
|
|
|
void PadRead(int channel)
|
|
{
|
|
if (!digitalRead(INT[channel-1]))
|
|
{
|
|
unsigned long time_on = millis();
|
|
slaveSend(channel, 1);
|
|
delayMicroseconds(10);
|
|
Wire.requestFrom(channel, 10);
|
|
uint16_t temp_value = 0;
|
|
uint16_t count = 0;
|
|
while(Wire.available()) // slave may send less than requested
|
|
{
|
|
byte c = Wire.read(); // receive a byte as character
|
|
delay(10);
|
|
uint16_t b = Wire.read(); // receive a byte as character
|
|
uint16_t v = ((b<<8)&0xFF00) + c;
|
|
Sensor[channel-1][count] = v;
|
|
count++;
|
|
}
|
|
}
|
|
}
|
|
|
|
void allRead()
|
|
{
|
|
for (int i=1; i<7; i++)
|
|
{
|
|
PadRead(i);
|
|
}
|
|
}
|
|
|
|
void setup()
|
|
{
|
|
// Open serial communications and wait for port to open:
|
|
for (int i=0; i<7; i++) pinMode(CTS[i], OUTPUT);
|
|
for (int i=0; i<7; i++) digitalWrite(CTS[i], HIGH);
|
|
for (int i=0; i<7; i++) pinMode(INT[i], INPUT);
|
|
for (int i=0; i<7; i++) digitalWrite(INT[i], HIGH);
|
|
|
|
Wire.begin();
|
|
Wire.setClock(100000);
|
|
Serial.begin(57600);
|
|
// set the data rate for the SoftwareSerial port
|
|
Serial1.begin(57600);
|
|
time1 = millis();
|
|
pinMode(green, OUTPUT);
|
|
pinMode(blue, OUTPUT);
|
|
pinMode(red, OUTPUT);
|
|
rgbDing(0, 0, 0);
|
|
for (int i=0; i<7; i++) {rgbPad(i, 0, 0, 0);}
|
|
delay(100);
|
|
for (int i=0; i<7; i++) {rgbPad(i, 0, 255, 0); delay(200);}
|
|
rgbDing(0, 255, 0);
|
|
// MIDI.begin(4); // Launch MIDI and listen to channel 4
|
|
}
|
|
|
|
uint32_t time_refresh = 5;
|
|
void loop() // run over and over
|
|
{
|
|
// for (int i=0; i<7; i++) {rgbPad(i, 255, 0, 0); delay(time_refresh);}
|
|
// rgbDing(255, 0, 0);
|
|
// delay(time_refresh);
|
|
// for (int i=0; i<7; i++) {rgbPad(i, 0, 255, 0); delay(time_refresh);}
|
|
// rgbDing(0, 255, 0);
|
|
// delay(time_refresh);
|
|
// for (int i=0; i<7; i++) {rgbPad(i, 0, 0, 255); delay(time_refresh);}
|
|
// rgbDing(0, 0, 255);
|
|
// delay(time_refresh);
|
|
// for (int i=0; i<7; i++) {rgbPad(i, 255, 255, 0); delay(time_refresh);}
|
|
// rgbDing(255, 255, 0);
|
|
// delay(time_refresh);
|
|
// for (int i=0; i<7; i++) {rgbPad(i, 255, 255, 255); delay(time_refresh);}
|
|
// rgbDing(255, 255, 255);
|
|
// delay(time_refresh);
|
|
|
|
// allRead();
|
|
// if (!digitalRead(INT[0]))
|
|
{
|
|
allRead();
|
|
rgbPad(1, map(Sensor[0][4],0,1023,255,0),map(Sensor[0][4],0,1023,255,0),map(Sensor[0][4],0,1023,150,0));
|
|
// MIDI.sendNoteOn(42,map(Sensor[0][4],0,1023,127,0),1); // Send a Note (pitch 42, velo 127 on channel 1)
|
|
// Serial.write(42);
|
|
// Serial.write(map(Sensor[0][4],0,1023,127,0));
|
|
// Serial.write(1);
|
|
//// MIDI.sendNoteOff(42,0,1); // Stop the note
|
|
//
|
|
int i = 0;
|
|
// for (int i = 0; i<6; i++)
|
|
// {
|
|
Serial.print("PAD ");
|
|
Serial.print(i);
|
|
Serial.print(": ");
|
|
for (int j = 0; j<5; j++)
|
|
{
|
|
Serial.print(Sensor[i][j]*3300/1023.); // print the character
|
|
Serial.print(' ');
|
|
}
|
|
Serial.println();
|
|
}
|
|
|
|
delayMicroseconds(10);
|
|
// }
|
|
}
|
|
|