Show Posts
Pages: 1 ... 49 50 [51] 52 53 ... 152
751  Using Arduino / Programming Questions / Re: How to undo a flipped state? on: January 20, 2014, 02:30:46 am
Stealing code that doesn't work is not very productive.
752  Using Arduino / Project Guidance / Re: how put a goal to the arduino to reach it on: January 19, 2014, 05:21:38 pm
Code:
Goal goal;
Thingy thingy;
goal.setGoal(thingy, 60000000UL / 3000);
goal.goalReached(thingy.stop());

Javascript background??

Code:
goal.goalReached( thingy.stop );
Or
Code:
goal.goalReached( &thingy.stop );
753  Community / Exhibition / Gallery / Re: Presenting the ATTinyest of ATTinys. The ATTiny4. on: January 19, 2014, 05:18:00 pm
Nice job. It look like you've had flames shooting out of the power connector  smiley.
754  Using Arduino / Programming Questions / Re: Is there such a thing as fast Serial.println? on: January 19, 2014, 07:40:00 am
Quote
If you forget to turn interrupts back on Serial will stop sending and also loose data once the buffer is full.
No, it won't. It will block waiting for room in the outgoing buffer. Of course, that will never happen, since room is made only by interrupts happening to shift data out, making room, and interrupts won't happen with interrupts disabled. So, the Arduino will hang.

Yeah I forgot that part, however the hang will only occur if the buffer is filled. I've had an app work fine, but no serial output until I intentionally sent large strings of frustration.
755  Using Arduino / Programming Questions / Re: IPAdress definition not found, inclusion error, how to solve it. on: January 19, 2014, 07:27:13 am
IPAddress, not IPAdress
756  Using Arduino / Programming Questions / Re: Discrepancy in ATmega32 manual on: January 19, 2014, 07:20:59 am
No worries smiley, That is what I wrote it for!

The hardware automatically zeros the memory on reset, the registers are at the beginning of the SRAM addressing scheme and get zeroed too.

Its good as it leaves the controller in a known state. Imagine your throttle speed in your car resetting to a random high speed. If the programmers forget to default every variable the device could potentially cause harm.

The init function does quite a lot. Browse to your arduino setup and find the core:

arduino-1.0.5\hardware\arduino\cores\arduino
or the beta
arduino-1.5.2\hardware\arduino\avr\cores\arduino

open wiring.c
757  Using Arduino / Programming Questions / Re: Discrepancy in ATmega32 manual on: January 19, 2014, 06:01:06 am
If you use setup/loop with out a custom main, then init() is called, it contains:

Code:
sbi(TCCR0B, CS01);
sbi(TCCR0B, CS00);

http://arduino.genx.biz/FAQ/content/2/2/en/can-i-use-int-main-with-arduino.html
758  Using Arduino / Project Guidance / Re: can we replace the delay by an if on: January 19, 2014, 03:50:41 am
Code:
delay (someCondition ? trueDelayTime : falseDelayTime); 

I was holding back from posting that for the same reasons given by Jimbo above. Hell might as well just post:

Code:
  struct LongDelay{
    enum{ TIME = 1000 };
  };
 
  struct ShortDelay{
    enum{ TIME = 50 };
  }; 
 
  template< bool flag, typename T, typename U >
    struct Select { typedef T Result; };
   
  template< typename T, typename U >
    struct Select<false, T, U> { typedef U Result; };
   
 
  delay( Select< condition, LongDelay, ShortDelay >::Result::TIME );
 
759  Using Arduino / Project Guidance / Re: can we replace the delay by an if on: January 19, 2014, 03:29:59 am
Are you after control of the delay time only:

Code:
int delay_time;

if( condition ){
  delay_time = 1000;
}else{
  delay_time = 50;
}

delay( delay_time );

I suspect writing this is in vain, the OP will be onto the next thread soon.
760  Using Arduino / Programming Questions / Re: Is there such a thing as fast Serial.println? on: January 19, 2014, 03:03:42 am
use Serial.write( ptr, len ); for a slight speedup.

Most of serial's work is done in interrupts. If you want to time your loop properly disable interrupts for the portion of code in test. This will prevent serial from clearing its buffers while your critical code is running. This is useful if you have a portion of code that must run uninterrupted smiley-razz.

If you forget to turn interrupts back on Serial will stop sending and also loose data once the buffer is full.

The library linked in my sig makes it easy.
Code:
{
  AtomicBlock< Atomic_RestoreState > a;

  //Code here is protected from interrupts.
}
//Code here is not protected.
761  Using Arduino / Project Guidance / Re: how to use true and false on: January 19, 2014, 02:39:53 am
Please go read this:  http://www.cplusplus.com/doc/tutorial/ and don't stop for a while,... please.
762  Using Arduino / Programming Questions / Re: does it work on: January 19, 2014, 02:13:46 am
The code which is extremely sparse will work if:

  • The variables are properly declared.
  • The assignments are placed somewhere within a function.
  • Each statement is terminated with a semi colon.

However the assignments to elapsedTime overwrite each other, timeneed is effectively not used and elapsedTime == bestime, which is the same as just writing:

Code:
elapsedTime = 0.0004;
763  Using Arduino / Programming Questions / Re: does it work on: January 19, 2014, 02:02:57 am
Yes if its pseudo code.
No if its real code.
764  Using Arduino / Programming Questions / Re: does it work on: January 19, 2014, 01:59:31 am
Really?

You have started a few topics now, the last one I answered you did not respond to anyone. Now this question is as pointless as tits on a bull.
I'll ask one too, why do dogs have cold noses?
765  Using Arduino / Programming Questions / Re: How to undo a flipped state? on: January 19, 2014, 01:27:55 am
Referring to my previous post  ( http://forum.arduino.cc/index.php?topic=211624.msg1552570#msg1552570 )

Code: (wrong)
digitalRead( BTN_01 == LOW )

I do not think this is what you want.

I'm pretty sure you want to: Read the value of BTN_01 and compare it to the value LOW.

To achieve this you need to put the comparison on the outside of the function call, otherwise you only read pin 0 or 1*, not BTN_01 or BTN_05 due to the way boolean values translate to integers.

Code: (correct)
digitalRead( BTN_01 ) == LOW

* True values are anything other than zero, so it may not be 1, and could be regarded as possibly random.

Pages: 1 ... 49 50 [51] 52 53 ... 152