Show Posts
Pages: 1 ... 102 103 [104] 105 106 ... 113
1546  Using Arduino / Programming Questions / Re: Sleep Tutorial problem on: January 13, 2012, 02:13:14 pm
Can't remember where I found this, but works for me with V1.0 on a Duemilanove.

Code:
#include <avr/sleep.h>      // powerdown library
.
.
.

//***************************************************
// *  Name:        enterSleep
  /* the sleep modes
   SLEEP_MODE_IDLE - the least power savings
   SLEEP_MODE_ADC
   SLEEP_MODE_PWR_SAVE
   SLEEP_MODE_STANDBY
   SLEEP_MODE_PWR_DOWN - the most power savings
   */
void enterSleep()
{
      set_sleep_mode(SLEEP_MODE_PWR_DOWN);
      cli();
      sleep_enable();
      sei();
      sleep_cpu();
      sleep_disable();
}

Pete
1547  Using Arduino / Programming Questions / Re: if (-1 > 4) evaluates to true? on: January 13, 2012, 12:06:37 pm
In that case "byte" can represent numbers from 0 to 255. "int" can represent numbers in the range -32768 to +32767.
And here you run into another problem. Not only is there an unsigned/signed mismatch but the size of the datatypes is different. A byte is only 8 bits whereas the int is 16-bits. Again the compiler has to make a decision about what to do in this case and since a signed int can comfortably represent the entire range of 0-255, it presumably "promotes" the unsigned byte to signed and away it goes.

Pete
1548  Using Arduino / Programming Questions / Re: Someone help me debug this Arduino program? on: January 13, 2012, 12:01:55 pm
You are running random separately for each player which probably isn't the right way to do it.

And you have to initialize the player counts to zero

int player1 = 0, player2 = 0 , .....

You'd probably be better off using an array for the player counts.

Pete
1549  Using Arduino / Programming Questions / Re: if (-1 > 4) evaluates to true? on: January 13, 2012, 11:55:30 am
As I said, if by "byte" you mean "char" (or do you mean the old byte keyword in 0023 and earlier?) then it is signed, so a byte containing -1 will be less than an int containing +4.
I don't know offhand of a source which explains this well.

Pete
1550  Using Arduino / Programming Questions / Re: Inverting Shift Register outputs in Arduino IDE. on: January 13, 2012, 11:49:04 am
Cross posted. (in Displays).

Pete
1551  Using Arduino / Displays / Re: Inverting Shift Register outputs in Arduino IDE. on: January 13, 2012, 11:47:00 am
Quote
As you can see Hex 0x11 means 00010001
Nope, I don't see. The binary pattern for 'A' is 01000001 which inverted is 10111110.
If you want to invert everything, all you have to do is exclusively OR it with 11111111 (= 0xFF).
I think this will compile (not tested):
Code:
shiftOut(dataPin, clockPin, MSBFIRST, 'A' ^ 0xFF );

Pete
1552  Using Arduino / Programming Questions / Re: Using ardunio as a time delay relay on: January 13, 2012, 11:37:58 am
Quote
Does it look right?
No. 30000 milliseconds is 30 seconds - not 5 minutes.

But, you need to get an Arduino and debug this yourself - you will learn much more that way than being spoonfed an answer for something you don't even own.

Pete
1553  Using Arduino / Programming Questions / Re: if (-1 > 4) evaluates to true? on: January 13, 2012, 11:35:00 am
The "byte" you refer to is probably a signed "char". There is also the data type "unsigned char" which would again give you problems.

Quote
Ahh, so when comparing variables it is not taken in to account whether they are signed?
No, that's not the right way to look at it. If both sides of the comparison are signed integers then the compiler uses a signed comparison. If both sides are unsigned then it uses unsigned comparison. But you have told the compiler to compare a signed int and an unsigned int. It has to make a decision as to how to do that. If it treats the unsigned int as being signed, any number above 32767 (for 16-bit int) will be interpreted as a negative number and you will also get weird results. The compiler was written such that when faced with this decision, it will generate code to treat them both as unsigned. Some compilers (e.g. the MSVC I use on Win 7) will give a warning when it encounters this sort of situation to let you know that your code could fail.

Pete
1554  Using Arduino / Project Guidance / Re: VU meter. on: January 13, 2012, 11:25:05 am
You only need to measure the amplitude of the input audio which would be no problem to the Arduino. The input from the ADC is 10 bits. If that would give sufficient range for your intended application then it should be easy enough to do.

Pete
1555  Using Arduino / Programming Questions / Re: if (-1 > 4) evaluates to true? on: January 13, 2012, 10:41:08 am
I think what is happening is that you are mixing signed and unsigned integers.
The size of a string can't be negative so sizeof actually returns an unsigned integer result - on top of that it may return an unsigned LONG but the documentation doesn't say. Subtracting one from it leaves the result as unsigned.
Then you try to compare a signed integer (i) with the unsigned result. If i is -1, as an unsigned integer that is 0xFFFF => +65535 which is the largest unsigned integer that can be represented in 16 bits and that is going to be larger than any sizeof minus one.

Pete
1556  Using Arduino / Sensors / Re: get rid of one resistor on: January 13, 2012, 09:22:52 am
and you'll only be able to turn both of them on or both off, instead of them being separately controllable as in your first example.

Pete
1557  Using Arduino / Project Guidance / Re: Power-saving techniques on: January 13, 2012, 08:43:56 am
Thanks again

Pete
1558  Using Arduino / Project Guidance / Re: Bug / Audio Reciever on: January 12, 2012, 10:03:04 pm
Thanks.

Pete
1559  Using Arduino / Project Guidance / Re: Power-saving techniques on: January 12, 2012, 10:01:47 pm
Interesting info Nick, Thanks.
Just an FYI. I added a power down mode to a program I wrote for my Duemilanove. It's an iambic morse code keyer.
When it is keying the radio with a string of dits or dahs it draws 33ma. If I put it into sleep IDLE mode it draws 10ma. I was hoping/expecting that a full-blown PWR_DOWN would be a lot less but it was actually 10ma as well, so I didn't bother to try out the other modes that are supposed to be intermediate between IDLE and PWR_DOWN.
Do you think a Nano, for example, would draw significantly less than 10ma in PWR_DOWN?

Pete
1560  Using Arduino / Project Guidance / Re: Bug / Audio Reciever on: January 12, 2012, 09:45:35 pm
Quote
The slowest Ethernet is a 10 megabits per second
Yep, but I meant the interface between the Arduino and the ethernet shield. I've never used one so I'm wondering how the data is transferred between the two and how fast it can be done.

Pete
Pages: 1 ... 102 103 [104] 105 106 ... 113