|
526
|
Using Arduino / Programming Questions / Re: ir remote relay control
|
on: October 14, 2012, 10:58:59 pm
|
What is the problem? Isn't it working if you do... else if (results.value == WHATEVER) { if (millis() - last > 250) { on2 = !on2; digitalWrite(relay2, on2 ? HIGH : LOW); } last = millis(); } ? Also a little tip, change: int relay1 = 4; ... int on = 0; ... on = !on; digitalWrite(relay1, on ? HIGH : LOW);
to byte relaysPins[] = { 4, 5, 6, 7 }; //assuming relays are connected to those pins... ... bool relaysStates[] = { LOW, LOW, LOW, LOW }; ... relaysStates[0] = !relaysStates[0]; digitalWrite(relaysPins[0], relaysStates[0]);
etc... Well, only a suggestion 
|
|
|
|
|
530
|
Using Arduino / Programming Questions / Re: Need a math sketch to compare Teensy 3.0 to Uno
|
on: October 14, 2012, 06:13:42 pm
|
47932.72 with Sainsmart's Arduino MEGA 2560  @Guix, I downloaded the library you linked to but, I did not figure out how to put it to use. The code you posted is a little above my understanding at the moment. Thank you for sharing it though.
If you want you can simply replace those 2 lines in my code: sprintf(result, "Average (microseconds) : %10.2f\n\n", ((float)time/(float)iterations));\ Serial.print(result);\
by this: Serial.print("Average (microseconds) : ");\ Serial.print((float)time/(float)iterations);\ Serial.print("\n\n");\
Running the same code more than one time is needed for accurate results, but your test already show the winner anyway 
|
|
|
|
|
531
|
Using Arduino / Programming Questions / Re: Need a math sketch to compare Teensy 3.0 to Uno
|
on: October 13, 2012, 11:08:06 pm
|
Edited to post corrected function: I have made a small code to measure speed of functions. unsigned int chrono_id; #define CHRONO(iterations,function) \ {\ chrono_id ++;\ \ Serial.print("Chrono ");\ Serial.print(chrono_id);\ Serial.print(" - "#function" - "#iterations" calls...\n");\ \ unsigned long time = micros();\ \ for (unsigned long i = 0; i < iterations; i++)\ {\ function;\ }\ \ time = micros()-time;\ Serial.print("Average (microseconds) : ");\ Serial.print((float)time/(float)iterations);\ Serial.print("\n\n");\ }
Example usage: void setup() { Serial.begin(9600); delay(1000); CHRONO(100000, random(10)); CHRONO(100000, micros()); CHRONO(100000, { sqrt(pow(2, 32)); sin(cos(tan(123456789))); }); }
Example output: Chrono 1 - random(10) - 100000 calls... Average (microseconds) : 140.21
Chrono 2 - micros() - 100000 calls... Average (microseconds) : 3.97
Chrono 3 - { sqrt(pow(2, 32)); sin(cos(tan(123456789))); } - 100000 calls... Average (microseconds) : 0.00
More iterations = more accurate result. Oh and I know, it's ugly, it isn't a good practice..but couldn't find a way to make it in a normal function 
|
|
|
|
|
533
|
Using Arduino / Project Guidance / Re: I'm affraid I can't use SPI, tell me I'm wrong!
|
on: October 13, 2012, 10:00:53 pm
|
Ok, I am reassured that I can choose whatever pin I want for the other SPI devices  But, in the schematic, does that mean that the SD slot is using SPI? Now to find a solution to connect those other devices to the same pins 50, 51, 52.. Well I'm far from here anyway, but I like to anticipate things... Thanks!
|
|
|
|
|
534
|
Using Arduino / Project Guidance / I'm affraid I can't use SPI, tell me I'm wrong!
|
on: October 13, 2012, 08:55:42 pm
|
Hello  So I have the Arduino MEGA2560 with a TFT display and it's adapter shield to connect easily the display to the Arduino. On the TFT there is also a SD slot. Here are the pins used by the adapter shield on the 36 pins connector of the Arduino:  You can see, the SD slot use the pin 53 for SD_CS. I was randomly reading things on the Arduino main site, and on this page I can read: On the Mega, the hardware SS pin, 53, is not used but it must be kept as an output or the SPI interface won't work. I don't care about the Wifi shield as I don't plan to use it, but I don't understand if this line is about just the Wifi shield, or if it's a general information?Ok I've read on the SPI page: On the Arduino Mega, this is 50 (MISO), 51 (MOSI), 52 (SCK), and 53 (SS). MISO, MOSI, and SCK are also available in a consistent physical location on the ICSP header; this is useful, for example, in designing a shield that works on the Uno and the Mega. Note that even if you're not using the SS pin, it must remain set as an output; otherwise, the SPI interface can be put into slave mode, rendering the library inoperative. It is, however, possible to use a pin other than pin 10 (53 in my case?) as the slave select (SS) pin. For example, the Arduino Ethernet shield uses pin 4 to control the SPI connection to the on-board SD card, and pin 10 to control the connection to the Ethernet controller. But I don't really understand what it said... My SD slot use those 4 pins! Because I plan to use an DS3234 RTC breakboard, and sensors, which will maybe use SPI, that's why I'm affraid of not being able to use them! So... Will I have problems using the SD slot + the RTC + those sensors? Thanks in advance!
|
|
|
|
|
536
|
International / Français / Re: Pb avec l'usb
|
on: October 13, 2012, 02:34:14 pm
|
Oui, les Strings (avec majuscule) sont des objets. C'est peut être plus pratique et plus facile à utiliser pour les débutants, le problème c'est que ça prends de la mémoire en plus, et y'en a peu sur les Arduino alors il vaut mieux l'économiser autant que possible  . Car par exemple la fonction String.equals, au final elle utilise probablement la fonction native strcmp pour faire la comparaison. J'ai aussi lu quelque part qu'il y a des bugs avec la classe String, c'est pourquoi je me suis permis de les déconseiller.. Les strings (minuscule) ne sont que des tableaux de char comme tu le dis, donc ils n'ont pas besoin d'inclure une classe supplémentaire pour être utilisés. Est-ce que tu as résolu ton problème?
|
|
|
|
|
537
|
Using Arduino / Programming Questions / Re: Help me about these codes
|
on: October 13, 2012, 06:26:13 am
|
Hello, please follow this advice before you are punished!! Code tags would be good too. I do believe you've been asked before to do that.
Just write: [ code ]<your code here>[ /code ] (without spaces) And, if you explained the problem it would be useful  In your code is missing a closing bracket "}", that's why indentation is useful 
|
|
|
|
|
538
|
Using Arduino / Programming Questions / Re: Theory of why this doesn't really work?
|
on: October 13, 2012, 06:10:41 am
|
Ok Nick, I know the test3 is the way to do it, I was just experimenting  But what about this: char s[13];
char* test1(unsigned long a) { sprintf(s,"<%lu>", a); return s; }
This is working as well, and the variable isn't local anymore. But is it still wrong to use things like that instead of the method used in test3?
|
|
|
|
|
540
|
Using Arduino / Programming Questions / Theory of why this doesn't really work?
|
on: October 12, 2012, 11:12:05 pm
|
Hello  I have a small question about general c++ programming: char* test1( unsigned long a ) { char s[13]; //under 13 = arduino reset sprintf(s,"<%lu>", a); return s; }
char* test2( unsigned long a ) { char s[39]; //under 39 = weird output sprintf(s,"<%lu>", a); return s; }
int test3( unsigned long a, char s[] ) { return sprintf(s,"<%lu>", a); }
void setup() { Serial.begin( 9600 ); delay(1000);
Serial.print( "Hello\n" );
Serial.print( "Test1:\"" ); Serial.print( test1(pow(2,32)) );
Serial.print( "\"\nTest2:\"" ); Serial.print( test2(pow(2,32)) );
Serial.print( "\"\nTest3:\"" ); char str[13]; test3( pow(2,32), str ); Serial.print( str );
Serial.print( "\"\nGood bye" ); }
Output: Hello Test1:"< ! " Test2:"<4294967295>" Test3:"<4294967295>" Good bye
You can see test2 and test3 work OK, they are 13 characters long. So why in test2 I need 39 cells? Why it doesn't work with 13 cells in test1, but does work in test3 with also 13 cells?!? Someone can explain what is going on? Thanks!
|
|
|
|
|