Show Posts
Pages: 1 ... 381 382 [383] 384 385 ... 590
5731  Using Arduino / Programming Questions / Re: Function destroying information on: April 03, 2012, 08:29:33 pm
You are running off the end of your array:
Code:
const int ARRAY_LENGTH = 50;

float knockTimes[ARRAY_LENGTH];
float knockDelays[ARRAY_LENGTH-1]; 
float knockRatios[ARRAY_LENGTH-1];  // Elements 0-48
int knocks;
int knockCounter;

void getKnockRatios(float *delayArray, float *ratioArray, int knockCounter) {
  // Finds the ratio of the knocks relative to the first delay.
  // This allows the knock sequence to be tempo independent.
 
  for (int i = 0; i < knockCounter-1; i++) {
    ratioArray[i] = delayArray[i] / delayArray[0];
  }
//  for (int j = knockCounter-1; j < ARRAY_LENGTH; j++) {   // Remove any extra delays from previous knock. THIS IS WHERE THE PROBLEM IS.
//    ratioArray[j] = 0;   ///////  When j reaches 49 (ARRAY_LENGTH-1) this overwrites your counts
//  }
5732  Using Arduino / Sensors / Re: How to make a coin selector for Making a piggy bank? on: April 03, 2012, 08:20:44 pm
A piggy bank is usually a container with a slot in the top.  I'm guessing that you want some way to determine the value os a coin being pushed into a coin slot.  I think the cheap toys use a spring-loaded arm that turns a pot and the peak value of the pot is a rough measure of coin diameter.
5733  Using Arduino / Programming Questions / Re: Can I get 5 V output at an analog Pin? on: April 02, 2012, 10:58:16 am
Code:
pinMode(A3, OUTPUT);
digitalWrite(A3, HIGH);
5734  Using Arduino / Microcontrollers / Re: ArduinoISP not working! on: April 02, 2012, 10:55:14 am
In Arduino 1.0 the serial buffer size has been reduced.  This causes failures in the ArduinoISP sketch.  One work-around is to reduce the baud rate in the ArduinoISP sketch and in the programmers.txt file.
5735  Using Arduino / Project Guidance / Re: Wireless detection of vehicle lock movement on: April 02, 2012, 10:46:00 am
You might be able to use a "wireless doorebell".  Put the bell in your bedroom and mount the button in the door such that it will be pressed when the lock is opened.  If you have the doors locked when you are driving and parked the battery in the button unit should last a good long time.

Does your care have a keyless entry system that opens the windows if you hold the button down?  Accidental pressing of the button could explain most of the symptoms you see.
5736  Using Arduino / Motors, Mechanics, and Power / Re: Motor Speed Control on: April 02, 2012, 10:28:26 am
Code:
void setup()
{
  Serial.begin(9600);       // start the serial port
  pinMode(pwm_a, OUTPUT);  //Set control pins to be outputs
  pinMode(pwm_b, OUTPUT);
  pinMode(dir_a, OUTPUT);
  pinMode(dir_b, OUTPUT);
 
  analogWrite(pwm_a, 80);  //set both motors to run slow
  analogWrite(pwm_b, 78);  // Motor B runs a little faster than Motor A so apply a little less power
  lastState = state = STATE_FORWARD;
}
5737  Using Arduino / Motors, Mechanics, and Power / Re: Motor Speed Control on: April 01, 2012, 08:13:42 pm
PWM (analogWrite()) only sets the proportion of time the motor gets power.  The characteristics of the motor and load determine how fast the motor goes with that input power.  To get any sort of precise speed control you need feedback.  You need some way to measure the speed and adjust the power to get the speed you want.

You might be able to get close by adding a fudge factor to one motor's control input and manually adjusting that fudge factor to get closer to equal speed on the two motors.
5738  Using Arduino / Project Guidance / Re: LM35 temperature equation? on: April 01, 2012, 02:21:29 pm
Also one more thing I found about the sensor says that " No matter what supply you use, the analog voltage reading will range from about 0V (ground) to about 1.75V." for LM35. I would like to know why that is if anyone knows.

1.75v = 1750 mV = 175°C  The LM35 is only good to 150°C so outputs above 1.5V (1500 mV) can't be relied on.

http://www.ti.com/lit/ds/symlink/lm35.pdf
5739  Using Arduino / Programming Questions / Re: Why is Serial.parseInt() so slow? on: March 31, 2012, 10:07:20 pm
Enter a number value such as 3 (with "No line ending" selected in the serial monitor) to see the sketch delay before getting the 3 value, but then use the value correctly. Enter a value such as "3x" (with or without a line ending) to see the sketch pick up the 3 value instantly but then after a delay receive a 0 value.

You call parseInt() and it sees the 3, starts to accumulate digits and knows it is done when it sees a non-digit (x) coming.  It returns the 3.

You call parseInt() again and it sees the 'x'.  Probably throws it away and waits for a digit to arrive.  After a second it has no new input so it returns 0.

After each parseInt() you should check the serial buffer (.available()) and read the terminating character.  You can turn on linefeed (newline) terminators and check that the terminating character is '\n'.  If it isn't you have detected an input error and can ignore the number.
5740  Using Arduino / Programming Questions / Re: long ISR on: March 31, 2012, 09:58:11 pm
You can re-enable interrupts in your ISR to allow other background operations to happen.  That should not cause a problem unless the current ISR takes longer than the interrupt interval that triggers it.  Does the interrupt ever happen again in less than 100 microseconds?
5741  Using Arduino / Microcontrollers / Re: using the onboaurd 8/16u2 as isp? on: March 31, 2012, 09:52:21 pm
Well, you'd need an ISP to re-write the firmware in the 8U2.  You'd also loose serial communication with the USB host unless you could fit both the ArduinoISP sketch and the USB-to-Serial firmware.  You would need separate firmware for the 386 and 2560 since the 2560 is too big for the STK500V1 protocol and  needs STK500V2.

Aside from all those limitations it would allow you to download sketches without using some of the main processor memory space for a bootloader.
5742  Using Arduino / Programming Questions / Re: Compiler error? A delay is needed to work on: March 31, 2012, 08:54:49 am
Code:
  do    
       if (Serial.available()>0) {
          recive[i]=Serial.read();          
          i=i+1;          
          recive[i]='\0';
          empty_port=true;
          //delay(2);  //try coment and uncoment this line  <-------------------------------------------------------------------- HERE!!!
       }
       else {
         empty_port=false;          
       }
   while (empty_port==true);
  

The reason you need the delay() is that you are reading until you get ahead of the sender, not until you read a character that indicates the end of input.  Without the delay you are reading faster than the sender is sending and get ahead of the sender before the transmission is complete.
5743  Using Arduino / Programming Questions / Re: using multiple pages in the ide on: March 31, 2012, 08:48:31 am
You could make each page a .h file and include them all in the main sketch.
5744  Using Arduino / Programming Questions / Re: Servo.h not behaving as i expect on: March 31, 2012, 06:45:44 am
You forgot to show where servo1 and servo2 are created.

You seem to be using pins 1 and 2 for your leg servos.  Are you not using Serial?  Serial uses pins 0 and 1.
5745  Using Arduino / Sensors / Re: PulseIn timeout reading a proximity Sensor on: March 30, 2012, 05:37:39 pm
I believe it has to do with how the function is declared out in the wiring.h file from what I have read.

The declarations look fine in Arduino 1.0.  What version are you using?
Pages: 1 ... 381 382 [383] 384 385 ... 590