Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Predefined int matrix to update via serial from Processing on: April 01, 2014, 02:02:13 pm
It is more clear now. Then just need to convert the multi-dimensional matrix to one single matrix. If I get it correct the following calculation would give me the location address to read or write of the value I want.
Code:
prsBtState[x][y];
address = (x * 8) - (8 - y) - 1;
2  Using Arduino / Programming Questions / Re: Predefined int matrix to update via serial from Processing on: April 01, 2014, 12:18:08 pm
I am confused about writing and reading matrix variables from EEPROM. I have read & write single values before but never did it with matrix.

But my main confusion is about the write order. As I said I have predifened values but these values should be updateable later on. If I write these predefined values to EEPROM at the setup loop it will reset the updates at each restart. Should I compile the skecth two times? First to upload the predifed values to EEPROM with EEPROM.write() in setup and then remove the write command and change it EEPROM.read() to retrive the data stored in the EEPROM?
3  Using Arduino / Programming Questions / Re: Predefined int matrix to update via serial from Processing on: April 01, 2014, 11:20:58 am
Thanks. I got your point and updated the code to change the data type to byte.
4  Using Arduino / Programming Questions / Re: Predefined int matrix to update via serial from Processing on: April 01, 2014, 10:39:58 am
The button state values are declared as int. The a preset is loaded i read the corresponded values from the matrix and update the button state variable with it.

Is it wrong? Shall I use another data type?
5  Using Arduino / Programming Questions / Predefined int matrix to update via serial from Processing on: April 01, 2014, 10:13:13 am
Hi,

I am working on a midi controller project. The controller has a preset mode. When a preset is selected it gets the button states predefined in prsBtState variable and updates the current butoon states.

The prsBtState state variable is a 20x8 int matrix.

Code:
int prsBtState[20][8] ={
                          {1, 0, 0, 0, 0, 0, 0, 0},//A1
                          {0, 1, 0, 0, 0, 0, 0, 0},//A2
                          {0, 0, 1, 0, 0, 0, 0, 0},//A3
                          {0, 0, 0, 1, 0, 0, 0, 0},//A4
                          {0, 0, 0, 0, 1, 0, 0, 0},//B1
                          {0, 0, 0, 0, 0, 1, 0, 0},//B2
                          {0, 0, 0, 0, 0, 0, 1, 0},//B3
                          {0, 0, 0, 0, 0, 0, 0, 1},//B4
                          {0, 1, 0, 1, 0, 1, 0, 1},//C1
                          {1, 1, 1, 1, 1, 1, 1, 1},//C2
                          {0, 0, 0, 0, 0, 0, 0, 0},//C3
                          {1, 0, 1, 0, 1, 0, 1, 0},//C4
                          {1, 1, 1, 1, 1, 1, 1, 1},//D1
                          {0, 0, 0, 0, 0, 0, 0, 0},//D2
                          {1, 0, 1, 0, 1, 0, 1, 0},//D3
                          {0, 1, 0, 1, 0, 1, 0, 1},//D4
                          {0, 0, 0, 0, 0, 0, 0, 0},//E1
                          {1, 0, 1, 0, 1, 0, 1, 0},//E2
                          {0, 1, 0, 1, 0, 1, 0, 1},//E3
                          {1, 1, 1, 1, 1, 1, 1, 1}//E4
                          };

The current sketch is working perfect. However each time I want update the predefined presets I need to change the sketch and recompile it. Now I want to build a custom GUI (I am planning to use processing) to update the presets. The goal is send the preset updates via serial to arduino and update the prsBtState. I think I need to store prsBtState in the EEPROM in order to achive this.

I am correct; how can I store this int matrix in EERPOM?
I am wrong; what is the best way to achive my goal?

Thanks in advance.
6  Using Arduino / Audio / Re: Arduino Micro and MIDI Library on: February 15, 2014, 11:29:40 am
Thank you. I have completely forgot about this topic.

I have edited the midi.h file in ordet to use the midi library with midi din connected to TX pin on Arduino Micro or Leonardo.

To do that:
1 - Open; MIDI.h with a text editor
2 - Find line; #define USE_SERIAL_PORT   Serial
3 - Replace; Serial with Serial1
4 - Save&Close file

7  Using Arduino / LEDs and Multiplexing / Re: Cascade two 4051 to read 16 buttons on: February 08, 2014, 05:50:05 am
Thank you so much Mike. I followed your suggestions and it is working now.

Here is the final code two read from two cascaded 4051s, for future reference...

Code:
int b0 = 0;
int b1 = 0;
int b2 = 0;

const int mux1 = A0;
const int mux2 = A1;

int buttonValue[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int lastButtonValue[16] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
const int ledPin =  13; 

void setup(){

  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT); 
  pinMode(4, OUTPUT); 
  pinMode(ledPin, OUTPUT);
}

