c_cpp Dilicktal_MIDI v1_0
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp Dilicktal_MIDI v1_0相关的知识,希望对你有一定的参考价值。
//****************************************************************//
// Dilicktal_MIDI v1_0 //
// //
// This sketch shows how to use Dilicktal platinum //
// To send MIDI messages with buttons and display the //
// State of the button on the corresponding LED. //
// //
// The buttons are in TOGGLE mode, which means that when the //
// First pressure is sent to MIDI ON (127) and the button //
// Remains ON until the second button press. //
// //
// The SHIFTOUT SHIFTIN and functions used in this sketch //
// Tutorials are available on the Arduino website //
// Http://www.arduino.cc/en/Tutorial/ShiftIn //
// Http://arduino.cc/en/Tutorial/ShiftOut //
//****************************************************************//
// Number of connected Dilicktal board (1 to 8)
#define numDigital 8
// Set PINs of 4021
#define latchPinIn 10
#define dataPinIn 11
#define clockPinIn 9
// Set PINs on 74hc595
#define latchPinOut 12
#define clockPinOut 9
#define dataPinOut 13
byte preBoutonRead[numDigital] = {
0};// the value of flag EVERY buttons
byte led[numDigital] = {
0};// send value EVERY turntables Dilicktal
byte stateBouton[numDigital] = {
0};// state of EVERY buttons
boolean stateLed[numDigital][8]={
0};// EVERY status leds
byte boutonCC[]={
20,28,36,44,52,60,68,76};// Control number changes to EVERY Dilicktal
// The value 20 corresponds to the first stage connected Dilicktal
// This is to say that the first plate of buttons have the CC values of 20 to 27
// The value 28 corresponds to the second connected Dilicktal platinum ...
void setup() {
// Serial baud rate to 57600 to use with USB and 31250 for use in MIDI
Serial.begin(31250);
//define pin modes
pinMode(latchPinIn, OUTPUT);
pinMode(clockPinIn, OUTPUT);
pinMode(dataPinIn, INPUT);
pinMode(latchPinOut, OUTPUT);
SendToLed (255,255,255,255,255,255,255,255);
delay (1000);
SendToLed (0,0,0,0,0,0,0,0);
}
void loop() {
for (int y=0; y<numDigital; y++){
// loop as many times as the number of connected Dilicktal
preBoutonRead[y] = BoutonRead(y);
// Get the current value of the byte buttons corresponding to the plate Dilicktal
if (stateBouton[y] != preBoutonRead[y]){
// Does the buttons byte value has changed?
stateBouton[y] = preBoutonRead[y];
// Stock the value of the changed byte
for (int x =0; x <8; x++){
//scan the 8 bits of byte
if (bitRead (preBoutonRead[y], x)){
//EVERY test buttons
if (stateLed[y][x]==0){
//if the corresponding LED on the button is set to 0
bitSet (led[y],x);
// they put 1
stateLed[y][x]=1;
// it updates the state of the led
sendCC ((x+boutonCC[y]),127);
// It sends the message MIDI Control Change "ON" corresponding to the selected channel
}
else{
// but if the corresponding LED on the button is 1
bitWrite (led[y],x,0);
// It puts 0
stateLed[y][x]=0;
// We update the state of the led
sendCC ((x+boutonCC[y]),0);
// It sends the message MIDI Control Change "OFF" corresponding to the selected channel
}
}
}
SendToLed (led[0],led[1],led[2],led[3],led[4],led[5],led[6],led[7]);
//Envoie des 8 octets correspondant aux leds
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////FUNCTION//////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
void SendToLed (byte data1,byte data2,byte data3,byte data4,byte data5,byte data6,byte data7,byte data8) {
digitalWrite(latchPinOut, 0);
delayMicroseconds(20);
shiftOut(dataPinOut, clockPinOut, data8);
shiftOut(dataPinOut, clockPinOut, data7);
shiftOut(dataPinOut, clockPinOut, data6);
shiftOut(dataPinOut, clockPinOut, data5);
shiftOut(dataPinOut, clockPinOut, data4);
shiftOut(dataPinOut, clockPinOut, data3);
shiftOut(dataPinOut, clockPinOut, data2);
shiftOut(dataPinOut, clockPinOut, data1);
digitalWrite(latchPinOut, 1);
}
byte BoutonRead (int flag) {
if (flag ==0){
int i;
digitalWrite(latchPinIn,1);
delayMicroseconds(20);
digitalWrite(latchPinIn,0);
i = shiftIn(dataPinIn, clockPinIn);
return i;
}
if (flag ==1){
int i;
digitalWrite(latchPinIn,1);
delayMicroseconds(20);
digitalWrite(latchPinIn,0);
shiftIn(dataPinIn, clockPinIn);
i = shiftIn(dataPinIn, clockPinIn);
return i;
}
if (flag ==2){
int i;
digitalWrite(latchPinIn,1);
delayMicroseconds(20);
digitalWrite(latchPinIn,0);
shiftIn(dataPinIn, clockPinIn);
shiftIn(dataPinIn, clockPinIn);
i = shiftIn(dataPinIn, clockPinIn);
return i;
}
if (flag ==3){
int i;
digitalWrite(latchPinIn,1);
delayMicroseconds(20);
digitalWrite(latchPinIn,0);
shiftIn(dataPinIn, clockPinIn);
shiftIn(dataPinIn, clockPinIn);
shiftIn(dataPinIn, clockPinIn);
i = shiftIn(dataPinIn, clockPinIn); // We stock the two bytes in a variable
return i;
}
if (flag ==4){
int i;
digitalWrite(latchPinIn,1); // It puts in play mode 4021
delayMicroseconds(20);
digitalWrite(latchPinIn,0);
shiftIn(dataPinIn, clockPinIn);
shiftIn(dataPinIn, clockPinIn);
shiftIn(dataPinIn, clockPinIn);
shiftIn(dataPinIn, clockPinIn);
i = shiftIn(dataPinIn, clockPinIn);
return i;
}
if (flag ==5){
int i;
digitalWrite(latchPinIn,1);
delayMicroseconds(20);
digitalWrite(latchPinIn,0);
shiftIn(dataPinIn, clockPinIn);
shiftIn(dataPinIn, clockPinIn);
shiftIn(dataPinIn, clockPinIn);
shiftIn(dataPinIn, clockPinIn);
shiftIn(dataPinIn, clockPinIn);
i = shiftIn(dataPinIn, clockPinIn);
return i;
}
if (flag ==6){
int i;
digitalWrite(latchPinIn,1);
delayMicroseconds(20);
digitalWrite(latchPinIn,0);
shiftIn(dataPinIn, clockPinIn);
shiftIn(dataPinIn, clockPinIn);
shiftIn(dataPinIn, clockPinIn);
shiftIn(dataPinIn, clockPinIn);
shiftIn(dataPinIn, clockPinIn);
shiftIn(dataPinIn, clockPinIn);
i = shiftIn(dataPinIn, clockPinIn);
return i;
}
if (flag ==7){
int i;
digitalWrite(latchPinIn,1);
delayMicroseconds(20);
digitalWrite(latchPinIn,0);
shiftIn(dataPinIn, clockPinIn);
shiftIn(dataPinIn, clockPinIn);
shiftIn(dataPinIn, clockPinIn);
shiftIn(dataPinIn, clockPinIn);
shiftIn(dataPinIn, clockPinIn);
shiftIn(dataPinIn, clockPinIn);
shiftIn(dataPinIn, clockPinIn);
i = shiftIn(dataPinIn, clockPinIn);
return i;
}
}
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
digitalWrite(myDataPin, pinState);
digitalWrite(myClockPin, 1);
digitalWrite(myDataPin, 0);
}
}
byte shiftIn(int myDataPin, int myClockPin) {
int i;
int temp = 0;
int pinState;
byte myDataIn = 0;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, INPUT);
for (i=7; i>=0; i--)
{
digitalWrite(myClockPin, 0);
delayMicroseconds(2);
temp = digitalRead(myDataPin);
if (temp) {
pinState = 1;
myDataIn = myDataIn | (1 << i);
}
else {
pinState = 0;
}
digitalWrite(myClockPin, 1);
}
return myDataIn;
}
void sendCC (int CCnum, int value)
{
Serial.write (0xB0); // Message " control change " on MIDI channel 1
Serial.write (CCnum);
Serial.write (value);
}
以上是关于c_cpp Dilicktal_MIDI v1_0的主要内容,如果未能解决你的问题,请参考以下文章
c_cpp 使用PCLVisualizer和Kinect v1 Grabber绘制点云
c_cpp 使用不带Grabber的Point Cloud Library绘制从Kinect v1检索到的Point Cloud
c_cpp 使用KinectGrabber / Kinect2Grabber从Kinect v1 / v2传感器检索的pcl :: PointCloud <pcl :: PointXYZRGBA