Pages: [1]   Go Down
Author Topic: Combining Code - MIDI test and 5x7 LED matrix  (Read 945 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 60
Interface Design Currently
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello !!

pls help if you can, would really appreciate it.

Im trying to combine this Simple MIDI test:
http://www.instructables.com/id/Send-and-Receive-MIDI-with-Arduino/?&sort=ACTIVE&limit=40&offset=40

with this simple LED 5x7:
http://www.instructables.com/id/Arduino-random-letter-generator/

I have edited both codes and they work separately.
When combining im getting the error:
Code:
Midi_and_5x7_test.cpp: In function 'void loop()':
Midi_and_5x7_test:87: error: 'noteOn' was not declared in this scope
Midi_and_5x7_test:97: error: a function-definition is not allowed here before '{' token

The sketches dont interact, i just want them to run in parallel.
Im guessing its my 'int' delcaration? But i dont know how to fix it.

pls HELP

thanks
(pretty nooby - read lots of articles and reseources but still baffled)


here is the code:

Code:
/*
"Stadt-Land-Fluss"
Arduino random capital letter generator by pressing a button. No transistors or shift registers are used for driving the LED matrix.

Pin mapping with Kingbright TC07-11EWA 5x7 LED matrix:

Arduino pin  LED matrix pin (470 Ohm resistor between each Arduino pin 0-6 and its corresponding LED matrix pin)
0            6  Row 7
1            5  Row 6
2            4  Row 5
3            9  Row 4
4            2  Row 3
5            11 Row 2
6            12 Row 1

8            1  Column 1
9            3  Column 2
10           10 Column 3
11           7  Column 4
12           8  Column 5

Arduino pin 7 is the input pin for the button. Using the other available pin 13 somehow didn't work out for me.
*/

const byte xPin[] = {8,9,10,11,12}; // Cathode pins, vertical columns on LED matrix
const byte yPin[] = {0,7,2,3,4,5,6}; // Anode pins, horizontal rows on LED matrix; connected via 470 Ohm resistor

const byte xLedNumber = 5; // Number of LEDs in the matrix in x direction (number of columns). Using variables makes it easier to adapt code to other matrices
const byte yLedNumber = 7; // Number of LEDs in the matrix in y direction (number of rows)

const byte numberOfCharacters = 28; // Number of characters in the font used. Variable needed as upper limit in the random number generation

byte font_5x7w[28][5] = {
 {0x7e,0x88,0x88,0x88,0x7e}, // A  0 <- the numbers here are the numbers of the matrix elements (helps to keep track)
 {0xfe,0x92,0x92,0x92,0x6c}, // B  1
 {0x7c,0x82,0x82,0x82,0x44}, // C  2
 {0xfe,0x82,0x82,0x44,0x38}, // D  3
 {0xfe,0x92,0x92,0x92,0x82}, // E  4
 {0xfe,0x90,0x90,0x80,0x80}, // F  5
 {0x7c,0x82,0x82,0x8a,0x4c}, // G  6
 {0xfe,0x10,0x10,0x10,0xfe}, // H  7
 {0x00,0x82,0xfe,0x82,0x00}, // I  8
 {0x04,0x02,0x82,0xfc,0x80}, // J  9
 {0xfe,0x10,0x28,0x44,0x82}, // K  10
 {0xfe,0x02,0x02,0x02,0x02}, // L  11
 {0xfe,0x40,0x20,0x40,0xfe}, // M  12
 {0xfe,0x20,0x10,0x08,0xfe}, // N  13
 {0x7c,0x82,0x82,0x82,0x7c}, // O  14
 {0xfe,0x90,0x90,0x90,0x60}, // P  15
 {0x7c,0x82,0x8a,0x84,0x7a}, // Q  16
 {0xfe,0x90,0x98,0x94,0x62}, // R  17
 {0x62,0x92,0x92,0x92,0x8c}, // S  18
 {0x80,0x80,0xfe,0x80,0x80}, // T  19
 {0xfc,0x02,0x02,0x02,0xfc}, // U  20
 {0xf8,0x04,0x02,0x04,0xf8}, // V  21
 {0xfe,0x04,0x18,0x04,0xfe}, // W  22
 {0xc6,0x28,0x10,0x28,0xc6}, // X  23
 {0xc0,0x20,0x1e,0x20,0xc0}, // Y  24
 {0x86,0x8a,0x92,0xa2,0xc2}, // Z  25
 {0x4C,0xB2,0x92,0x6C,0x0A}, // test 26 /*&*/
 {0x04,0x02,0xFF,0x02,0x04}, // test 27 arrow
 };

void setup() {
 
  Serial1.begin(31250);   //  Set MIDI baud rate:
 
 
 
  // Configure pins for output
  for (int i = 0; i < xLedNumber; i++) {
    pinMode (xPin[i], OUTPUT);
  }

  for (int i = 0; i < yLedNumber; i++) {
    pinMode (yPin[i], OUTPUT);
  }
 
}

void loop() {
 // clear();
 
 
 // play notes from F#-0 (0x1E) to F#-5 (0x5A):
  for (int note = 0x1E; note < 0x5A; note ++) {
    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    noteOn(0x90, note, 0x45);
    delay(20);
    //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
    noteOn(0x90, note, 0x00);   
    delay(20);
  }
 
 
//  plays a MIDI note.  Doesn't check to see that
//  cmd is greater than 127, or that data values are  less than 127:
void noteOn(int cmd, int pitch, int velocity) {
  Serial1.write(cmd);
  Serial1.write(pitch);
  Serial1.write(velocity);
}

 
displayCharacter(21); delay (100);
displayCharacter(0); delay (100);// Show an "A" until the button is pressed for the first time
displayCharacter(7); delay (80);
displayCharacter(0); delay (100);
displayCharacter(10); delay (200);
displayCharacter(3); delay (100);
displayCharacter(2); delay (100);
displayCharacter(22); delay (10);
displayCharacter(21); delay (100);
displayCharacter(25); delay (100);
displayCharacter(1); delay (500);
displayCharacter(8); delay (100);
displayCharacter(4); delay (100);
displayCharacter(10); delay (150);
displayCharacter(11); delay (100);
displayCharacter(2); delay (100);
displayCharacter(25); delay (100);
displayCharacter(1); delay (500);
displayCharacter(8); delay (100);
displayCharacter(3); delay (200);
displayCharacter(2); delay (100);
displayCharacter(11); delay (50);
displayCharacter(2); delay (20);
displayCharacter(25); delay (100);
displayCharacter(1); delay (500);
displayCharacter(8); delay (100);

}



// The clear() function clears the LED matrix
void clear() {
  for (int i = 0; i < xLedNumber; i++) {
    digitalWrite(xPin[i], HIGH); // The cathode pins need to be set HIGH if no current should flow in this directly driven configuration of Arduino and LED matrix
  }
  for (int i = 0; i < yLedNumber; i++) {
    digitalWrite(yPin[i], LOW);
  }

}


// The displayCharacter() function is responsible for displaying the selected character (number within the character matrix) on the LED matrix
void displayCharacter(int characterNumber) {
  for (int xCounter = 0; xCounter < xLedNumber; xCounter++) { // Cycling through the columns in the LED matrix
    digitalWrite(xPin[xCounter], LOW); // The cathode pins need to be set LOW for current to flow from an anode pin via an LED through a cathode pin

    for (int yCounter = 0; yCounter < yLedNumber; yCounter++) { // Cycling through the rows in the LED matrix
      byte yRow = (font_5x7w[characterNumber][xCounter] >> (yCounter + 1)) & 1; // y = (x >> n) & 1;    n=0..15.  stores nth bit of x in y.  y becomes 0 or 1. http://www.arduino.cc/playground/Code/BitMath#quickref
      digitalWrite(yPin[yCounter], yRow);
    }

    delay(10); // Some delay is needed for the multiplexing to function properly. Experiment with larger delay values to see multiplexing in slow motion.
 clear();
  }
 
 
}


   

Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is missing a curly bracket after the definition of the loop() function.
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 604
Posts: 33421
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

For how to combine code see:-
http://www.thebox.myzen.co.uk/Tutorial/Merging_Code.html
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 60
Interface Design Currently
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

THANKS for your replies
I have indeed already read the combining code page.

Also, I cannot find where the curly symbol should go.
Ive moved a few around but no luck.

Vahakn
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 604
Posts: 33421
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Also, I cannot find where the curly symbol should go.
It is called a brace, it marks out blocks of code, they always match left and right in the code.
It goes where it needs to go to do what you want to do.

You should get more experience in writing code before you try and do this. Try a few tutorials first and learn what code does.

reply #1 told you about the one you had missing.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Excuse the wrong word, I'm not a native English speaker.

My guess for the curly brace:
Code:
void loop() {
 // clear();
  
  
 // play notes from F#-0 (0x1E) to F#-5 (0x5A):
  for (int note = 0x1E; note < 0x5A; note ++) {
    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    noteOn(0x90, note, 0x45);
    delay(20);
    //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
    noteOn(0x90, note, 0x00);  
    delay(20);
  }

} // here it has to go (I guess)
  
  
//  plays a MIDI note.  Doesn't check to see that
//  cmd is greater than 127, or that data values are  less than 127:
void noteOn(int cmd, int pitch, int velocity) {
Logged

Saskatchewan
Offline Offline
Sr. Member
****
Karma: 19
Posts: 363
When the going gets weird, the weird turn pro. - Hunter S. Thompson
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That looks about right.

The technique I use to not lose track of braces is to always type them in pairs. If I type an open brace I immediately type the close brace and then cursor back and start putting in code. The IDE also has a brace matching tool. Cursor to one it will highlight it's match. The code format tool will also spot a missing brace.

It's easy to drop one or get an extra one when cutting and pasting too. Again, use the format tool. (ctrl-t)

No matter how careful you are it will still happen. So often that a compiler error like that should have you checking for mismatched braces. I tend to ctrl-t (format), ctrl-s (save), and then ctrl-r or ctrl-u, compile or compile and upload, as a habit.
Logged

Pages: [1]   Go Up
Jump to: