Show Posts
Pages: 1 ... 1630 1631 [1632] 1633 1634 ... 2099
24466  Forum 2005-2010 (read only) / Interfacing / Re: Midi IN velocity value to led output VU meter on: September 14, 2010, 04:28:32 am
See if this makes any difference to what you see:-
Code:
byte incomingByte;
byte note;
byte velocity;

int statusled = 13;
int ledx=2;  
int val =0;
  
void setup()
{
  Serial.begin(31250);
  pinMode(9, OUTPUT);    
  pinMode(8, OUTPUT);    
  pinMode(7, OUTPUT);    
  pinMode(6, OUTPUT);    
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(statusled, OUTPUT);  
}

void loop ()
{
  if (Serial.available() > 2)
  {
    digitalWrite(statusled,HIGH);
    incomingByte = Serial.read();
   if (incomingByte == 144)
    {                      
    note = Serial.read();
     if (note == 1)
      {
    velocity = Serial.read();
        val = map(velocity, 0, 110, 2, 9);
       if (velocity >= 1 ) {
              for(int i= 2; i<10; i++) {  // turn all LEDs off
               digitalWrite(i,HIGH);
               }    
       if (velocity <= 1 ) digitalWrite(2,LOW); // this will never switch becaus you only get here if velocity is >1    
          if(velocity <= 18 ) digitalWrite(3,LOW);
       if(velocity <= 36) digitalWrite(4,LOW);
       if(velocity <= 54 )digitalWrite(5,LOW);
       if(velocity <= 65 ) digitalWrite(6,LOW);
       if(velocity <= 80 ) digitalWrite(7,LOW);
           if(velocity <= 100 ) digitalWrite(8,LOW);      
       if(velocity <= 120 ) digitalWrite(9,LOW);
    }
  }  
  else {digitalWrite(statusled, LOW);}  // to do if note not = to 1
   }
  } // end of reading MIDI input
 } // end of loop

Quote
wouldn't this be much simpler?
No, this means generating an analogue voltage from the arduino.
24467  Forum 2005-2010 (read only) / Interfacing / Re: Midi IN velocity value to led output VU meter on: September 14, 2010, 02:59:56 am
Quote
why WHILE could give a delay?

Because it relies on two variables, and incrementing them. So if any of the variables were to get out of alignment it could cause a lot of looping in that function. The structure I gave is a simple limited function and is much better programming practice.

 
Quote
i see the upper leds (highest velocity value) blink very very shortly.
As outputting a LOW on the pin is the only way to turn on the LED (is this correct) then trace where this is happening.
Post your whole code as you have it now and I will have a look.
24468  Forum 2005-2010 (read only) / Interfacing / Re: Midi IN velocity value to led output VU meter on: September 13, 2010, 05:35:08 pm
I don't like this bit of code, it has the potential for wraping round and causing a delay:-
Code:
while  (ledx < val+1)  
        {
         digitalWrite(ledx,HIGH);
         ledx++;
         }
Try replacing it with:-
Code:
for(int i= 3; i<10; i++) {
   digitalWrite(i,HIGH);
}
24469  Forum 2005-2010 (read only) / Interfacing / Re: Midi IN velocity value to led output VU meter on: September 13, 2010, 08:19:02 am
Every time you do a
note = Serial.read();
you need to check there is data in the buffer to read. This is only happening one place in your code not every time.
It might be better to do:-
if(Serial.available() > 2)

so you know you have at least the three bytes for a MIDI not input before you start pulling bytes out.
I think if you do this you will find that you can take those delays out.

24470  Forum 2005-2010 (read only) / Interfacing / Re: Seeking advice on diodes and capacitors for servos on: September 29, 2010, 02:26:53 am
Quote
I also forgot to ask about a draw down resistor.
The correct term is pull down resistor.

This is normally used for relays and other such outputs. A servo uses a pulse position modulation so it doesn't really apply. However there might be some noise being picked up when the pins controlling the servo are a high impedance input so you could try a 4K7 pull down resistor.
24471  Forum 2005-2010 (read only) / Interfacing / Re: Seeking advice on diodes and capacitors for servos on: September 28, 2010, 04:55:02 pm
Quote
I have been advised to use a diode on each servo to prevent EMF
You have been advised incorrectly, you don't have access to the motor in a servo.

Quote
And since capacitors are polarized how can it feed the servo when it's going from power to ground before the servo?

Not all capacitors are polarised.

See the decoupling web page:-
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

Quote
Any ideas of the capacitor size I should be using?
0.1uF and 10uF
24472  Forum 2005-2010 (read only) / Interfacing / Re: Interfacing with MCP23008 - Pin Codes on: September 30, 2010, 10:44:51 am
You can only test one bit at a time with this technique. Think about the result you want to get. If you want to test more than one bit at a time you have three potential results:-
1) all bits the same
2) some bits the same
3) no bits at all