void loop () {

muxone();
muxtwo();
}

void muxone () {

for (int buttonCount = 0; buttonCount < 8; buttonCount++) {
    b0 = bitRead(buttonCount,0);
    b1 = bitRead(buttonCount,1);
    b2 = bitRead(buttonCount,2);

    digitalWrite(4,b0);
    digitalWrite(3,b1);
    digitalWrite(2,b2);

    buttonValue[buttonCount] = digitalRead(mux1);
 
   
    if(buttonValue[buttonCount] == LOW && lastButtonValue[buttonCount] == HIGH) {
      digitalWrite(ledPin, HIGH);
    }

    if(buttonValue[buttonCount] == HIGH && lastButtonValue[buttonCount] == LOW) {
      digitalWrite(ledPin, LOW); 
      }   
      lastButtonValue[buttonCount] = buttonValue[buttonCount];
  }
 
  }
 
 
  void muxtwo () {

for (int buttonCount = 0; buttonCount < 16; buttonCount++) {
    b0 = bitRead(buttonCount,0);
    b1 = bitRead(buttonCount,1);
    b2 = bitRead(buttonCount,2);

    digitalWrite(4,b0);
    digitalWrite(3,b1);
    digitalWrite(2,b2);
    buttonValue[buttonCount + 8] = digitalRead(mux2);
   
    if(buttonValue[buttonCount] == LOW && lastButtonValue[buttonCount] == HIGH) {
      digitalWrite(ledPin, HIGH);
    }

    if(buttonValue[buttonCount] == HIGH && lastButtonValue[buttonCount] == LOW) {
      digitalWrite(ledPin, LOW); 
      }   
      lastButtonValue[buttonCount] = buttonValue[buttonCount];
  }
 
  }
8  Using Arduino / LEDs and Multiplexing / Re: Cascade two 4051 to read 16 buttons on: February 03, 2014, 01:56:55 am
Thanks for your input Mike. I have adopted the part of the code that scans the inputs from other projects.

http://forum.arduino.cc/index.php?topic=69837.0 
http://forum.arduino.cc/index.php/topic,21547.0.html

These are my source projects. They are all using the same login with two 4051 chips

