Show Posts
Pages: 1 ... 42 43 [44] 45 46 ... 274
646  Using Arduino / Programming Questions / Re: Servo project help! on: April 16, 2014, 01:12:06 am
Some comments about your code.

Code:
  if (digitalRead(pushbutton) == LOW)
    for(ppos = 0; ppos < 25; ppos += 25)  // degrees from 0 to 45
      for (mpos = 0; mpos < 90; mpos += 90)
      {                                 
        pinservo.write(ppos);    //servo to position in variable "pos"
        mtrservo.write(mpos);                     
      }
It is not immediately obvious to me what statement(s) will be executed if
Code:
  if (digitalRead(pushbutton) == LOW)
 
is true.  The statements to be executed would be better in a block with braces round them.

What is the object of
Code:
    for(ppos = 0; ppos < 25; ppos += 25)  // degrees from 0 to 45
anyway ?  What values will ppos have ?  Does the servo really move from 0 to 45 degrees ?

Similarly
Code:
      for (mpos = 0; mpos < 90; mpos += 90)
and
Code:
      for(mpos =90 ; mpos>=90; mpos-=90)

How is the pushbutton wired ?
How are the servos powered ?  Directly from the Arduino or externally ?

That will do for now I think.
647  Using Arduino / Programming Questions / Re: Need Help how to control 4 dc motors with 2 potentiometers atAdafruitMotorShield on: April 15, 2014, 04:37:04 pm
Quote
AF_DCMotor left1stMotor(1);
I was assigned " left1stMotor " as my left bottom motor at my tank project. There will be 4 motors at body.
That does not explain what the 1 refers to.

Quote
Will the result ever be greater than 127 ?
I have 1K potentiomter ( but I will get 10K one soon ) ;so with this "potentiometerValue = potentiometerValue/4; " I wanted to make smaller the value for less pot rotation with my fingers.
If it is wired correctly it will not matter if the potentiometer is 1K or 10K, the value returned by analogRead() will still be between 0 and 1023.  How is the potentiometer wired ?

Quote
//use this line or the next line but not both  , what do you mean by " next line " ? it is the bottom line that is under the " potentiometerValue = map(potentiometerValue, 0, 1023, 0, 255); " ,right ? thanks.
The map function turns a range of values between 0 and 1023 into a range of values between 0 and 255.  This effectively divides the original value by 4.  Then your next line divides the value by 4 again so the maximum value will now be 64 and can never be greater than 127.

More generally, have you tried printing the value of any of the variables in your program to see if is doing what you expect ?  Printing potentiometerValue just before you test it to see whether it is greater/less than 127 would be interesting.
648  Using Arduino / Programming Questions / Re: Need Help how to control 4 dc motors with 2 potentiometers atAdafruitMotorShield on: April 15, 2014, 11:55:15 am
It looks like you were very close with the firs program you posted.  Here it is in code tags and without the commented lines which only serve to confuse.  I have also reformatted it to make it easier to read.
Code:
#include <AFMotor.h>

int potentiometerPin = 7; // analog pin used to connect the potentiometer
int potentiometerValue; // variable to read the value from the analog pin


AF_DCMotor left1stMotor(1); // 1. motor ( Left back motor )

int i;

void setup()
{
  Serial.begin(9600); // set up Serial library at 9600 bps
  left1stMotor.setSpeed(200);
  left1stMotor.run(RELEASE);
}

void loop()
{
  potentiometerValue = analogRead(potentiometerPin); // reads the value of the potentiometer (value between 0 and 1023)
  potentiometerValue = map(potentiometerValue, 0, 1023, 0, 255);  //use this line or the next line but not both
  potentiometerValue = potentiometerValue/4;

  Serial.print("tick");
  left1stMotor.run(FORWARD);

  for (i=0; i<255; i++)
  {
    if(potentiometerValue <= 127)
    {
      left1stMotor.setSpeed(i);
      delay(10);
    }
  }
  Serial.print("tock");
  left1stMotor.run(BACKWARD);

  for (i=0; i<255; i++)
  {
    if(potentiometerValue >= 127)
    {
      left1stMotor.setSpeed(i);
      delay(10);
    }
  }

  Serial.print("tech");
  left1stMotor.run(RELEASE);
  delay(1000);
}
Note my comment about using one line or the other but not both.  The first line maps the 0 to 1023 value to 0 to 255 then the second line divides the answer by 4.  Will the result ever be greater than 127 ?

