Show Posts
Pages: 1 ... 53 54 [55] 56 57 ... 71
811  Using Arduino / Programming Questions / Re: two dimensional array declaration on: January 19, 2012, 03:49:19 pm
The syntax is like this:
Code:
int coolarray[2][4] = {
{2, 5, -12, 4},
{4, 6, 2993, -1002 }
};

Although you can get away with this:
Code:
int coolarray[][] = {
{2, 5, -12, 4},
{4, 6, 2993, -1002 }
};
since the compiler can see "oh, it's four by two!"

If you want to pack 8 bools into a byte, you can do this:
Code:
char arrayofbits [] = {
0b11001111,
0b01111000,
0b10001111,
};

or you could use a union (google it)
812  Using Arduino / Programming Questions / Re: How to create a library that requires another libray on: January 19, 2012, 01:11:36 pm
...

that's all true. To destroy an instance of a class, you can just let it go out of scope, or use delete if you allocated it with new.

To access fish in the second example, you would do something like:
Code:
class Morse
{
  public:
    Morse(int pin);
    void dot();
    void dash();
    int fish;
  private:
    int _pin;
};

Morse morse(3);
morse.fish = 5;
int y = morse.fish
morse.dot();
morse.dash();

However, you almost never want to actually have a variable with public scope; people generally make get and set functions.
Code:
class Morse
{
  public:
    Morse(int pin);
    void dot();
    void dash();
    int getFish() { return fish; }
    void setFish(int val) { fish = val; }
  private:
    int fish;
    int _pin;
};
813  Using Arduino / Programming Questions / Re: detect falling object with infra red (urgent) on: January 18, 2012, 07:04:25 pm
What is ISR? First i thought it was a typing error for IR.
It's a function that gets run when an "interrupt" happens. An interrupt is usually triggered by a pin change or a timer (in your case, it would be a pin change), and it just pauses whatever the code is currently doing and calls the function, then goes back to whatever it was doing.
Quote
Quote
I'm also questioning how you managed to get a good digitalread value on an analog signal, but that's great if it works.

