Show Posts
Pages: 1 ... 64 65 [66] 67 68 ... 106
976  Using Arduino / Programming Questions / Re: Programming a ATtiny85 with a Morsecode sketch - failure on: October 19, 2012, 04:45:55 pm
I've made one change to the code. Instead of putting "toupper" in sendmsg, I have put it in send() so it will work whether you send a string or a single character. I've also removed the lower case chars from the table.

I've attached a zip of morse.cpp and morse.h with my fixes.

Pete
977  Using Arduino / Programming Questions / Re: Programming a ATtiny85 with a Morsecode sketch - failure on: October 19, 2012, 04:20:04 pm
Aaaarrrgghhhhhhhhhhhh.
Found it.
My previous fix isn't required unless you want to save some SRAM but the problem was this line in _morsetab:
Code:
    1,   //ASCII 92 \
The backslash at the end of the line is treated as a line continuation, so the comment is continued to include (and therefore remove) the next line. This has the effect of removing one element from the table and so 'a' will be indexed into 'b', 'b' into 'c' etc.

Just change that line to:
Code:
    1,   //ASCII 92 '\'

Pete
978  Using Arduino / Programming Questions / Re: Programming a ATtiny85 with a Morsecode sketch - failure on: October 19, 2012, 12:34:09 pm
I haven't figured out why it is going wrong yet but it doesn't handle lower case letters correctly.
I have a workaround. Change this line at the end of Morse.cpp:
Code:
    send(*str++);
to this:
Code:
    send(toupper(*str++));
which forces it to deal only with upper case.
If you do this, you can remove all the lower case letters from the _morsetab table because it will never use them and it'll save a bit of SRAM.

Pete
979  Using Arduino / Programming Questions / Re: Multiplying 2 ints on: October 16, 2012, 11:14:47 am
I got caught by this too. http://arduino.cc/forum/index.php/topic,121141.0.html
I thought the intermediate result of int*int was a long but it isn't. int*int is int.
0xFF02 * 512 is 1024 because the high order word is lost.

Pete
980  Using Arduino / Programming Questions / Re: Problem with && operator on: October 15, 2012, 08:37:44 pm
The two 'if' statements with && should be inside the first 'if' statement so that they are only tested when a serial character is available.
Code:
void loop()
{
  buttonState = digitalRead(buttonPin);

  if (Serial.available() > 0) {
    incomingByte = Serial.read();
    if (incomingByte == 'H' && buttonState == HIGH) {
      myservo.write(180);
      delay(1500);
      digitalWrite(ledPin, HIGH); 

    }
    if (incomingByte == 'L' && buttonState == LOW) {
      myservo.write(90);
      delay(1500);
      digitalWrite(ledPin, LOW);

    }
  }
}

Pete
981  Development / Other Hardware Development / Re: Teensy 3.0 on: October 14, 2012, 05:30:49 pm
Quote
(Cortex M4 has an FPU, right?)

Not necessarily apparently. From wikipedia:
Quote
The Cortex-M4 adds DSP instructions and an optional single-precision floating-point unit. If the Cortex-M4 has the floating point unit, then it is known as the Cortex-M4F.

Pete
982  Using Arduino / Programming Questions / Re: Can someone explain this? on: October 13, 2012, 08:28:07 pm
15*60 = 900 which fits into a 16-bit integer.
900*1000 = 900000 which doesn't fit. The result is truncated to 16-bit and sign-extended.
900000 = DBBA0 (hex). Truncate to 16 bits = BBA0. This is negative so sign-extend it to 32 bits FFFFBBA0. This value is then stored in p. Converting this as an unsigned 32-bit integer to decimal gives 4294949792.

Pete
983  Using Arduino / Programming Questions / Re: the function call just partly work on: October 13, 2012, 01:38:12 pm
This is wrong:
Code:
  if (sample < sinewave_length&&PressStatus=1) {
It would be best to parenthesize the two separate conditions but the real problem is that '=' is assignment, not comparison.
Use this:
Code:
  if ((sample < sinewave_length) && (PressStatus == 1)) {

Pete
984  Using Arduino / Programming Questions / Re: Fast Fourier Transform in realtime on: October 13, 2012, 10:45:27 am
I posted some results of playing around with FFT here: http://arduino.cc/forum/index.php/topic,96562.0.html

But there is an implementation of the Fast Hartley Transform here: http://wiki.openmusiclabs.com/wiki/ArduinoFHT
The FHT is faster than FFT.

Pete
985  Using Arduino / Programming Questions / Re: Excel on: October 10, 2012, 11:09:10 am
I've used the Arduino to generate CSV files on a uSD card. Double-left-clicking on the filename immediately opens the file in Excel with each Comma Separated Value entered in a new field. As far as I can remember, I haven't done any special setup in Excel to make it do that. This is with Excel 2010 on WIn7Pro.

Pete
986  Using Arduino / Programming Questions / Re: Concatenate int to make a file name on: October 10, 2012, 11:02:01 am
Code:
snprintf(nombrearchivo,13,"%02d%02d20%02d.csv", dayOfMonth, month, year);
That filename structure will not sort well when you have a lot of files. I'd suggest that you use YYYYMMDD instead so that the files will be sorted into natural order when you view them in Windows Explorer or use 'ls' or whatever on Linux.
Code:
snprintf(nombrearchivo,13,"20%02d%02d%02d.csv",year,month, dayOfMonth);

Pete
987  Using Arduino / Programming Questions / Re: Programming parabolic function on: October 05, 2012, 10:19:07 am
A little bit of algebra changes that to
Code:
RTCvar = (120.*seconds - seconds*seconds)/36.;

Pete
988  Using Arduino / Programming Questions / Re: sketch formula line on: September 28, 2012, 11:38:01 am
The formula is slightly wrong. It should be:
Code:
position = pinval_1 | (pinval_2 << 1) | (pinval_3 << 2) | (pinval_4 << 3);

Pete
989  Using Arduino / Project Guidance / Re: *Total noob working on school project*- How to know what I need? on: September 26, 2012, 11:03:11 am
How big is the can? Why are you using an Arduino anway?

Pete
990  Using Arduino / Programming Questions / Re: Problem with DS1307 and DS18B20 on: September 22, 2012, 04:03:03 pm
Quote
it shows a size of 27,180 bytes
That's the amount of flash ram that's used. The IDE does not show you how much SRAM you are using.
You are using the String library and, as I mentioned, the SD library requires quite a bit of SRAM so you will almost certainly be running into problems caused by exceeding the SRAM limit which on a 328-based Arduino is only 2kB.
You should get rid of the String library and handle the character strings yourself.

Pete
Pages: 1 ... 64 65 [66] 67 68 ... 106