Show Posts
Pages: 1 ... 31 32 [33] 34 35 ... 80
481  Using Arduino / Programming Questions / Re: Calling functions from string on: May 03, 2013, 08:27:23 am
You cannot do this the way you are trying to do it. The function names need to be dereferenced by the compiler at compile time.

There are a number of different approaches:
1. You can set up an array of function pointers for each letter of the alphabet, then call the function based on the array lookup. This produces the most compact code.
2. Each letter can be in a switch/case statement and the function is called from the appropriate case. If you have only a few letters to handle this will probably use the least amount of memory
3. Use if statements, as in "if (letter == 'A') function_A();"
482  Using Arduino / Programming Questions / Re: how to ' convert data types to get only one decimal point ' ? on: May 01, 2013, 03:04:39 am
Riva probably has the easiest answer for you.

@ukhelibob - good question and I can't see an answer. Give other restrictions on floats, I expect probably not.

Update: here is a solution http://arduino.cc/forum/index.php/topic,146638.0.html
483  Using Arduino / Programming Questions / Re: how to ' convert data types to get only one decimal point ' ? on: May 01, 2013, 02:47:18 am
Use sprintf() to format the string before you use it, into a character array and then print the character array. There is an option to use a specific number of decimal points as part of the %format string (%.1f from memory, but better look it up).
484  Using Arduino / Programming Questions / Re: Count Down Code Options on: April 29, 2013, 02:24:28 pm
I have implemented something similar that counts down from 99 seconds that you could adapt. Look in the link below (signature block). Hope it is useful.
485  Using Arduino / Displays / Re: Does anyone know how to address character map of a 16x2 LCD? on: April 27, 2013, 06:49:12 pm
My reading of documentation has been that the LCD displays come with one rom set. Most of the ones I have seen have been the Asian extended characters. I have not found any way to 'switch' the rom code to one of the others sets - they are different part numbers from the manufacturer.
486  Using Arduino / Displays / Re: Does anyone how to address character map of a 16x2 LCD? on: April 27, 2013, 03:31:09 pm
As far as I know you just use the ASCII code for the characters and they will work. Internally they may well be arranged as rows and columns, but that is too detailed for me to want to worry about when I am just trying to print a character.
487  Using Arduino / LEDs and Multiplexing / Re: RGB LED easy smooth colour transitions on: April 25, 2013, 06:41:14 pm
What Headroom said is correct. You wil notice that there are lower and upper thresholds for the LEDs defined in the code. This was to ensure that the really big jumpiness that you get at the lower end (when the LED suddenly turns on) was avoided. In hindsight, it may have been better to have a threshold for each colour (R, G, B) as they seem to respond differently. However, it was good enough for me at the time and I still enjoy my little LED changer on the desk at work smiley

@Headroom - Thanks, this was the first real project I did and on the Arduino early in 2012, about 2 months after I started with the hardware. Lots of water under the bridge since then and I post most of my reasonable stuff on the site in my signature below.
488  Using Arduino / Audio / Re: Piezo MIDI Drums on: April 25, 2013, 02:47:50 am
Quote
why it doesnt work with two midi msg at the same time?

Probably because of the 5ms delay waiting for the dignal. If you hit botrh at the same time one will be registered and the other has probably disappeared by the time you have finished checking and sent the messge out the port.

To fix this you would have to rewrite the functions without delay statements. One approach may be to just remove the delay you have now and just see if that works better.
489  Using Arduino / Programming Questions / Re: Help Needed changing PID constants using a DIP-Switch on: April 23, 2013, 05:01:22 pm
THe scope of your PID object is just within the loop function. Every time the loop function ends the PID object is delected and recreated again the next time tru loop. You need to make the PID object global scope or a static variable.
490  Using Arduino / Audio / Re: Piezo MIDI Drums on: April 23, 2013, 02:49:15 pm
I have tried to simplify the code to make it easier to debug. I have created a function that does everything your code was repeating once to avoid cut an paste and make things more consistent.

Code:
#define  MAX_PIEZO  5

uint8_t piezo[MAX_PIEZO] = { A0, A2, A4, A6, A8 };
uint8_t drumType[MAX_PIEZO] = { 5, 4, 3, 2, 1 };

const int threshold = 500;  

void setup()
{
  for (uint8_t i=0; i<MAX_PIEZO; i++)
    pinMode(piezo[i], INPUT);

  Serial.begin(57600);      
}

void MidiTX(unsigned char StatusByte, unsigned char Note, unsigned char Val)
{
  Serial.write(StatusByte);
  Serial.write(Note);
  Serial.write(Val);
}

void ProcessPiezo(uint8_t p)
{
  uint16_t sensorReading = analogRead(piezo[p]);
  uint16_t  val;

  if (sensorReading > threshold)
  {
    uint32_t oldcas = millis() + 5;
    
    // this part of the code looks complex
    // explain what you are trying to do?
    while (analogRead(piezo[p]) > threshold)
    {
      if (millis() >= oldcas)
      {
        val = analogRead(piezo[p]) / 8;
      }
    }
    
    MidiTX(144, drumType[p], val);
    MidiTX(128, drumType[p], val);
  }
}

void loop()
{
  for (uint8_t i=0; i<MAX_PIEZO; i++)
    ProcessPiezo(i);
}

So the question is what do you mean by delay? How long? milliseconds, seconds, minutes?

There is a 5ms delay built into you code when you detect a value > threshold, but I imagine that you don't mean that.
Your code also used int for a millis() value instead of unsigned long, so I changed that. In some cases that could have caused delays until the counter wrapped around again.

Try what is there now, verify that you still have a problem and then give us more details.

You can also try to capture the output using the serial monitor on the computer (avoid all the MIDI) and if the message is there instantaneously, you knoew the delay is after that in the MIDI software chain on the PC.
491  Using Arduino / Project Guidance / Re: Debounce interrupt pin, pullups on, res/cap combo? on: April 23, 2013, 06:35:42 am
Page 32 doesn't have what you need? Ok.
492  Using Arduino / LEDs and Multiplexing / Re: Problem with MAX7219 on: April 22, 2013, 05:06:01 pm
You will need to post your cirtcuit and your code. If you don't have a circuit, pictures of your (breadboard?) setup would be ok.

Hard to help if we can't see what is made.
493  Using Arduino / Programming Questions / Re: Can't use function in setup on: April 22, 2013, 05:00:46 pm
The function is spelt differently. You have swapped the s and the h in the call from setup.
494  Using Arduino / Project Guidance / Re: Debounce interrupt pin, pullups on, res/cap combo? on: April 22, 2013, 04:57:38 pm
Have a look at http://arduino.cc/forum/index.php/topic,154549.0.html
495  Using Arduino / Project Guidance / Re: Magnetic rotary encoder Code on: April 22, 2013, 04:46:21 pm
Quote
Was there a question?

Actually there was no punctuation at all. I inferred a question  smiley-cool
Pages: 1 ... 31 32 [33] 34 35 ... 80