Show Posts
Pages: 1 ... 3 4 [5] 6 7
61  Using Arduino / Programming Questions / don't understand float on: August 05, 2012, 03:57:48 pm
I was varying a float variable called "lfoAmmount", and this line worked fine:
Code:
pitch=(pitch+(getLfoValue(lfoType)/lfoMaxValue)*lfoAmmount);

pitch is also float and contained decimals.

I read that floats are a little heavy for proccesing, so I want now to convert "lfoAmmount" to integer, but when I run this line:
Code:
pitch=(pitch+(getLfoValue(lfoType)/lfoMaxValue)*float(lfoAmmount/10)));

Now pitch doesn't have any decimals.

Also I tryed doing this and it does the same:
Code:
pitch=(pitch+(getLfoValue(lfoType)/lfoMaxValue)*float(lfoAmmount/10)));

What's the problem?
62  Using Arduino / Project Guidance / Re: Help with multiplexer (74HC4051) on: August 04, 2012, 02:35:33 pm
Code:
OK, and you are actively driving the right pins LOW? Have you verified that all input selector pins show zero volts continuously?

I feel so stupid... The problem was that I didn't defined the selectorPins as output, so they were erratic...

Thank you so much you all!!!

EDIT: It's working perfectly!
63  Using Arduino / Project Guidance / Re: Help with multiplexer (74HC4051) on: August 04, 2012, 12:00:22 pm
I've noticed that using or not the multiplexer when I press any button connected on the board the reading gets a little higher, that might be interference with the board I'm using, is not really a problem at this point.

But the weird thing is that it seems that the multiplexer every time in a while changes the channel it's reading
64  Using Arduino / Project Guidance / Re: Help with multiplexer (74HC4051) on: August 04, 2012, 11:45:29 am
yes, I am using a pot like that.
It's working fine if it's connected directly to an Arduino pin
65  Using Arduino / Project Guidance / Re: Help with multiplexer (74HC4051) on: August 04, 2012, 11:38:49 am
I'm sorry but what do you mean when not actuated?

As a test I connected every input from the multiplexor to the ground except a potentiometer.

*When I select one of the ground channels (A1-A7) it gives a reading of 47-49 when the pot is at maximum or at minimum, it's affecting it very little to nothing.
*When I select the pot channel (A0) and set the pot to minimum it gives me this:
Code:
pitchRead: 47.00
pitchRead: 48.00
pitchRead: 48.00
pitchRead: 48.00
pitchRead: 49.00
pitchRead: 70.00
pitchRead: 73.00
pitchRead: 46.00
pitchRead: 46.00
pitchRead: 47.00
pitchRead: 53.00
pitchRead: 56.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 49.00
pitchRead: 71.00
pitchRead: 76.00
pitchRead: 50.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 80.00
pitchRead: 62.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 48.00
pitchRead: 48.00

And when I spin the pot at maximum it gives me this:
Code:
pitchRead: 973.00
pitchRead: 974.00
pitchRead: 973.00
pitchRead: 974.00
pitchRead: 971.00
pitchRead: 965.00
pitchRead: 962.00
pitchRead: 46.00
pitchRead: 69.00
pitchRead: 54.00
pitchRead: 46.00
pitchRead: 46.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 62.00
pitchRead: 969.00
pitchRead: 973.00
pitchRead: 974.00
pitchRead: 975.00
pitchRead: 975.00
pitchRead: 974.00
pitchRead: 975.00
pitchRead: 976.00
pitchRead: 964.00
pitchRead: 975.00
pitchRead: 974.00
pitchRead: 974.00
pitchRead: 974.00
pitchRead: 974.00
pitchRead: 973.00
pitchRead: 973.00
pitchRead: 974.00
pitchRead: 973.00
pitchRead: 973.00
pitchRead: 974.00
pitchRead: 974.00
pitchRead: 974.00
pitchRead: 973.00
pitchRead: 974.00
pitchRead: 47.00
pitchRead: 975.00
pitchRead: 974.00
pitchRead: 975.00
pitchRead: 974.00
pitchRead: 974.00
pitchRead: 974.00
pitchRead: 974.00

I am constantly selecting the cannel in the loop.
66  Using Arduino / Project Guidance / Re: Help with multiplexer (74HC4051) on: August 04, 2012, 11:13:50 am
Thanks all for the help!
But now I need more :-)

