Show Posts
Pages: 1 [2] 3 4 ... 268
16  Using Arduino / Programming Questions / Re: Servo Code Double Check on: July 18, 2014, 02:36:20 am
Judging by the voltages that you mentioned the servo is being supplied 5V from the Arduino.  If so that is not a good idea because the servo can easily take more current than the Arduino voltage regulator can supply.  Consider powering the servo from an external supply but don't forget to connect the two grounds.
17  Using Arduino / Programming Questions / Re: Run loop one time? on: July 18, 2014, 01:43:10 am
Look at the state change detection example in the IDE.  You need to trigger the sound when the PIR becomes LOW, not when it is LOW.  All this involves is checking its current state against it previous state and acting if it has changed and is now LOW when previously it was HIGH.
18  Using Arduino / Programming Questions / Re: Void Setup on: July 17, 2014, 07:18:07 am
A function can have almost any name as long as it does not contain spaces or punctuation.

It is good practice to give functions meaningful names that indicate what they do and the use of 'camelCase' for names is common.  So you will see functions such as digitalWrite(), pinMode() etc built into the Arduino environment and you can write your own to do common tasks and/or make program maintenance easier. 

The myFunction() used in previous replies was only an example.  It could just have well been called wibble() for all the IDE cared !
19  Using Arduino / Programming Questions / Re: PWM Pins 9 and 10 on Uno on: July 17, 2014, 07:09:32 am
In your program you attach the servo only in setup(), which is the correct place but that means that you cannot use pins 9 and 10 for PWM output as I suspected..  Did you choose which pins to use for which purpose or are you using a motor shield which requires certain pins to be used ?

It may still be possible to use pins 9 and 10 but that would require the servo object to be detached before using them and attached again afterwards which sounds very messy.  You could do yourself a favour and put the analogWrite() commands in a function along with the servo detach and subsequent servo attach then call the function when required.

On the whole, using other pins would be the best solution although there is an alternative servo library (ServoTimer2) that allows PWM on pins 9 and 10
20  Using Arduino / Programming Questions / Re: Switch Control on: July 17, 2014, 12:52:27 am
Quote
if the while loop condition is not fulfilled, it will read the switch value again and again till it is satisfied.
That's better.  Now the while loop can end, whereas before it never, could so the program would stall.
21  Using Arduino / Programming Questions / Re: Game of Life generation not being pushed to 16x32 LED matrix on: July 16, 2014, 03:09:48 pm
An array of booleans usea half as much memory as an integer array.

As a test as to whether memory is the problem, how about reducing the size of the array to say 8 by 8 initially ?
22  Using Arduino / Programming Questions / Re: Void Setup on: July 16, 2014, 07:23:28 am
Try this
Code:
void setup()
{
  Serial.begin(115200);
  int theAnswer = multiplyFunction(4, 5);
  Serial.println(theAnswer); 
 
  Serial.println(multiplyFunction(11, 555));
}

void loop()
{
}

int multiplyFunction(int x,int y) {    // x & y are declared as integers.
  int result = x * y;
  return result;                    //returns the value where it is called
}
The value in the result variable in the function is returned (made available) to the code that called the function.  It does not have to be put into a variable but can be used directly as in the second example above.

setup() and loop() don't, in normal use, have a program calling, them so cannot return a value, hence their return type is void.
23  Using Arduino / Programming Questions / Re: Strange Interrupt Behaviour on attach on: July 16, 2014, 07:11:53 am
Code:
attachInterrupt(1, vibration1, FALLING); //doesn't work. Triggers interrupt routine instead.
Quote
This is a strange comment. I always thought the purpose of attachInterrupt was to trigger an interrupt routine.
Surely the act of attaching the interrupt should not actually trigger it though, merely make it possible to trigger the interrupt when the interrupt pin state changes.
24  Using Arduino / Programming Questions / Re: #define, int or const int on: July 16, 2014, 04:47:07 am
Note that
Code:
#define ledPin = 13
is not correct.  Unless, that is, you really want the pre-processor to replace all instances of ledPin with = 13, which is unlikely
25  Using Arduino / Programming Questions / Re: Game of Life generation not being pushed to 16x32 LED matrix on: July 16, 2014, 03:01:14 am
Which Arduino are you using ?

I have not looked at your code in detail but you have 2 arrays of booleans, each 18 by 34.  That is going to take over 1200 bytes so you may have a problem with lack of memory.

It would be much more efficient in terms of space to pack the data into bits rather than bytes.
26  Using Arduino / Programming Questions / Re: Programme stuck in setup on: July 15, 2014, 12:36:08 pm
Define what you mean by more powerful

More memory ?
Faster processor ?
More pins ?
More than one hardware serial port ?
etc, etc
27  Using Arduino / Programming Questions / Re: Programme stuck in setup on: July 15, 2014, 11:14:30 am
My best guess would be that you are running out of memory which will not be helped by the extensive use of String objects as opposed to C style strings.  As a first test reduce the length of hdrstr to a single character.  Do you get any different results ?
28  Using Arduino / Programming Questions / Re: Problem with 433Mhz rf link code on: July 15, 2014, 11:06:24 am
Code:
Serial.print((char)buf[i]);
29  Using Arduino / Programming Questions / Re: Problem with 433Mhz rf link code on: July 15, 2014, 07:55:51 am
You are getting the Hex value of the ASCII code for the letters.  No surprise really when you print the data using
Code:
    Serial.print(buf[i], HEX);
from a buffer defined as being an int rather than a char.
Code:
    uint8_t buf[VW_MAX_MESSAGE_LEN];
30  Using Arduino / Programming Questions / Re: Strange Interrupt Behaviour on attach on: July 15, 2014, 07:26:27 am
Code:
void vibration1() {
  vibration1Timer = millis();
  detachInterrupt(1);
}
Interrupts are automatically disabled when an ISR is triggered and enabled when the ISR has run.  The latter may be causing interrupts to be enabled at the end of the ISR.

Quote
The full sketch is quite long and take about 2 seconds to go through the loop
What is it that causes it to take 2 seconds each time through the loop() function ?

Without seeing what else your program does it is difficult to tell, but it is quite possible that you do not need to use an interrupt at all.
Pages: 1 [2] 3 4 ... 268