I think when using digital read on a analog signal that below 512 is 0 and above 512 is 1 (that's my guess).
Nope. Generally, it will read HIGH if it's above about 2.7V, LOW if it's under about 0.3V, and whatever it wants between the two. For speed, I'd suggest getting something like an analog comparator that can take an analog signal and say "under" or "over" for a certain voltage.
Quote
I will look at direct port acces.
That will have the same problems as I just mentioned, but it will be faster. However, if the digitalRead'ing works somehow, direct port access will also.
814  Using Arduino / Programming Questions / Re: unknown IR receiver error on: January 18, 2012, 06:56:04 pm
Sorry for pushing that thread, but i'm looking for a solution for the same thing here...

Well, part of the problem is that translating code from the atmega to that attiny is that the atmega can do more stuff than the attiny - it has more pins and it has more timers. So, when you say you want to make the code run on the attiny, it can be like saying you want your bike to go 100 km/h.

Depending on how many timers the attiny has (I'm not an expert) you could make the library use timer1. If it only has one timer (which is used up by millis) it's best to throw out the library and start over.

Come to think of it, I wrote a library that does essentially the same thing but doesn't use any timers, so it should be relatively easy to port to an attiny -- PM me if you want it.
815  Using Arduino / Programming Questions / Re: detect falling object with infra red (urgent) on: January 18, 2012, 04:19:25 pm
I'm not sure if using an ISR is necessary if you need to get it done quickly, but try looking up direct port access. It's many times faster than digitalRead.

I'm also questioning how you managed to get a good digitalread value on an analog signal, but that's great if it works.
816  Using Arduino / Programming Questions / Re: LiquidCrystal595 help on: January 18, 2012, 02:41:16 am
go to C:\Users\Grant\Desktop\arduino-1.0\libraries\LiquidCrystal595/LiquidCrystal595.h on line 98, and change "void" to "size_t"
817  Using Arduino / Installation & Troubleshooting / Re: Trying to interact with Arduino on Ubuntu on: January 15, 2012, 05:38:10 pm
What's the error message you get when it doesn't work? It shows up as ACM on my computer. You could try looking in /etc/udev for how linux mounts things.
818  Using Arduino / Programming Questions / Re: Where do I find cpp source? on: January 15, 2012, 05:18:38 pm
yes, but you have to hit compile and not upload
/tmp/build{numbers}

You could find exactly the directory by pressing ctrl-comma and makeing compiling verbose; when you compile it'll have that directory everywhere.
819  Using Arduino / Programming Questions / Re: DC motor Steering control through POT on: January 15, 2012, 05:16:43 pm
It's pretty difficult if you want to do it right - look up PID.

Of course, you can try to simplify it - just take the value of the pot, subtract where you want to go from it, and then move the motor at a speed proportional to that. (that's a P loop in PID terms)

Code:
// Set this value by trial and error - if it doesn't get to where you want it to go, increase it; if it oscillates after getting where you want it to go, lower it; if both (or you can't find a happy medium) you'll need to look into using the I and D terms of PID
int Pterm; // 0 to 1000
int dest; // where you want the steering to go
int pos = analogRead(potpin);
int speed = (((long)pos - (long)dest) * (long)Pterm)/1000;

// Run your motor at the right speed.
820  Using Arduino / Installation & Troubleshooting / Re: lilypad onboard led doesn't flash on: January 14, 2012, 12:42:46 am
Stupid question, but did you try disconnecting and reconnecting it? What LED are you talking about?  The power one shouldn't flash, and a solid Tx LED (if it exists on a lilypad; I'm not sure) is some sort of error. I usually fix it (on linux) by holding down the reset button until it's ready to upload. Release the reset button when the Rx LED flashes once.
821  Using Arduino / Installation & Troubleshooting / Re: Error on compile -stdlib.h not found on: January 14, 2012, 12:40:36 am
Are you having the problems with windows or linux? What distro? Do I see that you have arduino installed in the root directory? That sounds like a bad idea.
822  Using Arduino / Installation & Troubleshooting / Re: Arduino 1.0 compile issues on: January 14, 2012, 12:37:34 am
I'm running archlinux and it doesn't highlight the line numbers for me, either. It's especially annoying since the line numbers correspond to the IDE-processed sketch rather than the one I can actually see. :/
823  Using Arduino / Installation & Troubleshooting / Re: pin 13 doesn't seem to have any power? on: January 14, 2012, 12:35:48 am
thanks; that would be great.

by the way, when you say the serial won't work, do you mean that IF I connected those pins then it would be DAMAGED?

No, since one is an input and one is an output. If you connected to output pins, one driven HIGH and one driven LOW, you'd likely break something.

Actually, connecting the two serial pins together is a fine way to test the serial code. Just do a serial.write('a'); and then serial.read(); and hope you get 'a' back (but it's hard to see since you can't send anything to your computer!)
824  Using Arduino / Programming Questions / Re: learning c on: January 13, 2012, 11:19:14 pm
what dose it mean when i see <servo.h> or <stepper.h> are these files i need to have are dose the arduino already know.thanks

The preprocessor code "#include" takes the file specified and copy-and-pastes it in place of the #include. The preprocessor knows several places to look by default, then the Arduino IDE adds some more when it calls the preprocessor. Using angle brackets (like <servo.h>) means just look in those directory specified, and using quotes (like "myfile.h") looks in the same directory as your file being compiled first.

For if you need to get them, try compiling the code. If it compiles, great; you have them. If not, scroll up to the first (most useful) error message. If it says "cannot find stepper.h" then find a place to download it from and put it in your sketchbook, under a directory called "libraries"
825  Using Arduino / Programming Questions / Re: library definition on: January 12, 2012, 09:47:59 pm
What about looking into const global variables? They'll get optimized away no problem, and you'll be able to see them from every file in your project.
Pages: 1 ... 53 54 [55] 56 57 ... 71