Arama butonu
Bu konudaki kullanıcılar: 1 misafir
0
Cevap
1646
Tıklama
0
Öne Çıkarma
'was not declared in this scope' hatası
B
7 yıl
Teğmen
Konu Sahibi

Merhaba, bir Midi klavye projesi üstündeyim. Acemi olduğum için bazı şeylere çözüm bulamıyorum. Bir blogdan bulduğum kodda hatalar var.
Öncelikle #include expects "FILENAME" or <FILENAME> hatası aldım. Bunu biraz araştırıp include <wire.h> tanımladığımda düzeldi fakat ikinci include un ne için yazıldığını çözemedim.
İkinciyi sildiğimde ise 'lt' was not declared in this scope. hatasını çözemedim. Sırf denemek için lt ye değer verdiğimde ise if(octave &lt; 4) satırında expected ')' before ';' token şeklinde bi hata aldım. Yardımcı olursanız çok sevinirim.
Kod şu şekilde;


// MultiButtonMIDIOctave.ino
// Driving MIDI using a Multiple Buttons
// Added variables for Octave, Transpose and Velocity
// Rob Ives 2012
// This code is released into the Public Domain.

#include
#include

int keyispressed[16]; //Is the key currently pressed?
int noteisplaying[16]; //Is the Note currently playing?
unsigned char data1; //data from chip 1
unsigned char data2; //data from chip 2
int octave = 2; //set currently played octave
int transpose = 0; //transpose notes on the board
int velocity = 127; //set note velocity
//--- Octave LED output pins
int octave1 = 8;
int octave2 = 9;
int octave3 = 10;
int octave4 = 11;
//--- Octave Switches
int octaveup = 7;
int octavedown = 6;
//--- Pot
int potpin = 2;

void setup() //The Setup Loop
{
Wire.begin(); // setup the I2C bus
for (unsigned int i = 0; i &lt; 16; i++) { //Init variables
keyispressed[i] = 1; //clear the keys array (High is off)
noteisplaying[i] = 0; //no notes are playing
}
//--- Set up pins
pinMode(octaveup, INPUT);
pinMode(octavedown, INPUT);
pinMode(octave1, OUTPUT);
pinMode(octave2, OUTPUT);
pinMode(octave3, OUTPUT);
pinMode(octave4, OUTPUT);

MIDI.begin(); //initialise midi library
displayoctave(); //display the current octave

}
//---------------------------------------------
void loop() //the main loop
{
readkeys();
sendMIDI();
checkoctave();
}
//-------------------------------------
void readkeys() { //Read the state of the I2C chips. 1 is open, 0 is closed.
Wire.requestFrom(0x38, 1); // read the data from chip 1 in data1
if (Wire.available()){
data1 = Wire.read();

}
Wire.requestFrom(0x39, 1); // read the data freom chip 2 into data2
if (Wire.available()){
data2 = Wire.read();
}

for (unsigned char i = 0; i &lt; 8; i++) {// puts data bits from chip 1 into keys array keyispressed[i] = ((data1 &gt;&gt; i) &amp; 1); // set the key variable to the current state. chip 1
keyispressed[i + 8] = ((data2 &gt;&gt; i) &amp; 1); //chip 2
}
}
//-------------------------------------
void sendMIDI() { // Send MIDI instructions via the MIDI out
int note; //holder for the value of note being played

velocity = analogRead(potpin)/8;// Read velocity from the pot
for (unsigned char i = 0; i &lt; 16; i++) { //for each note in the array
if (keyispressed[i] == LOW){ //the key on the board is pressed
if(!noteisplaying[i]){ //if the note is not already playing send MIDI instruction to start the note
note = i + (octave*12) + transpose;
MIDI.sendNoteOn(note,velocity,1); // Send a Note ( vel.127 ch. 1)
noteisplaying[i] = note; // set the note playing flag to TRUE and store the note value
}
}
else{
if(noteisplaying[i]){ //if the note is currently playing, turn it off
note = noteisplaying[i]; //retrieve the saved note value incase the octave has changed
MIDI.sendNoteOff(note,0,1); // Stop the note
noteisplaying[i] = 0; // clear the note is playing flag
}
}
}
}
//----------------------------------------
void checkoctave(){
int up = digitalRead(octaveup);
int down = digitalRead(octavedown);

if(up == HIGH){ //up button pressed
if(octave &lt; 4){ octave++; } while(up == HIGH){// wait until button is released up = digitalRead(octaveup); delay(20); } displayoctave(); } if(down == HIGH){ //down button pressed if(octave &gt; 1){
octave--;
}
while(down == HIGH){// wait until button is released
down = digitalRead(octavedown);
delay(20);
}
displayoctave();
}
}
//-------------------------------------
void displayoctave(){
// clear all the LEDs
digitalWrite(octave1, LOW);
digitalWrite(octave2, LOW);
digitalWrite(octave3, LOW);
digitalWrite(octave4, LOW);
// ...and then display the current octave
switch(octave){ // display the current actave
case 1: digitalWrite(octave1, HIGH);
break;
case 2: digitalWrite(octave2, HIGH);
break;
case 3: digitalWrite(octave3, HIGH);
break;
case 4: digitalWrite(octave4, HIGH);
break;
}
}



DH Mobil uygulaması ile devam edin. Mobil tarayıcınız ile mümkün olanların yanı sıra, birçok yeni ve faydalı özelliğe erişin. Gizle ve güncelleme çıkana kadar tekrar gösterme.