Show Posts
Pages: 1 ... 72 73 [74] 75 76 ... 147
1096  Using Arduino / Programming Questions / Re: Interrupt question on: April 23, 2013, 08:23:09 am
Quote
is it possible to interrupt an interrupt routine
No, it is not.

By calling 'sei' an interrupt can be re-entrant or interrupted. However there are concerns regarding an interrupt being entered more times than exited causing a stack overflow. Timing needs to be precise, interrupts firing at random times may be something to avoid with re-entrant code; whereas interrupts with a pre-determined or minimum time between manifestations will provide a stable time slice for a previous call to finish as the AVR has a deterministic execution.

Visit the link in my signature for a comprehensive atomic control solution.
1097  Using Arduino / Programming Questions / Re: Compiler getting flaky on: April 20, 2013, 07:01:46 pm
Clicking compile or upload while the IDE is already compiling or uploading will cause this error. I have done this a few times by accident, sometimes it uploads, sometimes it dies in a spew of java exceptions.

I wish there was a 'clean' button for helping this problem ( IDE doesn't seems to clean up temp dirs on exit either, leaving thousands of files after a few days of use ), I have also had AVR apps conflicting with includes from ARM apps when the IDE uses the same temp folder for upload.
1098  Using Arduino / Storage / Re: interface both the SD CARD MODULE and LCD display to arduino ? on: April 19, 2013, 05:38:00 am
Good post, Leaving the fix is nice. I'm sure someone will eventually find this thread looking for the same answer.
1099  Using Arduino / Programming Questions / Re: How to use a variable from a different scope on: April 19, 2013, 05:34:05 am
'x' is global so you can access it anywhere in the file, you can't access 'y' cos its local to setup()
What is the problem? You can just make 'y' global if you really need it 'global'.
1100  Using Arduino / Storage / Re: interface both the SD CARD MODULE and LCD display to arduino ? on: April 18, 2013, 09:12:41 pm
As the SD card needs the SPI, can you move the LCD to other pins, do you have a shield or wires?

I'm sure the LCD code can be modified to change the pins ( unless its SPI also ).

EDIT: Just had a look at the LiquidCrystal library, the pins are set in the constructor so it should be an easy fix if you have spare pins ( and aren't using a shield )

You only need to change pins 4, 11, and 12 according to your pinout lists.
1101  Using Arduino / Programming Questions / Re: Must Arduino libraries be object-oriented? on: April 18, 2013, 08:47:41 pm
There is no need, here is a post I made the other day: http://arduino.cc/forum/index.php/topic,104447.msg1205867.html#msg1205867
There are other posts there that might be useful too.
 
1102  Using Arduino / Programming Questions / Re: enum and switch cases on: April 18, 2013, 08:02:27 pm
Quote
cannot convert "char*" to "clr" in initialization

Is that really what it said?
Seems more appropriate to say the actual type mismatch:
Quote
cannot convert "char*" to "Color" in initialization

If arg was an int or char, I would suggest casting the value, but char* is pretty incompatible.

Code:
Color clr = ( Color )( unsigned int ) arg;
1103  Using Arduino / Programming Questions / Re: newby help on: April 18, 2013, 08:30:38 am
Static variables inside a function hold their value between calls to that function.
They can also be given a starting value.

Code:
void loop()
{
static char lastState = !switch1;

if( lastState != switch1 ){

  lastState = switch1;

  if (switch1 == HIGH){
    Serial.println("switch open");
  }else{
    Serial.println("switch closed");
  }
}

}
1104  Using Arduino / Programming Questions / Re: can i include .ino or pde files? on: April 18, 2013, 12:48:24 am
Arduino.h would only be required if you use any of the standard arduino core stuff like 'byte' and digitalRead.
1105  Using Arduino / Programming Questions / Re: use of main() in arduino IDE on: April 17, 2013, 11:16:45 pm
Quote
I'm going to go look up that init() you mentioned.  maybe that is what is configuring my timers differently ?

Yeah it does do some things, it is in wiring.c

Here is the timer1 stuff:
Code:
// timers 1 and 2 are used for phase-correct hardware pwm
// this is better for motors as it ensures an even waveform
// note, however, that fast pwm mode can achieve a frequency of up
// 8 MHz (with a 16 MHz clock) at 50% duty cycle

#if defined(TCCR1B) && defined(CS11) && defined(CS10)
TCCR1B = 0;

// set timer 1 prescale factor to 64
sbi(TCCR1B, CS11);
#if F_CPU >= 8000000L
sbi(TCCR1B, CS10);
#endif
#elif defined(TCCR1) && defined(CS11) && defined(CS10)
sbi(TCCR1, CS11);
#if F_CPU >= 8000000L
sbi(TCCR1, CS10);
#endif
#endif
// put timer 1 in 8-bit phase correct pwm mode
#if defined(TCCR1A) && defined(WGM10)
sbi(TCCR1A, WGM10);
#elif defined(TCCR1)
#warning this needs to be finished
#endif
1106  Using Arduino / Programming Questions / Re: use of main() in arduino IDE on: April 17, 2013, 10:52:52 pm
using main overrides the internal main.

It also calls a function named init() that also sets up timers and PWM.

So your 1st and 2nd codes override it and setup/loop aren't even called in the 2nd code.

the 3rd uses the default main, sets up the timers, then you make further changes using mainx.

EDIT: main is the program entry point, the Arduino default calls init(), then setup(), then calls loop() in a never ending loop.
1107  Using Arduino / Programming Questions / Re: can i include .ino or pde files? on: April 17, 2013, 09:56:46 pm
I too would like to be able to take say a dozen (maybe or maybe not unrelated) short C functions I've created and somehow turn them into a simple library that I could include into a sketch when desired. So if someone does have some simple examples to accomplish that I be most interested in seeing it.

Lefty

You can use namespaces for this job, here is a mockup FFT library:

FFT.h
Code:
#include "complex.h"

namespace FFT{
//   FORWARD FOURIER TRANSFORM
bool Run(const complex *const Input, complex *const Output, const unsigned int N);
bool Run(complex *const Data, const unsigned int N); //INPLACE VERSION

//   INVERSE FOURIER TRANSFORM
bool Inverse(const complex *const Input, complex *const Output, const unsigned int N, const bool Scale = true);
bool Inverse(complex *const Data, const unsigned int N, const bool Scale = true); //INPLACE VERSION
};

FFT.cpp
Code:
#include "FFT.h"

namespace FFT{

//   FORWARD FOURIER TRANSFORM
bool Run(const complex *const Input, complex *const Output, const unsigned int N)
{
return true;
}

bool Run(complex *const Data, const unsigned int N) //INPLACE VERSION
{
return true;
}
//Left out Inverse functions.
};

Client Code
Code:
#include <FFT.h>

void loop(){

  Complex c_Data[ 512 ];
  //... Fill with data.

  //Use library
  FFT::Run( c_Data, 512 );

}
1108  Using Arduino / Programming Questions / Re: enum member of a class on: April 17, 2013, 09:13:17 pm
For non-static members of a class, this is not initialising, its assigning.
Code:
valve::valve()
{
    _state = opening;
}

This is initialising:
Code:
valve::valve() : _state( opening )
{ return; }
1109  Using Arduino / Programming Questions / Re: length of multidimensional array? on: April 17, 2013, 12:19:20 am
Never needed to know that value, but here is how I would do it in C++:
Code:
template< typename T, size_t A, size_t N >
  inline const size_t sizeofMArray( T (&)[A][N], const char item ) { return item ? A : N; }

Tested with this code:
Code:
    Serial.begin( 9600 );
    Serial.println( sizeofMArray( zone1, 0 ) );
    Serial.println( sizeofMArray( zone1, 1 ) );
    Serial.println( sizeofMArray( zone2, 0 ) );
    Serial.println( sizeofMArray( zone2, 1 ) );
    Serial.println( sizeofMArray( zone3, 0 ) );
    Serial.println( sizeofMArray( zone3, 1 ) );

Gives this output.
Quote
3
6
3
7
3
4

Do what WizenedEE said and use the global variable, then this code in your function.
1110  Using Arduino / Programming Questions / Re: can you see what I am doing wrong? on: April 16, 2013, 07:40:31 pm
What pin are you setting high, http://arduino.cc/forum/index.php/topic,160932.msg1204291.html#msg1204291

There is a difference between pin numbers and pin values You are comparing a pin number with HIGH, completely illogical,
just remove the 'if' dang nabbit, the pin is high cos you set it high, there is no need to assume it has changed unless you typed the code below inside an interrupt.

Code:
digitalWrite(b1yel1, LOW);

Pages: 1 ... 72 73 [74] 75 76 ... 147