Loading...
  Show Posts
Pages: [1] 2 3 4
1  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: LCD Library on: April 25, 2008, 01:04:12 pm
Quote
what would happen then if I have a 2 line lcd and i did
LCD.println("A");
LCD.println("B");
LCD.println("C");

would the last line roll off and lcd  showing

A
B

or would it scroll up showing

B
C

or would it wrap around to the top showing

C
B


In this case, I think the C would get lost, as the chips in a 16*2 LCD don't have memory for more than 2 lines and 0x27 characters per line. If the characters are printed off the screen, they do not get printed, but instead remain in the driver's DRAM. If the LCD received commands to scroll the text, then these hidden characters would start appearing on the screen.
Ultimately, it would depend on how the function was implemented.
2  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Spammers on: April 22, 2008, 06:49:37 pm
Does YaBB keep track of poster's IP addresses? We could start blocking ranges of repeat offenders.
3  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: stdio.h in 0011 broken on: April 01, 2008, 12:53:04 pm
Seems the discussion's mostly over here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1206744591/6#6
4  Forum 2005-2010 (read only) / Bugs & Suggestions / stdio.h in 0011 broken on: April 01, 2008, 12:45:02 am
Something seems to have been changed in Arduino 0011, and apparently has broken the AVR stdio.h. The code still compiles in 0010, but gives errors in 11. I thought it might be the order of includes, so I rearranged mine some, but didn't do anything. My sketch needs it for some sprintf junk.

Quote
c:/documents and settings/marc/desktop/embedded dev/arduino/arduino-0011/hardware/tools/avr/bin/../avr/include/stdio.h:263: error: expected unqualified-id before 'int'


c:/documents and settings/marc/desktop/embedded dev/arduino/arduino-0011/hardware/tools/avr/bin/../avr/include/stdio.h:263: error: expected `)' before 'int'


c:/documents and settings/marc/desktop/embedded dev/arduino/arduino-0011/hardware/tools/avr/bin/../avr/include/stdio.h:263: error: expected `)' before 'int'


c:/documents and settings/marc/desktop/embedded dev/arduino/arduino-0011/hardware/tools/avr/bin/../avr/include/stdio.h:264: error: expected unqualified-id before 'int'


c:/documents and settings/marc/desktop/embedded dev/arduino/arduino-0011/hardware/tools/avr/bin/../avr/include/stdio.h:264: error: expected `)' before 'int'


c:/documents and settings/marc/desktop/embedded dev/arduino/arduino-0011/hardware/tools/avr/bin/../avr/include/stdio.h:264: error: expected `)' before 'int'


c:/documents and settings/marc/desktop/embedded dev/arduino/arduino-0011/hardware/tools/avr/bin/../avr/include/stdio.h:417: error: '__put' was not declared in this scope


c:/documents and settings/marc/desktop/embedded dev/arduino/arduino-0011/hardware/tools/avr/bin/../avr/include/stdio.h:417: error: expected primary-expression before 'char'


c:/documents and settings/marc/desktop/embedded dev/arduino/arduino-0011/hardware/tools/avr/bin/../avr/include/stdio.h:417: error: expected primary-expression before 'struct'


c:/documents and settings/marc/desktop/embedded dev/arduino/arduino-0011/hardware/tools/avr/bin/../avr/include/stdio.h:417: error: '__get' was not declared in this scope


c:/documents and settings/marc/desktop/embedded dev/arduino/arduino-0011/hardware/tools/avr/bin/../avr/include/stdio.h:417: error: expected primary-expression before 'struct'


c:/documents and settings/marc/desktop/embedded dev/arduino/arduino-0011/hardware/tools/avr/bin/../avr/include/stdio.h:417: error: initializer expression list treated as compound expression

If you want my sketch code as well, just holler.
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: get the length of an Array on: June 17, 2008, 01:05:02 pm
One thing to note about the sizeof function is that it will not work on arrays not defined at compile time.

char * arr;
arr = new char[10];
int size = sizeof(arr);

size will contain 2, which is the size of a char *.

The arr.length() function you speak of doesn't exist in C++. Java and other languages actually build a class around the array to provide the programmer with all these handy little functions, and also provide some bounds-checking as well, preventing you from accidentally doing arr[10] when the array is only 10 items long. It is possible to create a 'wrapper class' in C++ to get these nice features, but you have to use it explicitly.
6  Forum 2005-2010 (read only) / Syntax & Programs / Re: How to access TCNT1 (ATmega168)? on: May 01, 2008, 09:53:43 pm
Include avr/io.h and then you can read/write directly to TCNT1, like so:

TCNT1 = 0;
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: Read from file on: April 28, 2008, 01:34:35 pm
I can't remember exactly, but I thought the file objects were in the header file "fstream".
8  Forum 2005-2010 (read only) / Syntax & Programs / Re: How do I write a Class in Arduino Language on: April 27, 2008, 03:18:15 pm
Here's an example of a class:

Code:
class Button {
private:
  byte down_at;
  byte down;
  
public:
  Button();
  byte downFor();
  void resetDown();
  bool isDown();
  void turnOn();
  void turnOff();
};

Button::Button()
{
  this->down_at = 0;
  this->down = 0;
}

// Find the number of beats the button has been down for. Function can compute max. 8 sec down before rolling over.
byte Button::downFor()
{
  byte time;
  if (this->down_at > sc_beat)
  {
   time = (sc_beat + 256) - this->down_at;
  }
  else
  {
    time = sc_beat - this->down_at;
  }
  return time;
}

