When I try to upload this is the error:
sketch_apr25b.ino:18:2: error: expected ',' or ';' before 'const'
sketch_apr25b.ino:27:22: error: 'HISTORY_BUFFER_LENGTH' was not declared in this scope
sketch_apr25b.ino: In function 'void setup()':
sketch_apr25b.ino:52:20: error: 'HISTORY_BUFFER_LENGTH' was not declared in this scope
sketch_apr25b.ino:54:9: error: 's_history' was not declared in this scope
sketch_apr25b.ino: In function 'void loop()':
sketch_apr25b.ino:127:20: error: 'HISTORY_BUFFER_LENGTH' was not declared in this scope
sketch_apr25b.ino:129:12: error: 's_history' was not declared in this scope
sketch_apr25b.ino:133:13: error: 's_history' was not declared in this scope
sketch_apr25b.ino:133:57: error: 'HISTORY_BUFFER_LENGTH' was not declared in this scope
Errore durante la compilazione
The code is:
/*
MIDI On/Off Messages
By Amanda Ghassaei
July 2012
http://www.instructables.com/id/Send-and-Receive-MIDI-with-Arduino/
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*/
int noteOFF = 128;//128 note off on midi command
const int analogInPin = A0;
const int analogInPin2 = A1;//pin del potenziometro 1
const int POT_THRESHOLD = 3;
const int POT_THRESHOLD2 = 3// in +
const int HISTORY_BUFFER_LENGTH = 6;// in +
int velocity = 0;
int velocity2 = 0;//velocity of MIDI notes, must be between 0 and 127
//higher velocity usually makes MIDI instruments louder
int sensorValue = 0;
int ControlChange = 176;
int ControlChange2 =180; //176 = in binary, controlchange command
int NoteOn =145;
//int noteOFF = 128;//128 = 10000000 in binary, note off command
static int s_history[HISTORY_BUFFER_LENGTH];// in +
//BUTTONS
int buttonState1;
int val1;
int buttonState2;
int val2;
int buttonState3;
int val3;
int led = 13; // the pin that the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5;//led
//TIMER
long previousMillis = 0;
long interval = 50;
void setup() {
// Set MIDI baud rate:
Serial.begin(57600);
// Initialize he buffer
for(int i=0; i<HISTORY_BUFFER_LENGTH; i++)// in +
{// in +
s_history[i] = -1;// in +
}// in +
//BUTTON
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(led, OUTPUT);//led
buttonState1 = digitalRead(2);//HIGH
buttonState2 = digitalRead(3); //HIGH
buttonState3 = digitalRead(4); //HIGH
}
void loop() {
val1 =digitalRead(2);
if(val1 != buttonState1){
if (val1 ==LOW) {
//Send an ASCII 'A',
MIDImessage(145, 60 ,100);
}
else{MIDImessage(129,60,0);}}
val2 = digitalRead(3);
if (val2 != buttonState2){
if (val2 ==LOW){
MIDImessage(146, 61,100);
}
else{MIDImessage(130, 61,0);}
}
val3 = digitalRead(4);
if (val3 != buttonState3){
if (val3 == LOW){
MIDImessage(147, 62,100);
}
else{MIDImessage(131, 62,0);}
}
unsigned long currentMillis = millis();//delay(50);
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
buttonState1 = val1;
buttonState2 = val2;
buttonState3 = val3;
}
static int s_nLastPotValue = 0; //in +
static int s_nLastMappedValue = 0;//in +
int nCurrentPotValue = analogRead(A0);//in +
if(abs(nCurrentPotValue - s_nLastPotValue) < POT_THRESHOLD)//in +
return;//in +
s_nLastPotValue = nCurrentPotValue;//in +
int nMappedValue = map(nCurrentPotValue, 0, 1023, 0, 255); //in + // Map the value to 0-255
if(nMappedValue == s_nLastMappedValue)//in +
return;//in +
for(int i=0; i<HISTORY_BUFFER_LENGTH; i++)//in +
{//in +
if(s_history[i] == nMappedValue)//in +
return;//in +
}//in +
memcpy(&s_history[0], &s_history[1], sizeof(int) * (HISTORY_BUFFER_LENGTH - 1));//in +
s_history[HISTORY_BUFFER_LENGTH - 1] = nMappedValue;//in +
s_nLastMappedValue = nMappedValue;//in +
// sensorValue = analogRead (analogInPin);
velocity = map (nCurrentPotValue, 0, 1023, 0, 127);
MIDImessage(176, 50, velocity);//turn note on
delay(20);
//POT2
static int s_nLastPotValue2 = 0; //in +
static int s_nLastMappedValue2 = 0;//in +
int nCurrentPotValue2 = analogRead(A1);//in +
if(abs(nCurrentPotValue2 - s_nLastPotValue2) < POT_THRESHOLD2)//in +
return;//in +
s_nLastPotValue2 = nCurrentPotValue2;//in +
int nMappedValue2 = map(nCurrentPotValue, 0, 1023, 0, 255); //in + // Map the value to 0-255
if(nMappedValue2 == s_nLastMappedValue2)//in +
return;//in +
s_nLastMappedValue2 = nMappedValue2;//in +
// sensorValue = analogRead (analogInPin);
velocity2 = map (nCurrentPotValue2, 0, 1023, 0, 127);
MIDImessage(180, 51, velocity2);//turn note on
delay(20);
blinkLed();
}
//send MIDI message
void MIDImessage(int command, int MIDInote, int MIDIvelocity) {
Serial.write(command);//send note on or note off command
Serial.write(MIDInote);//send pitch data
Serial.write(MIDIvelocity);//send velocity data
}
void blinkLed(){ //led function
analogWrite(led, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 170) {
fadeAmount = -fadeAmount ;
}
// wait for 30 milliseconds to see the dimming effect
delay(10);
}
I think I've to create something like this... but for only 2 pots and not 6:
//#include <MIDI.h>
#include <usbDevices.h>
#define numPots 6 // numer of pots
#define b 1 // this is the delta needed in
unsigned int currentPot[6] = {0,0,0,0,0,0};
unsigned int pot[6] = {0,0,0,0,0,0};
byte controlChange = 0xBC; //0xB0 or 176
void setup() {
usb.init(midi);
// MIDI.begin();
//Serial.begin(31250);
}
void loop() {
for(unsigned char i=0; i<numPots; i++) {
currentPot[i] = analogRead(i) / 8;
if(abs(currentPot[i]-pot[i]) > b) {
sendMidi(controlChange, i+1, currentPot[i]);
pot[i] = currentPot[i];
}
}
}
void sendMidi(byte controlChange, unsigned int controlNum, int val) {
//MIDI.sendControlChange(controlNum, val);
Serial.write(controlChange);
Serial.write(controlNum);
Serial.write(val);
// Serial.write(unsigned char(controlChange));
// Serial.write(unsigned char(controlNum));
// Serial.write(unsigned char(val));
}