Code:
for (int buttonCount = 0; buttonCount < 8; buttonCount++) {
    b0 = bitRead(buttonCount,0);
    b1 = bitRead(buttonCount,1);
    b2 = bitRead(buttonCount,2);

    digitalWrite(4,b0);
    digitalWrite(3,b1);
    digitalWrite(2,b2);
 
    buttonValue[buttonCount] = digitalRead(mux1);
 
    buttonValue[buttonCount + 8] = digitalRead(mux2);

buttonvalue stores 16 value array variable.  When I read "digitalRead(mux1);" Button count should go from 0-7 and I should be able to parshe the pin values of the first mux into the first 8 values of the buttonValue array variable. Then, "digitalRead(mux2)" should continue and "buttonValue[buttonCount + 8]" should register the pinvalues from the second mux into 8the to 15th values of the array. The for loop is going from 0 to 7 since I have two chips, and the reads from the second chip is incremented by 8 "buttonCount + 8" inorder to be able assign values to the second half of the 16 value array variable.

I have also suspected from the same part while experimenting and have change "buttonCount < 8;" part of the for loop to "buttonCount < 16;" and tested. It did not help. the same problem continued.

I think you are right about the problematic part but I do not know how to solve it. I need to read two different chips in a single for loop and then assign the 8 input readings from the first chip to the first 8 values of an array variable and the 8 other input values from the second chip to the second half of the same array.
9  Using Arduino / LEDs and Multiplexing / Re: Cascade two 4051 to read 16 buttons on: February 02, 2014, 03:43:16 pm
sorry I forgot to mention, my data lines are also using pins 2,3,4 on my circuit,  as it is in the code. I have added the wiring picture to give a reference to cascade type I am using.  I have modified the circuit while coding. Two chips are sharing the same data pins connected to oins 2,3,4 and they have individually connected to A0 and A1 pins for read channel.

You have no supply decoupling on any chips.
You never seem to address the second mux chip in the lower part of the code with all the ifs in it.

Can you open up this a bit? I dont really know how to read from the second chip. I am searching for an reference tutorial for the last two days and this is the result with I could find.

Note: I am using Arduino micro
10  Using Arduino / LEDs and Multiplexing / Cascade two 4051 to read 16 buttons on: February 02, 2014, 03:24:49 pm
Hi all,

I am tring to cascade two cd4051s inorder to 16 buttons.

Wiring is done based on http://www.567.dk/arduino/arduinocd4051b02.png this diagram and buttons have 220ohm resistors on readpins.

The problem is I can only read from one 4051 that is connected to Analog 0, the second 4051 does not respond. If I connect the non responding 4051 to A0 it starts working, so I am pretty sure the it is wired correctly.

I checked http://forum.arduino.cc/index.php/topic,21547.0.html this atticle and my others... modified my code, rewired everything, etc... but still no luck.

Most probably I am missing something basic but I am stucked and really appreciate some help.

My code:

Code:
int b0 = 0;
int b1 = 0;
int b2 = 0;

const int mux1 = A0;
const int mux2 = A1;

int buttonValue[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int lastButtonValue[16] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
const int ledPin =  13; 

void setup(){

  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT); 
  pinMode(4, OUTPUT); 
  pinMode(ledPin, OUTPUT);
}

void loop () {

for (int buttonCount = 0; buttonCount < 8; buttonCount++) {
    b0 = bitRead(buttonCount,0);
    b1 = bitRead(buttonCount,1);
    b2 = bitRead(buttonCount,2);

    digitalWrite(4,b0);
    digitalWrite(3,b1);
    digitalWrite(2,b2);
 
    buttonValue[buttonCount] = digitalRead(mux1);
 
    buttonValue[buttonCount + 8] = digitalRead(mux2);
   
    if(buttonValue[buttonCount] == LOW && lastButtonValue[buttonCount] == HIGH) {
      digitalWrite(ledPin, HIGH);
    }

    if(buttonValue[buttonCount] == HIGH && lastButtonValue[buttonCount] == LOW) {
      digitalWrite(ledPin, LOW); 
      }   
      lastButtonValue[buttonCount] = buttonValue[buttonCount];
  } 
}

Many thanks in advance!

Deniz
11  Using Arduino / Audio / Re: audio channel select and volume control on: July 23, 2013, 01:47:51 pm
Hi,

Do you have any updates on this project?

/deniz
12  Community / Exhibition / Gallery / Re: Arduino Audio Mixer with TDA7439DS, speaker remapping, equalizer, remote ... on: July 21, 2013, 03:55:30 pm
Hi

The source code link on your blog does not seem to be working. I downloaded the zip file but I think it is corrupted.

Would you mind posting the files here also?
13  Using Arduino / Audio / Arduino Micro and MIDI Library on: January 19, 2013, 03:35:00 pm
Hi all,

I recently bought a Arduino Micro board. I intent to use it for a midi footcontroller project. I tried a few basic sketches and the confirmed the board functions OK.

I want to use Franky's MIDI library for this project. The midi over serial is also an other option. Anyways, I tried a few basic codes for sending the midi message, but non of them working. Do I need to modify the code especially for arduino MICRO? All documentation on arduino Micro is based on Leonardo board, and it seems like some parts are out of date or doesnot really apply to MICRO board. I would really appreciate any help on this.

Midi out; pin3 goes to arduino ground, pin4 goes to 5v with a 220ohm resistor, pin5 goes to arduino TX with a 220ohm resistor.

Button is connected to arduino digital 2.

I tested the following codes but

The first code I tried:
Code:
#include <MIDI.h>

// set pin numbers:
const int ledPin =  13;      // the number of the LED pin

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);     
  MIDI.begin(); 
}

void loop(){

    MIDI.sendNoteOn(42,127,1);
    delay(1000);  
    MIDI.sendNoteOff(42,0,1);
    delay(1000);
    MIDI.sendNoteOn(25,127,1);
    delay(1000);  
    MIDI.sendNoteOff(25,0,1);
    delay(1000);
  }
This code is constantly sending note on/off messages but midi in monitor displays nothing.

The second code is to send to note when a button is pressed. The led flashes when is pressed.
Code:
#include <MIDI.h>

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);     
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  MIDI.begin(1); 
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) { 
    digitalWrite(ledPin,HIGH);
    MIDI.sendNoteOn(42,127,1);  // Send a Note (pitch 42, velo 127 on channel 1)
    delay(1000);         // Wait for a second
    MIDI.sendNoteOff(42,0,1);   // Stop the note
    digitalWrite(ledPin,LOW);
  }
}
Button is working and the led is flashing when it is pressed. But again no signal in midi monitor.

The final code I tried is just using serial.write and doesnt include the midi library. This also didnt work. Again No midi signals
Code:
const int button1 = 2;     // the number of the pushbutton pin

int buttonState = 0;       

void setup() {
  pinMode(button1, INPUT);     
  Serial.begin(31250);
}

void loop(){
  buttonState = digitalRead(button1);
  if (buttonState == HIGH) {
    noteOn(0x90, 0x1E, 0x45);
    delay(100);
  }
}


void noteOn(int cmd, int pitch, int velocity) {
  Serial.write(cmd);
  Serial.write(pitch);
  Serial.write(velocity);
}

I checked my midi cable and it is working perfectly. MIDI in port at my soundcard also functions OK with other devices. So all external factors are isolated.

Thanks in advance...
Pages: [1]