So to test if all the bits are the same make your mask with bits you want to check, say bits 3 and 2 - mask = 0x0C and do
if( (var & mask) == mask ) { // all the bits in the mask match the bits in the variable }
24473  Forum 2005-2010 (read only) / Interfacing / Re: Interfacing with MCP23008 - Pin Codes on: September 30, 2010, 10:15:33 am
Quote
I should end up with "00110100" right? Turning Pin 14 on and leaving everything else the way it was before my statement?

yes that is right. There is an easer command to use now with bitSet() and bitClear() but I still prefer to use this method.

Quote
is there a way to tell if a specific bit is a 0 or a 1?

Yes you AND the variable with an other number (called a mask), the mask has a one in the bit position you want to check. So say you want to check bit 3 in a variable called var then
if(var & 0x08) { // its a 1 } else { // it's a zero }
24474  Forum 2005-2010 (read only) / Interfacing / Re: Interfacing with MCP23008 - Pin Codes on: September 24, 2010, 02:22:17 am
Quote
Yeah, that's not too clear from the MCP datasheets.
You must be joking, on page 5 there is a list of all the pins, it says:-
Quote
A2/SO 3 1 3 I/O Hardware address input (MCP23008)/
Serial data output (MCP23S08).
A2 must be biased externally.
A1 4 2 4 I Hardware address input. Must be biased externally.
A0 5 3 5 I Hardware address input. Must be biased externally.
then on page 7 it says:-
Quote
• MCP23008 has address pins A2, A1 and A0.
then on page 8 it says:-
Quote
The MCP23008 is a slave I2C device that supports 7-bit
slave addressing, with the read/write bit filling out the
control byte. The slave address contains four fixed bits
and three user-defined hardware address bits (pins A2,
A1 and A0). Figure 1-2 shows the control byte format.
With a diagram showing the pins in the bit array of the address.

Short of tattooing it on your forehead in a reverse manor so you can see it in the mirror I don't see how it could be much more clear.  :-?
24475  Forum 2005-2010 (read only) / Interfacing / Re: Interfacing with MCP23008 - Pin Codes on: September 23, 2010, 10:05:26 am
You can't command individual pins to go on and off you can only write whole bytes. Therefore you need to have a variable of the bit pattern you are writing. Then if you want to control an individual bit you simply set or clear the bit in that variable and write the whole thing again. You can do this with the bitSet() and bitClear() functions.

look at:- http://www.arduino.cc/playground/Code/BitMath

This project uses the chips big brother, two 8 bit registers and the code changes individual bits:-
http://www.thebox.myzen.co.uk/Hardware/MIDI_Footsteps.html
24476  Forum 2005-2010 (read only) / Interfacing / Re: Help on multiple sensor circuit on: September 30, 2010, 02:26:28 am
Quote
If my shield makes a pin unusable, why would the designer bring the connection through a supply a point for creating a connection to that (unusable) pin?
Because it is probably not totally unusable. For example some of those pins are for the SPI bus. This can coexist with your shield if you want to add an extra device to the bus but is not usable if you want them to light LEDs and such.
24477  Forum 2005-2010 (read only) / Interfacing / Re: Help on multiple sensor circuit on: September 29, 2010, 04:06:57 pm
Quote
Can my circuit be incompatible with the shield?

Yes if it uses the same pins as the shield or if the interrupts in the software interfere with the operation of your circuit.

It would have helped if you mentioned this other circuit earlier.
24478  Forum 2005-2010 (read only) / Interfacing / Re: Help on multiple sensor circuit on: September 29, 2010, 09:26:05 am
It indicates that it is not the other sensors causing you trouble but some miss wiring over all.
24479  Forum 2005-2010 (read only) / Interfacing / Re: Help on multiple sensor circuit on: September 29, 2010, 08:11:53 am
Quote
Is anything obvious wrong with my circuit?
No looks ok.
Make sure the ground shown is connected to the ground on the arduino. Then start backwards. Connect up your distance sensor and add the other things one at a time and see which one breaks it. Then find out if it is just this one or is it the accumulation of the other circuit parts.
24480  Forum 2005-2010 (read only) / Interfacing / Re: LM135 - Precision Temperature Sensor on: September 30, 2010, 02:41:42 am
Quote
1) How do i know what resistor i will need for R1?
You calculate it. The sensor sucks 10mV per degree K. So you work out what voltage you want to see at a spot temperature. Suppose you want it to read 1V at 0C (that's about 273K)
http://en.wikipedia.org/wiki/Kelvin
Therefore the sensor drops 273 * 10 = 2730mV or 2.730mV across it. If you look at the data sheet it says that it operates from 400uA to 5mA. So say you want to run it at 2mA, you want 2mA through a resistor to have a voltage drop of 5 - 2.73 = 2.27V. Ohms law gives you a value of 2.27 / 0.002 = 1135R (ohms). So choose the closest value of 1K.

Quote
2) if you only need the + and - pins what the hell is the ADJ pin there for?
To adjust the absolute value of the voltage out and so calibrate it. Please read the data sheet.
Pages: 1 ... 1630 1631 [1632] 1633 1634 ... 2099