Show Posts
Pages: 1 ... 70 71 [72] 73 74 ... 111
1066  Using Arduino / Networking, Protocols, and Devices / Re: Does RF transmitter transmit all the time? on: September 20, 2012, 06:04:55 pm
The ebay page says the transmitter does "Modulation mode: ASK /OOK".
In order to do OOK there would have to be a way of keying the transmitter on and off - n'est-ce pas?
However, the "documentation" is sparse at best, so that might be wrong.

Pete
1067  Using Arduino / Programming Questions / Re: bitwise shift operators, where does the bit go? on: September 19, 2012, 01:52:34 pm
You can do inline assembler stuff but the closest I have got to it is to use
Code:
    asm volatile("nop\n"::);
to give me a delay guaranteed to be greater than a few nanoseconds.

You may be focusing on the wrong thing to optimize though. If your "do blah" takes microseconds or even milliseconds to execute then agonizing over the few instructions required to shift and test a bit is a waste of time.

Pete
1068  Using Arduino / Programming Questions / Re: bitwise shift operators, where does the bit go? on: September 19, 2012, 12:52:10 pm
Quote
How are either of those examples any different in efficiency than the first example I gave?
They have two great advantages over your example.
(a) you can't access the overflow bit from C even if you use a left shift.
(b) they work.


Quote
In assembler you to a test under mask and then branch on a condition
If you are so desperate for speed you will have to use assembler, one way or another.

Pete
1069  Using Arduino / Programming Questions / Re: bitwise shift operators, where does the bit go? on: September 19, 2012, 12:23:25 pm
Code:
for(byte i=0;i<8;i++)
{   data >>=1;
   if(overflow) {
       do blah;
   }
}
A right shift cannot create an overflow condition. All you need to do is test the low order bit and shift the data *afterwards*.
Code:
for(byte i=0;i<8;i++)
{
   if(data & 1) {
       do blah;
   }
  data >>= 1;
}

If you need to test the high order bit first this code will work:
Code:
for(byte i=0;i<8;i++)
{
   if(data & 0x80) {
       do blah;
   }
  data <<= 1;
}
If data is a signed byte you can use (data < 0) instead of (data & 0x80).

Pete
1070  Using Arduino / Programming Questions / Re: CRC8 calc on: September 19, 2012, 12:12:47 pm
The OneWire library here http://www.pjrc.com/teensy/td_libs_OneWire.html has a CRC8 function in it. It uses a different polynomial but you could use that function as a starting point.

Pete
1071  Using Arduino / Audio / Re: Renaming an Arduino midi device.... on: September 18, 2012, 11:50:37 am
I think this is a common problem in Windows when you have multiple identical MIDI devices (e.g. 2 or 3 identical keyboards). Windows distinguishes them by just adding a number and as you have discovered it doesn't always assign the same number to the same device. The only sure way I can think of to get around it would be if you have the ability to change the actual device name within the MIDI device. i.e. if you can get at the device software and change "Moco for Lufa" to "Moco for Lufa A" in one of them and "Moco for Lufa B" in the next etc.
A less certain way would be to always power each device up in the same order and power them down in the reverse order but Windows will probably find a way to screw that up too.

Pete
1072  Using Arduino / Networking, Protocols, and Devices / Re: connecting TDA1543 DAC - I2S protocol on: September 17, 2012, 09:41:25 pm
There are a couple of problems in this bit of code:
Code:
    digitalWrite(data, !!(table[k] & (1 << pos)));   //data= data output pin , Outputs each single bit (MSB)
   
    if (pos=0) {     //when all bits are sent it switches channel
      pos=16;

when pos is 16, 1<<pos will equal zero. You need to initialize pos to 15. I would also change the way that you select the bit in digitalWrite. Finally, "if(pos=0)" doesn't test for equality, it sets pos to zero.
So, initialize pos to 15 and then replace the above with this:
Code:
    digitalWrite(data, (table[k] >> pos) & 1));   //data= data output pin , Outputs each single bit (MSB)
   
    if (pos == 0) {     //when all bits are sent it switches channel
      pos = 15;


Pete
1073  Using Arduino / Programming Questions / Re: Byte Digital Output on: September 16, 2012, 07:35:29 pm
Code:
byte b = 00000111;
This sets b to the octal value 0111 which is the bit pattern 01001001. What I think you wanted was:
Code:
byte b = B00000111;

Pete
1074  Development / Other Software Development / Re: Compilers goes crazy when you have "\\" inside a comment on: September 16, 2012, 07:30:19 pm
I think inside a comment the backslash doesn't have its special meaning as the escape character except the last one on a line. The first backslash is therefore ignored - i.e. it isn't read as an escape for the following backslash. The second backslash then gets read as the line continuation. The compiler issues a warning:
Code:
sketch_sep16a.cpp:8:1: warning: multi-line comment

Pete
1075  Using Arduino / Programming Questions / Re: Map selector on: September 15, 2012, 09:43:22 pm
In the loop function you set game_mode using question_box() but then four lines further down the code, you set game_mode to zero which presumably forces it to always use "Plane".

Pete
1076  Using Arduino / Project Guidance / Re: Where do i find the library and code i need on: September 15, 2012, 10:59:17 am
Quote
I have change the WProgram.h to arduine.h
That's not all you have to change. The error messages are caused because the compiler can't find "send" and "receive" methods in the TwoWire class. That is because those methods were renamed in V1. If you edit DS1307new.cpp and change "send" to "write" and change "receive" to "read" that will get rid of those errors.

Pete
1077  Community / Exhibition / Gallery / Re: DTMF detection in software on: September 14, 2012, 04:35:02 pm
If you were "one with Google" you should have already seen these two threads and saved yourself some time and effort.
http://arduino.cc/forum/index.php/topic,121030.0.html

http://arduino.cc/forum/index.php/topic,121540.0.html


Pete
1078  Using Arduino / Programming Questions / Re: logical if in C on: September 12, 2012, 05:25:11 pm
Udo was apparently referring to the original statement:
Code:
If(temp=-1 || temp1=-1){
which doesn't compile:
Code:
sketch_sep12a:4: error: lvalue required as left operand of assignment

Pete

1079  Using Arduino / Programming Questions / Re: logical if in C on: September 12, 2012, 05:03:23 pm
Quote
Notice that the first assignment will evaluate to true thus the second assignment will not be processed because || has short circuit evaluation.
No, the compiler doesn't parse it like that. You are looking at it as if it is parsed as:
Code:
if ((temp = -1) || (temp1 = -1 )) {
But the compiler sees it as one assignment statement with a syntax error.
Code:
if (temp = ( -1 || temp1 = -1 )) {
It finds that it can't turn "-1 || temp1" into an lvalue and spits out an error message.

This, for example, is legal and will compile and is essentially what the compiler was expecting:
Code:
if(temp = temp1 = -1){

Pete
1080  Using Arduino / Project Guidance / Re: need to add odds of value getting picked inside random on: September 10, 2012, 10:24:58 am
Code:
ran1 = random(1,100);
ran2 = random(100,1000);

ran1 is a random number from 1 to 100 - so it could be 23.
ran2 is a random number from 100 to 1000 - may be 792.

Code:
delay(random(ran1,ran2));
Now you delay by a random number of milliseconds from 23 to 792. So, perhaps 298 - or 25 or 681 or ....

Quote
Quote
That means its a 1 out of 2 odd for either ran1 or ran2
How do you get 1 out of 2 odds?

Pete


Pages: 1 ... 70 71 [72] 73 74 ... 111