Show Posts
Pages: 1 ... 60 61 [62] 63 64 ... 84
916  Using Arduino / Programming Questions / Re: Run if (or similar) statement once on: October 27, 2012, 02:01:31 pm
dpm goes to zero because 10 divided by anything greater than 10 is zero (in integer maths). Even if the multiplication happens first you get the problem with denominator greater than 30.

I am assuming that the key presses will be at least 100ms if they are being done manually, so this calculation will probably never work as you expect.

I would consider combining the rpm & dpm calculations into one and use brackets () to control the flow of calculation so that you do not lose significant digits in the integer maths.
917  Using Arduino / Programming Questions / Re: Run if (or similar) statement once on: October 26, 2012, 11:30:12 pm
Looks to me like this statement at the top of the loop()

Code:
dpm = 3 * tooth_spacing / threepulsetimecopy; // causing problem, due to multiplying diff types

will divide by zero (at least on the first loop)?

What is the output of your program - the debug statements?
918  Using Arduino / Programming Questions / Re: Trying to use binary number (B10000) in lib and getting error. on: October 26, 2012, 11:17:43 pm
The binary numbers Bxxxxxxxx (8 digits) are defined in the headers for Arduino.

You can either expand yours to be 8 binary digits (B00010000) or just use the standard C convention 0b10000 (same way as 0x prefix would be used for hex numbers).
919  Using Arduino / LEDs and Multiplexing / Re: Help with cycling multiple LED states within modified Blink without delay on: October 23, 2012, 02:10:45 am
Look at the MultiBlink example in the Playground.

What you may want to do is defined 2 data tables and swap over which one you use to get the different patterns you are lookng for.
920  Using Arduino / Programming Questions / Re: Program doesn't loop with Serial using switch and case on: October 22, 2012, 05:30:47 am
Agree on what you say, PaulS, but the OP structured the code expecting it to block on getSerial() until it gets a number.

Short of changing the entire structure of the program, this is the easiest way to get OPs code working so that he can progress. What is there now will become a limitation later IF he needs to do other things
921  Using Arduino / Programming Questions / Re: Program doesn't loop with Serial using switch and case on: October 22, 2012, 05:20:05 am
Code:
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  int pinNumber;
  int digitalState;

  switch(getSerial())
  {
  case 1:
    {
      pinNumber = getSerial();
      digitalState = getSerial();
      Serial.print("Pin: ");
      Serial.print(pinNumber);
      Serial.print("; S: ");
      Serial.println(digitalState);

      pinMode(pinNumber, OUTPUT);
      switch (digitalState)
      {
        case 33:
          digitalWrite(pinNumber, HIGH);
          break;
         
        case 44:
          digitalWrite(pinNumber, LOW);
          break;
      }
      break;
    }
  }
}

int getSerial()
{
  int d = 0;
  int b;

  while (b != '/')
  {
    b = Serial.read();
   
    if (b == -1)  // no char available
    {
      delay(1);  // just long enough to get a char in?
    }
    else if ((b >= '0') && (b <= '9'))
    {
      d = (d * 10) + (b - '0');
    }
  }

  return d;
}

This works for me. The problem was in the getSerial() function - your tests for validity of the character received were not correct:
- What is returned by the Serial.read() when there are no characters waiting?
- You need to check if the characters read was between '0' and '9' or the formula will not work.

I have also restructured to code to be in line with more standard programming practices.

What is also clear is that if you want to be able to specify the pin number you need to set the mode to output when you know the pin number from the serial stream, not just in setup(), unless you are restricting the pin number to a few pins.
922  Using Arduino / Programming Questions / Re: Program doesn't loop with Serial using switch and case on: October 22, 2012, 04:56:14 am
And if you send 1/13/44/ nothing happens? Even if you send it as the first message?
923  Using Arduino / Programming Questions / Re: Program doesn't loop with Serial using switch and case on: October 22, 2012, 04:36:18 am
Code:
          Serial.print(" pin number ");
          Serial.print(pinNumber);
          Serial.print(" state ");
          Serial.print(digitalState);
          Serial.print("end\n");
What is your debug printout telling you?

And why are you using 'led' and not 'pinnumber' in your digital output?
924  Using Arduino / Sensors / Re: Sensor Audio on: October 21, 2012, 09:17:53 pm
You'll need to be more specific:

What sensor (link to a datasheet or website is useful)?
How have you got this in a circuit?
What software (if any) are you using?
925  Using Arduino / Sensors / Re: Modelling Temperature Sensor Delay on: October 21, 2012, 06:25:42 pm
Temperatures are slow moving inputs compared to the speed of any control devices, so the issue is not generally to predict the temperature changes but to smooth out any of the noise that happens on the input from the sensor. This is usually done by taking an average of a number of values over a set period of time and calling that the 'tempertaure'.
926  Using Arduino / Programming Questions / Re: Can someone help me update these code into 1.0.1. on: October 21, 2012, 03:02:20 am
Generally if you can get it to compile it should work like it did before, so good luck.
927  Using Arduino / Programming Questions / Re: Can someone help me update these code into 1.0.1. on: October 21, 2012, 02:08:11 am
You need to be more specific about what does not work. What was working that now does not work any more?
928  Using Arduino / Programming Questions / Re: Arduino UNO to Stepper Motor Control Box on: October 20, 2012, 01:50:04 am
Have you captured the Arduino output in the terminal program and checked that it looks right?
929  Using Arduino / Programming Questions / Re: Doing a simple calculation not working. on: October 19, 2012, 03:05:37 pm
Quote
I intended taking 20 divided by time and multiplying by 60000000 to get RPM however when I divide 20 by time I get 0

Integer maths is different from floating point maths. 20 divided by anything bigger than 20 is zero (the integer part of the float). You need to plan your calculation carefully. In this case try dividing 60000000 by time and multiplying by 20 (should be the same equation).
930  Using Arduino / Programming Questions / Re: Two things simultaneously on: October 19, 2012, 03:17:22 am
You need to post your code for proper help , however a common issue with code is the use of delay()  in the program. While the software is delaying it does nothing else.  Look at the blink without delay example in the Playground for an example on how to multitask.
Pages: 1 ... 60 61 [62] 63 64 ... 84