Show Posts
Pages: 1 ... 42 43 [44] 45 46 ... 285
646  Using Arduino / Programming Questions / Re: is it possible to replace ledPin assigning with a for statement? on: May 02, 2014, 08:29:30 am
Quote
as a newby I am keeping to the format of being able to alter the pin assignments at the start of the program.
That's exactly what putting the LED pin numbers in an array lets you do.
Suppose your first thoughts are to use pins 2 to 13 for the 12 LEDS.  You define this in the global array at the start of the program like this
Code:
const byte ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
and set their pinMode to OUTPUT like this
Code:
const byte ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};

void setup()
{
  for (int i = 0; i < 12; i++)
  {
    pinMode(ledPins[i], OUTPUT);
  }
}
Later on, if you decide to use the LED pins in a different order, or use different pins because it makes wiring easier then all you need to do is to change the pin numbers in the array and the for loop will take care of itself.
Code:
const byte ledPins[] = {3, 2, 4, A1, 6, 7, 8, 9, A0, 11, 12, 13};

void setup()
{
  for (int i = 0; i < 12; i++)
  {
    pinMode(ledPins[i], OUTPUT);
  }
}
The rest of your program does not need to be changed because a reference to ledPins[2], for instance, will always refer to the third LED no matter what its pin number actually is.

647  Using Arduino / Project Guidance / Re: Motor Shield's Power 'Leaking' on: May 02, 2014, 08:10:28 am
If you want to you can just add a link to the pictures rather than adding the pictures themselves but it is not a picture of the shield that we need, rather details of how you have your motors and power supplies connected.
648  Using Arduino / Project Guidance / Re: Motor Shield's Power 'Leaking' on: May 02, 2014, 05:18:19 am
Im my experience here diagrams, even hand drawn, are better than photos.
649  Using Arduino / Project Guidance / Re: Motor Shield's Power 'Leaking' on: May 02, 2014, 04:17:25 am
Please post diagrams showing the connections in both cases and the program that you are using.
650  Using Arduino / Project Guidance / Re: Project coding Question on: May 02, 2014, 04:15:52 am
delay() "does what it says on the tin"  it delays the program until the delay is over. 

So, you want to run 2 motors at random speeds and directions.  You start motor 1 and delay() for a random time.  Nothing else happens until the delay() is over so how do you start/stop motor 2 ?

The BlinkWithoutDelay example in the IDE shows how to use millis() to get the current time since the Arduino started and compare it with the elapsed time since an action, such as starting a motor, began.  Only if the elapsed time exceeds the required period does the code do anything else, so it can move on to check other (different) elapsed times.

Code:
start motor1
save startTime1
define period1
start motor2
save startTime2
define period2

start of loop
  if millis() - startTime1 >= period1
    stop motor1
    //other actions such as starting motor 1 again etc
  end if
 
  if millis() - startTime2 >= period2
    stop motor2
    //other actions such as starting motor 2 again etc
  end if
end of loop
Code like this runs freely instead of stalling as it would using delay().  The actions when the periods elapse are up to you but if you start a new timed period remember to save the new start time.
651  Using Arduino / Programming Questions / Re: House Garrage door Project (coding concepts question) on: May 02, 2014, 02:54:08 am
You started by describing a garage door being left open, now you are talking about a shed.
Confused ?  I am.
652  Using Arduino / Programming Questions / Re: Error from basic Servo Sweep example on: May 02, 2014, 02:45:23 am
Which Arduino are you using and does it match the board selected in the IDE ?
653  Using Arduino / Programming Questions / Re: Basic Interrupt Question on: May 01, 2014, 12:48:03 pm
Are you planning on using an interrupt because you want to understand how they work or because you think you need an interrupt to do what you want ?
654  Using Arduino / Project Guidance / Re: Project coding Question on: May 01, 2014, 09:56:48 am
Quote
I have run the program and it worked running the motor forward faster then at its peak slows it down again till it goes into a reverse direction and repeats this.
Good, because that is what it is supposed to do.  Do you understand why/how it works ?  Did you try changing the program in any way to make it do something different or the same thing but slower or faster maybe ?

By experimenting like this by changing code that works you will understand better what is possible and how.  If an experiment does not work then try to work out why and try again.  You want motors to speed up and slow down at a random rate.  What is it about the program that controls the rate of speeding up and slowing down ?  Can you change it ?  Can you make it random ?

At some point you will need to stop using the delay() function but that can come later.
655  Using Arduino / Project Guidance / Re: Project coding Question on: May 01, 2014, 04:25:53 am
This is like pulling teeth.
Have you run that program and did it do anything ?
656  Using Arduino / Project Guidance / Re: Is There Any Simple Way To Combine Sketches? on: May 01, 2014, 03:58:36 am
Two programs cannot run independently on the Arduino as it is not a multi-tasking environment.  You can have two things appear to happen at once by making them happen very soon after one another and/or you can do things like monitoring the output of two (or more) sensors sequentially and get the same effect.

What two programs did you have in mind to use at the same time ?
657  Using Arduino / Project Guidance / Re: Project coding Question on: May 01, 2014, 03:55:01 am
Ok I have Considered your questions and thinking how I missed those details but to the point...

2 motors will be close to each other and what I want them to do is spin in one direction (both in the same direction at same speed mayby one delayed from the other by 1 or 2 sec) slowly and then work faster then slower, stopping every now and then at a random rate. The motor shield will run 4 dc motors at 3v to 36v and can handle the current of the motors. The shield can also run 2 stepper motors and 2 servos if desired and that I wont be needing in this anyway.

Thanks for the help I really appreciate it

sincerely,

Matthew
Very interesting, but what about the questions I asked ?
Put more simply, have you managed to get a motor running using the motor shield ?  Is there any sample code associated with the motor shield that you could use ?
658  Using Arduino / Project Guidance / Re: Project coding Question on: May 01, 2014, 01:21:44 am
What have you managed to do using the motor shield ?

Run one motor forward and reverse ?
Run one motor forward and reverse fast and slow ?
Run two motors forward and reverse ?
Run two motors forward and reverse fast and slow ?
Any of the above ?
659  Using Arduino / Programming Questions / Re: error: expected unqualified-id before numeric constant on: April 30, 2014, 02:43:50 pm
Is that really your whole program ?
660  Using Arduino / Programming Questions / Re: xor 'ing something longer than a byte ? on: April 30, 2014, 10:46:07 am
Is XOR limited to bytes, I ask myself, or can it be used with any unsigned integer ?
Code:
unsigned int a = 0b0100000000000000;
unsigned int b = 0b1000000000000000;

void setup()
{
  Serial.begin(115200);
  Serial.println(a ^ b, BIN);
}

void loop()
{
}
Pages: 1 ... 42 43 [44] 45 46 ... 285