bool Button::isDown()
{
  return (bool)this->down;
}

void Button::resetDown()
{
  this->down_at = sc_beat;
  this->down = 1;
}
  
void Button::turnOn()
{
  if (!this->down)
  {
    this->down_at = sc_beat;
    this->down = 1;
  }
  return;
}

void Button::turnOff()
{
  this->down = 0;
  return;
}
9  Forum 2005-2010 (read only) / Syntax & Programs / Embedding Assembly in C++ on: April 04, 2008, 11:46:08 pm
I'd like to use some assembler directly in my sketch for my ISRs (It's not that they're running slowly, it's just that I'd like to try it out), and have done some poking about the internet for assistance on this topic. I seem to have found the basics on how to do it syntactically, but there's a couple things that I can't seem to find.

Is it possible to reference global variables from the ASM? What would the syntax for this be? Can I use them as addresses, and load them into a register as if it was defined in the ASM part of the program?
Can anyone provide any tips/pointers for this? Thanks!
10  Forum 2005-2010 (read only) / Syntax & Programs / Re: Newb Q re. interrupts & timers on: April 19, 2008, 05:03:36 pm
You can use the External interrupts 0 and 1, available on digital pins 2 and 3 respectively. These are the two interrupts that use the attachInterrupt function. When you call it, it will automatically enable the interrupts for those two vectors.
You can set the interrupts to trigger on the falling or rising edge of the signal, or when it is low. The datasheet describes them as INT0 and INT1, starting from page 67.
11  Forum 2005-2010 (read only) / Syntax & Programs / Re: Non-Int Storage in EEPROM. on: April 17, 2008, 04:19:46 pm
You can use a union to access each byte of the 4-byte float. A union is similar to a struct, except that it only allocates enough space to contain the largest single type that is defined inside it. Here's an example of how to copy a float byte by byte from the original to another, using C++ on a PC.

Code:
#include <iostream>
using namespace std;

union bitFloat {
      float float_num;
      char byte[4];
};

int main()
{
      bitFloat test;
      test.float_num = 10.5f;
      bitFloat test2;
      test2.byte[0] = test.byte[0];
      test2.byte[1] = test.byte[1];
      test2.byte[2] = test.byte[2];
      test2.byte[3] = test.byte[3];

      cout << test.float_num << endl;
      cout << test2.float_num << endl;

      getchar();
      return 0;
}

The important thing to realise is that the bitFloat type defined is only 4 bytes, and you have two ways of accessing its data - one through the float type test.float_num or through the byte array, test.byte.
So, the practical upshot of all this is that you can store your floating point numbers in EEPROM, and read them out byte by byte, and use them to build up your whole float variable. (floats and doubles are both 4 bytes on the AVR cores.) The only thing you might have to worry about is endian-ness... which order the bytes need to be stored in. Unfortunately I don't know myself what the AVRs are. ):
12  Forum 2005-2010 (read only) / Syntax & Programs / Re: serial port and software serial!!!! on: April 14, 2008, 08:54:35 pm
It sounds like you have your pins swapped. Try connecting your modem's TX to the Arduino RX, and Arduino TX to the modem's RX.
13  Forum 2005-2010 (read only) / Syntax & Programs / Re: Debugging errors.. Returning an array from a F on: April 01, 2008, 03:24:00 pm
Heh. My long-winded version of my post had that. >_<;
14  Forum 2005-2010 (read only) / Syntax & Programs / Re: Debugging errors.. Returning an array from a F on: March 31, 2008, 07:13:51 pm
Your array syntax was not correct, that's why you the first sketch you posted didn't compile. Namely, the compiler didn't like

return dd[];

Arrays are quite a bit different than regular values in C/C++. You cannot return several of them from a function. The compiler was expecting a number between those brackets, seeing as it was looking for an integer to return.

Also keep in mind that arrays are not passed by value (using copies of its arguments) they are passed by reference (using the variables the calling function uses). That is to say, any change you make to items in the array in a function will be reflected in the same array that the calling function passed into it - the fallout of which is that you don't have to return the array at all! You can make changes to it in a function, and it gets changed as far as the calling function can tell. So we can rewrite your naughty function as this:

Code:
//takes an array and appends the current distance at the end of it, moving all values and deleting the first
void AppendDistance (int dd[], int arrayVals){
// dd is being passed by reference - any change we make here will be reflected in the calling function.
      int i = 0;

      for(i=0;i<arrayVals;i++){                  //should this be i<arrayVals or i<=arrayVals
            if (i=1){
                  dd[1]=dd[2];
            }
            else if (i=arrayVals){
                  dd[i] = GetDistance();
            }
            else{
            dd[i]=dd[i+1];
            }
       }
         // Don't return anything, since we've already changed dd, and the calling function will know about it.
}

I hope that helps you understand why it didn't quite work the first time!  smiley-wink  If you're new to C(++), it might be a good idea to find a couple tutorials on arrays, and pointers as well. They're actually quite closely related, and knowing a bit about pointers will help you return arrays from functions if you need to. (:
15  Forum 2005-2010 (read only) / Syntax & Programs / Re: Syntax Error causing boolean / byte to be unkn on: April 01, 2008, 11:45:59 pm
Try replacing 'boolean' with 'bool'.
Pages: [1] 2 3 4