What does the 1 in this line do ?
Code:
AF_DCMotor left1stMotor(1);
Does it mean that you are using digital pin 1 ?  If so then it will conflict with Serial.print() and vice versa.
649  Using Arduino / Programming Questions / Re: Ethernet Shield using Alarms for Garduino on: April 15, 2014, 11:32:18 am
It is a safeguard to ensure that the water() function only gets called once when the time to water matches the current time.  Probably not a problem when the timing is to the second but imagine what might happen if the timing was being done only to the minute, particularly if the water() function is non blocking, which it should be.
650  Using Arduino / Programming Questions / Re: Basic question: Pin modes and enums on: April 14, 2014, 06:43:16 am
If you really want to do things that way have you tried printing the values of INPUT and OUTPUT ?
651  Using Arduino / Programming Questions / Re: Example: SerialBlinkWithoutDelay on: April 14, 2014, 01:24:49 am
Code:
  while (Serial.available())
Won't this effectively act as blocking code, albeit for a very short time ?  Whatever you are timing with millis() will have to wait until all available serial data has been processed.  Might it not be better to read just one character from serial before returning to loop() so that the millis() timing can do its stuff between serial characters ?

Also, there is an argument for implementing the millis() timing differently.  Instead of
Code:
    previousMillis = now;   
use
Code:
    previousMillis = previousMillis + BLINK_INTERVAL;   
This ensures that reacting to the interval ending remains constant even if time consuming events have occurred in the meantime.
652  Using Arduino / Programming Questions / Re: Misbehaving servo on: April 13, 2014, 04:45:47 pm
Can you provide a link to the servo that you are using ?
653  Using Arduino / Programming Questions / Re: Misbehaving servo on: April 13, 2014, 01:33:49 pm
What happens if you use a simple program (no dependence on external input) that cycles the servo between 0, 90 and 180 with a delay between the movements ?
654  Using Arduino / Programming Questions / Re: Misbehaving servo on: April 13, 2014, 09:42:09 am
How is the servo powered ?
What data type is inByte ?
What values do you see if you print inByte when serial data is available and just before writing it to the servo ?
655  Using Arduino / Programming Questions / Re: Using delays inside loop on: April 13, 2014, 08:00:58 am
Sigh....

Look at the BlinkWithoutDelay example in the IDE.
It uses the principle of noting the start time of an event then periodically checking if the required interval has elapsed.  If yes then do the next thing.  If no then do something else like reading sensors before going back to check again if the required interval has elapsed.
656  Using Arduino / Programming Questions / Re: Strange error message on: April 13, 2014, 07:54:01 am
Does anyone know at what stage this error occured ?  Does anyone know what the program was ?  Does anyone know what board was being used ?  Someone must know.  Right ? (hint)
657  Using Arduino / Project Guidance / Re: arduino and access on: April 12, 2014, 04:58:49 am
You will need something running on the PC to accept the data.  Once you have decided what that something is then you can turn your attention to the Arduino code to send the data.  Similarly the other way.

Depending on the amount and frequency of the data transfer you might like to consider saving the data to an SD card attached to the Arduino and transferring it to and from the PC using the card.
658  Using Arduino / Programming Questions / Re: CapSense Output Low? on: April 12, 2014, 01:42:56 am
You are using pin 4 as the Send pin for both sensors so you can't "turn off" one of them.

Perhaps it would be better if you explained what you are trying to achieve rather than describing what you think is the solution.  For instance, if you want one sensor to be inactive for a period of time then either don't read it or ignore the result when you do read it.
659  Using Arduino / Programming Questions / Re: CMUCAM4 Color test in Arduino on: April 11, 2014, 10:33:38 am
Have you tried searching this form for CMUCAM4 ?

I also found this on the Web with just a few clicks
http://www.cmucam.org/docs/cmucam4/arduino_api/class_c_m_ucam4.html
660  Using Arduino / Programming Questions / Re: Read analog pin on: April 11, 2014, 08:23:19 am
Are you sure that the socket that you indicate in your picture is pin A1 ?
Pages: 1 ... 42 43 [44] 45 46 ... 274