Show Posts
Pages: 1 ... 30 31 [32] 33 34 ... 114
466  Using Arduino / Project Guidance / Re: What is a carriage return? on: December 02, 2013, 10:50:17 pm
Quote
"CR" is a single character
"CR" is a string containing the two characters C and R followed by the NULL terminator

Quote
"\n"   is a coded parameter "n" send to the "printf"
The backslash inside a string is an escape character and the character following it is interpreted differently.
\n is translated (by the compiler) to the linefeed character
\r is translated to the carriage return character
\t is translated to the horizontal tab character.
\\ is translated to a single backslash character
These and other escaped characters are valid in any C string, not just in printf strings.
So, "\n" is a string consisting of a linefeed character followed by the NULL terminator.

The special character in a printf string is %.

Pete
467  Using Arduino / Programming Questions / Re: Curious Error with goto: I know its discouraged, but this is a nested loop here! on: December 02, 2013, 08:12:03 pm
You can't jump out of one function and into another.
The label is only valid in the function in which it is declared.

Pete
468  Using Arduino / Sensors / Re: DS18B20 temp sensor read 85 C on: November 30, 2013, 01:42:33 pm
There is a footnote on page 4 which says "The power-on reset value of the temperature register is +85°C."
so if you read 85 degrees it means it hasn't done a conversion since the last power on.
You hadn't wired it up properly so the sensor was being powered off and on periodically, which resets the register to 85 and that is why you got a valid CRC from it.

Pete
469  Community / Exhibition / Gallery / Re: seconds timekeeping and time conversion on: November 28, 2013, 04:17:15 pm
Quote
Not really.  It is computing:

Yup, you're right.

Pete
470  Community / Exhibition / Gallery / Re: seconds timekeeping and time conversion on: November 28, 2013, 03:51:06 pm
Quote
I'm not out to throw stones at the Time library
Yup, no problem. I was just wondering whether you had a better "mousetrap" smiley

Quote
This code in Time.cpp, in particular, gives me the willies
I think what the now() code is doing is waiting for the internal time to change to the next second before returning the time value. That way if it returns a string saying it is (for example) 17:15:12, the seconds value will have just "ticked" and be very close to 12.00 secs rather than being 12.85 or 12.13 or ....

Quote
It also doesn't have date/time string parsing
True, but I have always found it easy to parse the year, month, day, etc, of a string into the elements of the tm_elements structure and then just convert that to a time_t.

Pete
471  Using Arduino / Programming Questions / Re: Time, Sync etc on: November 28, 2013, 12:49:50 pm
Which RTC and Arduino are you using?

Pete
472  Using Arduino / Networking, Protocols, and Devices / Re: How can I change the I2C Address of MPU9150 on: November 28, 2013, 11:28:45 am
The Sparkfun circuit diagram shows that the AD0 pin is connected to ground. I presume that the symbol implies that you can cut this trace and connect to +3v3 if you wish. Did you cut the trace? If not, you've got a problem because you are grounding the 3v3 supply.

Pete
473  Community / Exhibition / Gallery / Re: seconds timekeeping and time conversion on: November 28, 2013, 10:59:20 am
Doesn't the Time library do most or all of this?

Pete
474  Using Arduino / Project Guidance / Re: How to change GMT time on arduino on: November 28, 2013, 10:38:14 am
I haven't used the TinyGPS library but if I read it correctly it provides the time as an unsigned long number of milliseconds. So, adjusting that to Central European Time is:
Code:
  unsigned long fix_age,local_age;

  // Add two hours (in milliseconds)
  local_age = fix_age + 1000L*2*60*60;
Now convert local_age to a string and write to the LCD.
You'll have to figure out how to handle daylight savings time though.

Pete
475  Using Arduino / Programming Questions / Re: Button press sends out unwanted MIDI signal on: November 27, 2013, 01:45:36 pm
In setup() you initialize both pins to inputs but then you write LOW to one of them and HIGH to the other.
Code:
  pinMode(buttonPin, INPUT);
  pinMode(muteButton, INPUT);
  .
  .
  digitalWrite(buttonPin, LOW);
  digitalWrite(muteButton, HIGH);
Writing HIGH to an input pin turns on its internal pullup resistor. The other pin won't have the pullup turned on. You should decide what they really need.


Then in loop() you have problems with keeping track of the button states. 
Code:
  buttonState = digitalRead(muteButton);
  if(buttonState != lastButtonState){
  .
  .
  buttonState = digitalRead(buttonPin);
  if (buttonState != lastButtonState) {
You are using buttonState and lastButtonState to keep track of both buttons. Won't work. You need to keep the last states in separate variables, e.g. lastButtonState and LastMuetState. This is probably why one of the buttons appears to be sending MIDI data when it shouldn't.


Pete
476  Using Arduino / Sensors / Re: DHT22 - negative celsius temperatures on: November 26, 2013, 11:27:36 am
I don't think the library does the conversion correctly.
This code:
Code:
    // Below zero, non standard way of encoding negative numbers!
    // Convert to native negative format.
    _lastTemperature = -currentTemperature & 0x7FFF;
doesn't look quite right because I think the unary minus will be performed before the &.
Try changing it to this:
Code:
    // Below zero, non standard way of encoding negative numbers!
    // Convert to native negative format.
    _lastTemperature = -(currentTemperature & 0x7FFF);

Aside: just because signed-magnitude isn't common doesn't mean that two's complement is "standard".

Pete
477  Using Arduino / Programming Questions / Re: pins_arduino.h challege - sample code anyone? on: November 24, 2013, 03:40:17 pm
For previous versions of the IDE, the code would have been:
Code:
   pinMode(PIN1, INPUT); // Connect to a button that goes to GND on push
   digitalWrite(PIN1, HIGH);
The digitalWrite was required to set the internal pullup.

The code must have been updated to INPUT_PULLUP for recent IDE versions but the following digitalWrite wasn't removed even though it isn't needed any more.

Pete
478  Using Arduino / Project Guidance / Re: avr-gcc compiler header file error on: November 24, 2013, 03:22:28 pm
The compiler/preprocessor/whatever only gives a warning if a header file can't be found and warnings are turned off by default.
I forget how to turn warnings on.

El Supremo
479  Using Arduino / Project Guidance / Re: avr-gcc compiler header file error on: November 24, 2013, 01:56:55 pm
How about:
Code:
#include <Rotary.h>

and have you installed the Rotary library (whatever that is)?

Pete
480  Using Arduino / Programming Questions / Re: Is this a bug in rvalue promotion? on: November 24, 2013, 12:05:03 pm
The Arduino IDE turns off the warnings. IMHO, not a good thing to do, but there it is.

Quote
Because 33 and 1000 are literals, and 33 * 1000 is a literal sum.  The preprocessor will evaluate that part for you

The preprocessor doesn't touch that at all. When the compiler parses 33 * 1000 it sees that both operands of the multiply are constants and the compiler's optimizer evaluates (according to the rules of C/C++) the expression and replaces it with a new constant - if the required optimization flag has been specified.

Pete



Pages: 1 ... 30 31 [32] 33 34 ... 114