I am using the 74HC4051 multiplexor and I connected 3 buttons and 2 pots to it.
I am getting very erratic readings on the pots, it might be accurate enough to use it for buttons, but not for the pot.
For example, I select channel 0 (0,0,0) for reading A0 wich is connected to the pot, I spin the pot to the maximum value and the output is this:
Code:
pitchRead: 1014.00
pitchRead: 1013.00
pitchRead: 1014.00
pitchRead: 1013.00
pitchRead: 1013.00
pitchRead: 1014.00
pitchRead: 1013.00
pitchRead: 1014.00
pitchRead: 1023.00
pitchRead: 26.00
pitchRead: 24.00
pitchRead: 25.00
pitchRead: 26.00
pitchRead: 40.00
pitchRead: 1013.00

Also, if I press one of the buttons the reading is higher, if I press the 3 buttons at the same time more.
Maybe I need to use one multiplexor for the pots and another for the buttons???

Why the sudden drop on the reading?
67  Using Arduino / Project Guidance / Re: Help with multiplexer (74HC4051) on: August 03, 2012, 06:32:46 pm
oooohhhhhhh... I see.
So a shift register it is.

Thanks for the clarification.
68  Using Arduino / Project Guidance / Re: Help with multiplexer (74HC4051) on: August 03, 2012, 05:40:07 pm
No, wait... you can write on it.

On the datasheet (http://www.datasheetcatalog.org/datasheet2/8/0uo046lw3xgikpf1d0zg15wpefpy.pdf) it says:
Code:
The 74HC/HCT4051 are 8-channel analog
multiplexers/demultiplexers with three digital select inputs
(S0to S2), an active LOW enable input (E), eight
independent inputs/outputs (Y0to Y7) and a common
input/output (Z).

What I want to do is write on 8 different pins by using the multiplexer, one at a time by writing each time the selector value and then the pin value. Am I that wrong?
69  Using Arduino / Project Guidance / Re: Help with multiplexer (74HC4051) on: August 03, 2012, 05:24:26 pm
oh... ok, so a multiplexer cannot be used to write?
There is the problem then, hehe. I thought it could be used for reading as well as writing.
I would need to use a shift register then, right?

Cool project by the way!
70  Using Arduino / Project Guidance / Help with multiplexer (74HC4051) on: August 03, 2012, 04:56:40 pm
I am using an IC that has a data input of 8 bit. Instead of using 8 pins on my Arduino I want to use a multiplexer.
So I connected it in the same way it's here: http://www.arduino.cc/es_old/Tutoriales/74HC4051
but instead of doing a analogRead at the end, I do a digitalWrite to the "COM OUT/IN" pin on the multiplexer. And when trying to write a certain 8 bit value it doesn't work.

I did a test reading a control pin on the multiplexer outputs but it's not even stable, it's erratic.

Is it possible to use this multiplexer in the way I want? What's wrong????

Thanks!
71  Using Arduino / Programming Questions / Re: Problem with reading back from PROGMEM, HELP? on: July 27, 2012, 01:54:40 pm
I used the example for Strings documented here: http://arduino.cc/en/Reference/PROGMEM
The problem seems to be giving it a variable instead of a constant where it is "i" here:

Code:
strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i])));

I really don't know why it does that, here it is used like that and it is suposed to work fine:

Code:
  for (int i = 0; i < 6; i++)
  {
    strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i]))); // Necessary casts and dereferencing, just copy.
    Serial.println( buffer );
    delay( 500 );
  }

Anyway... I resolved it by putting a number instead of "i"
Thanks
72  Using Arduino / Programming Questions / Re: Problem with reading back from PROGMEM, HELP? on: July 27, 2012, 12:37:52 pm
now, I "commented" some of the definition lines of PROGMEM at the beginning to check if it was memory problem and also I added this on the trouble line:

Code:
  printLog("menuIndex",menuIndex); // <--- ADDED THIS
  strcpy_P(buffer, (char*)pgm_read_word(&(menuOption[noteNumb])));  //    <--- THIS LINE IS TROUBLE
  Serial.println(buffer);
  printLog("menuIndex",menuIndex); // <--- ADDED THIS

Its giving me trash on the Serial Monitor, and the programm crashes (on Arduino), it doesn't responds anymore.
73  Using Arduino / Programming Questions / Problem with reading back from PROGMEM, HELP? on: July 27, 2012, 12:33:17 pm
I want to store a lot of strings for displaying it on an LCD, so first I do this:

