Show Posts
Pages: 1 ... 65 66 [67] 68 69 ... 71
991  Using Arduino / Programming Questions / Re: Call millis() before setup on: October 04, 2011, 06:19:08 pm
Anything that involves pin modes, millis(), etc. is not ready for you to use until the init() method completes.

I don't see the code in init() that "initializes" pin modes, except pins 0 and 1. Is that the only exception you were talking about? What if we put UCSRB = 0; in our constructor before using pinMode?

It doesn't seem like using attachInterrupt in a constructor would hurt anything either, as long as the interrupt doesn't use millis(). (Is micros() okay? I don't really understand its code)
992  Using Arduino / Programming Questions / Re: Can I use analog pins using digitaRead? on: October 03, 2011, 08:52:13 pm
digitalRead(A0);
digitalRead(14);

Either one works.
993  Using Arduino / Programming Questions / Re: Tagging multiple sensors for Serial.print on: October 03, 2011, 06:47:38 pm
0x11, in ASCII, is Device Control 1. Serial Monitor doesn't know how to print "Device Control 1", so it doesn't. If you want to send the characters "0x11" then just println("0x11 " + aAccX);

Note that 0x11 is one byte, while "0x11" is 4 bytes ("11" is 2 bytes).

Also, if you have 2 devices that are both piping in data (I don't know how that works...), it's entirely possible that they'll both send data at the same time, so you could get "00xx1112  9587" with all of the data mashed together.
994  Using Arduino / Installation & Troubleshooting / Re: Code only runs when programmed. Not after reboot on: October 03, 2011, 05:41:12 pm
Try using PROGMEM: http://www.arduino.cc/en/Reference/PROGMEM
995  Using Arduino / Programming Questions / Re: Manage ports? on: September 19, 2011, 12:43:25 am
How is
Code:
value = portRead(PB);
different from  
Code:
value = PINB;

besides being a lot slower to execute? Pretty much the same thing for the other two.

Edit: fixing code tags...
996  Using Arduino / Programming Questions / Re: replace delay(xxxx) with button press?? on: September 19, 2011, 12:37:59 am
Think about what you mean by "pause and restart the shift register".

Is it that you want to hold off in displaying the next digit, and then start back and display the first digit again?

For the first part, you can write a loop that just checks for the button and only gets out of the loop when the button is pressed.
Something like this:
Code:
while(!digitalRead(pin)); // Assuming you want to continue when the button is HIGH

For the second part, there's a handy command called "continue" that skips the rest of what's happening in the loop function and goes back to the beginning.
I'd do something like this:
Code:
if(restart) {
    continue;
}

Also, the comment in the code
Code:
//Arduino doesn't seem to have a way to write binary straight into the code
  //so these values are in HEX.  Decimal would have been fine, too.
is not true at all. Just type B before you put in the ones and zeros. Only works in arduino, not c++, though.
997  Using Arduino / Programming Questions / Re: Problem with "Shift Register" on: September 18, 2011, 02:54:08 pm
How to control a shift register:
Connect three wires, data, clock, and latch, from the shift register. If you more than one shift register, connect the clock and latch pins to each one, and the "data out" of one to the "data in" to the other.

Then, to control it, you do a digitalWrite for the value the first output should have on the data wire. Then, digitalWrite the clock pin high and then low again. Repeat for each output on each shift register. Then digitalWrite the latch pin high and then low again. At this point, the outputs should become the values you tell them to.

This can be simplified by using the shiftOut function. To use this, just give it the three pins, the order (MSBFIRST or LSBFIRST, it doesn't matter which you choose, but if your image is backwards, switch them around) and the data you want to send -- in your case, what LEDs you want to light up (use the format "B00111010" to get the first two LEDs off, the next three on, etc)

How to control an LED Matrix:
The basic premise of controlling an LED Matrix that you light the appropriate LEDs for one row and cycle through the rows. Attach all of the rows to one shift register and all of the columns to another. Then, use something like the TimerOne library to call a function every 100 ms. The function should retain a counter of what row it's currently on, then use a lookup table to figure out what column LEDs to turn on.

Here's some example code that is untested.
Code:

#include <TimerOne.h>

byte picture[8] = {
    B01100110,
    B11100111,
    B11111111,
    B01111110,
    B01111110,
    B00111100,
    B00011000,
    B00011000,
}

const int clockPin = 9;
const int dataPin = 10;
const int latchPin = 11;

void setup() {
    TimerOne.initialize(1000);              //These two lines have the arduino automatically
    TimerOne.attachInterrupt(screenUpdate); //call screenUpdate every 1000 microseconds
}

void loop() {
    for (int i=0; i < 8; i++) {
        picture[i] = ~picture[i]; // Reverse each row
    }
    delay(500);
}

void screenUpdate() {
    static int curRow = 1; // Static means keeps value loop to loop

    //~_bv means the inverse bit value of curRow -- basically
    //~_bv(1) = B11111110, ~_bv(2) = B11111101, ~_bv(3) = B11111011..

    //invert because the rows are generally the negatives of the LEDs
    shiftOut(dataPin, clockPin, MSBFIRST, ~_bv(curRow));

    //shiftOut the data for the current row.
    shiftOut(dataPin, clockPin, MSBFIRST, picture[curRow]);
    curRow = (curRow + 1) % 8; //Increase curRow, and loop to 0 if it's 8
}
998  Using Arduino / Programming Questions / Re: Emergengy Stop Help on: September 17, 2011, 05:03:36 pm
If you wanted to be able to recover from the estop, you could have the estop function detach it's own interrupt and attach another interrupt (on a LOW to HIGH)  that would set the flag to false (plus detach itself and attach the estop function).

something like this:
Code:
void estop() {
    estopFlag = true;
    detachInterrupt(2);
    attachInterrupt(2, unstop, RISING);
}

void unstop() {
    estopFlag = false;
    detachInterrupt(2);
    attachInterrupt(2, estop, FALLLING);
}
999  Using Arduino / Programming Questions / Re: Shift registers code on: September 14, 2011, 08:37:31 pm
Code:
shiftOut(dataPin, clockPin, bitOrder, dataToSendToFirstOne);
shiftOut(dataPin, clockPin, bitOrder, dataToSendToSecondOne);
shiftOut(dataPin, clockPin, bitOrder, dataToSendToThirdOne);
shiftOut(dataPin, clockPin, bitOrder, dataToSendToFourthOne);
//...

digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
1000  Using Arduino / Programming Questions / Re: I would like to use this code but how do i modify to suit servos on: September 13, 2011, 07:53:45 pm
Nice code. Do you have a question you would like to ask?

By the way, [code] tags are very useful.
1001  Using Arduino / Programming Questions / Re: Arduino pointer-to-function broken? Compiler Issue? on: September 13, 2011, 07:51:34 pm
I'm not sure if you founds this already, but here's the information about program memory: http://arduino.cc/playground/Main/PROGMEM
1002  Using Arduino / Programming Questions / Re: A question to Gentoo users on: September 06, 2011, 12:53:36 pm
The code you put on an arduino should have nothing to do with what operating system, much less which distro, you're using, unless the versions of avr-gcc are different.

Where is this "bug" documented? I've never heard of it before.
1003  Using Arduino / Programming Questions / Re: Arduino Pin to Port n,x conversion ? on: September 06, 2011, 12:47:22 pm
I've done direct port manipulation with a class (with changing pins) and it's not that hard. In your constructor/initialization where you get the pin numbers, do
Code:
pinBit = digitalPinToBitMask(pinNumber);
pinBitNOT = ~pinBit; //Optional -- uses more memory, but makes writing LOWs faster
uint8_t pinPort = digitalPinToPort(pinNumber);
pinOut = portOutputRegister(pinPort);
EDIT: You also have to include pins_arduino.h

where pinNumber is the user-supplied pin number, pinBit and pinBitNOT are class variables of uint8_t type, and pinOut is another class variable, but is a pointer to a uint8_t. Then, to do the actual writing, do this:
Code:
if (/*you want to write HIGH*/) {
    *pinOut |= clockBit;
}
else {
    *pinOut &= clockBitNOT;
    //if you don't want to use the extra memory of clockBitNOT, do this
    *pinOut &= ~clockBit;
}
digitalWrite also likes to disable interrupts while writing to the registers, which can be done by
Code:
uint8_t old_SREG = SREG;
cli();
before you write to *pinOut and
Code:
SREG = old_SREG;
afterward.
1004  Using Arduino / Programming Questions / Re: Reading a File in the Sketchbook from a Library on: September 06, 2011, 12:07:24 pm
Try

Code:
#include "file.h"

Using <> tells the compiler to search everywhere, "" looks in the curr. directory, only.

I was under the impression that the brackets method was a full subset of the quotes, and the quotes just told it to look in the current directory. Nevertheless, I have tried to simply include it with no results.
1005  Using Arduino / Programming Questions / Reading a File in the Sketchbook from a Library on: September 04, 2011, 05:34:04 pm
Hello,

So I wrote a library that can read IR remotes and gives the user the name of the button pressed. In order to get the names, I wrote another application that runs on a PC and makes two header files containing all the stored codes and their user-generated names. Right now I have it saving the files in the same directory as my library, but that means that user can't have two different sets of codes that stick with the program, it is just one set that each program they write uses.

I would like to put the header files in with their .pde file, but my problem is that I don't know how the library can read from the sketchbook, in the same folder as the calling program. Is this possible?

Thank you!
Pages: 1 ... 65 66 [67] 68 69 ... 71