Code:
prog_char string_0[] PROGMEM = "1-Tempo";
prog_char string_1[] PROGMEM = "2-Lider gordo";
prog_char string_2[] PROGMEM = "3-Envolvente";
prog_char string_3[] PROGMEM = "3b-Forma de env";
... etc etc
prog_char string_34[] PROGMEM = "C#";
prog_char string_35[] PROGMEM = "C";
prog_char string_36[] PROGMEM = "B";
prog_char string_37[] PROGMEM = "A#";
prog_char string_38[] PROGMEM = "A";

PROGMEM const char *menuOption[] = {string_0,string_1,string_2,string_3,... etc etc ,string_38};
char buffer[16];

then when I want to display one of the strings on the LCD:

Code:
strcpy_P(buffer, (char*)pgm_read_word(&(menuOption[21])));
lcd.print(buffer);

and that seems to work fine.

but when I want to return one of those strings back from a function I get a strange behavior

Code:
String getNoteName(int pitch){
  int oct = ((pitch-33)/12)+1; //33=A1
  int noteNumb = pitch-((12*(oct+2))-3);
 
  noteNumb=noteNumb+38; //Index 38 is A, 37 is A#, 36 is B and so on...
  String noteName;
  strcpy_P(buffer, (char*)pgm_read_word(&(menuOption[noteNumb])));  //    <--- THIS LINE IS TROUBLE!
  Serial.println(buffer);
  noteName = String(buffer);
  noteName.concat(oct);
  return noteName;

What that function does is you give it the note number and it returns the note name, for example "A4". The problem is that the line I point there is, somehow, changing the value for menuIndex when I do this:

Code:
  strcpy_P(buffer, (char*)pgm_read_word(&(menuOption[menuIndex])));
  Serial.println(buffer);
  lcd.print(buffer);

also when I print buffer to Serial it prints this:

œ ”œ ”œ ”œ ”œ •œ –X œ ”ü ”C ”œ ”œ ”œ ”œ ”œ ”œcB6·›Ø§9hV®º«UŒ<·ÌWc½míýu>ör1”

Any idea???? Very weird, I am not writing on the memory, always reading... or that is what I intend...
Could it be that I am getting low on memory? my sketch is 19.300 bytes according to the bottom of the compiler
Thanks!
74  Using Arduino / Project Guidance / Balance like knob? on: July 23, 2012, 01:08:37 am
I am working on a small synth and I wanted to have one knob that detunes one oscillator from the main note.
If someone detunes it and then wants to put it back to where it was, on a normal potentiometer you will have to use your ear.
So I was thinking of having a potentiometer/knob like the one on some radios where you control the balance: When you reach the normal (center) position it clicks and goes to the exact middle, if you want to move it from the center the knob resists a little.

Could I buy it somewhere? What's called?

BONUS: Also what about ribbon resistor? A band that gets different R values depending on where you press it.

Thanks!
75  Using Arduino / General Electronics / Re: [SOLVED] Help with the AY-3-8910 IC datasheet! on: July 20, 2012, 02:39:56 am
OH YEAH! The problem was the way I was sending the address for the registers.
I used a library for fast pin switching so I didn't have to use PORT manipulation.

Right now I reached a point where you can play a note with a button and you can change pitch of the note with a pot.

Again, thank you very much to all, especially Majenco and Telecommando for taking the time to help me!

For future generations  smiley-cool I will paste the entire code here:

Code:
#include <digitalWriteFast.h>
//then you can use digitalWriteFast(pin,HIGH/LOW),
//digitalReadFast(pin), pinMode(pin,INPUT/OUTPUT),
//digitalWriteFast2(pin,HIGH/LOW), digitalReadFast2(pin),
//pinMode2(pin,INPUT/OUTPUT)very much as you have used the built-in commands.
//The object code will not only be faster, but actually smaller as well.

//----CLOCK OUTPUT ON PIN 3
const int freqOutputPin = 3; 
const int ocr2aval  = 3;
const int prescale  = 1;
const float period    = 2.0 * prescale * (ocr2aval+1) / (F_CPU/1.0e6);
const float freq      = 1.0e6 / period;
//---------


const int dataPins[] = {4,5,6,7,8,9,10,11};
const int bc1Pin=12;
const int bdirPin=13;
//-------

const int pitchPin=A0;
float oldPitch=-1;
int oldPitchDec=-1;
const int playPin=A1;

void setup() {
  //---for the clock output
  pinMode(freqOutputPin, OUTPUT);
  Serial.begin(9600);
  TCCR2A = ((1 << WGM21) | (1 << COM2B0));
  TCCR2B = (1 << CS20);
  TIMSK2 = 0;
  OCR2A = ocr2aval;

  Serial.print("Period    = ");
  Serial.print(period);
  Serial.println(" microseconds");
  Serial.print("Frequency = ");
  Serial.print(freq);
  Serial.println(" Hz");
  //----
 
  pinMode (bc1Pin,OUTPUT);
  pinMode (bdirPin,OUTPUT);
  pinMode (pitchPin,INPUT);
  Serial.begin(9600);
  inactiveModeFun();
  setDataOutFun();
  resetICFun();
  testSoundA();
}

void loop() {
  float pitch = analogRead(pitchPin);
  pitch=(pitch/1023)*15;
  int pitchDec=(pitch-int(pitch))*255;
 
  if (analogRead(playPin) < 16) {
  writeICFun(13,0);
  }
 
  delay(100);
  if (int(pitch)!=int(oldPitch)) {
    oldPitch=pitch;
    Serial.print("Course: ");
    Serial.println(int(pitch));
    writeICFun(1,int(pitch));
    writeICFun(3,int(pitch));
    writeICFun(5,int(pitch));
  } 
  if (pitchDec-oldPitchDec<10 ||  pitchDec-oldPitchDec>-10){
    oldPitchDec=pitchDec;
    //Serial.print("Fine: ");
    //Serial.println(pitchDec);
    writeICFun(0,int(pitchDec));
    writeICFun(2,int(pitchDec));
    writeICFun(4,int(pitchDec));
  }
 
}

void writeICFun(int reg,int valor) { //maneja valor integer, lo convierte y lo pasa a la otra

  writeBusFun(reg); //buscar dir
  latchModeFun();
  inactiveModeFun();
  writeBusFun(valor); //darle varlor
  writeModeFun(); 
  inactiveModeFun();
}
void writeBusFun(int valor) {
  for (int x=0;x<8;x++) {
    digitalWriteFast2(dataPins[x],bitRead(valor,x));
  }
}

byte readICFun(int reg) {
  writeBusFun(reg); //buscar dir
  latchModeFun();
  inactiveModeFun();
  readModeFun();
  byte valorByte=readBusFun(); //mira valores
  inactiveModeFun();
  return valorByte;

}
byte readBusFun() {
  setDataInFun();
  byte valorByte=0;
  for (int x=0;x<8;x++) {
    bitWrite(valorByte,x,digitalRead(dataPins[x]));
  }
  setDataOutFun();
  return valorByte; 
}

void inactiveModeFun(){
  digitalWriteFast2(bdirPin,LOW);
  digitalWriteFast2(bc1Pin,LOW)
}
void readModeFun(){
  digitalWriteFast2(bdirPin,LOW);
  digitalWriteFast2(bc1Pin,HIGH)
}
void writeModeFun(){
  digitalWriteFast2(bdirPin,HIGH);
  digitalWriteFast2(bc1Pin,LOW)
}
void latchModeFun() {
  digitalWriteFast2(bdirPin,HIGH);
  digitalWriteFast2(bc1Pin,HIGH)
}
void setDataOutFun(){
  for (int x=0;x<8;x++) {
    pinMode(dataPins[x],OUTPUT);
}
}
void setDataInFun(){
  for (int x=0;x<8;x++) {
    pinMode(dataPins[x],INPUT);
}
}
void testSoundA(){
  writeICFun(0,0);
  writeICFun(1,6);
  //delay(6);
  writeICFun(2,0);
  writeICFun(3,6);
  writeICFun(4,0);
  writeICFun(5,6);
  writeICFun(6,1);
  writeICFun(7,int(B11111000));
  writeICFun(8,16);
  writeICFun(9,16);
  writeICFun(10,16);
  writeICFun(11,0);
  writeICFun(12,50);
  writeICFun(13,0);
}
void resetICFun(){
  for (int x=0;x<6;x++){
    writeICFun(x,0);
  }
}

There might be some variables named in spanish language but I changed that, so it's the minority.
Pages: 1 ... 3 4 [5] 6 7