Show Posts
Pages: 1 ... 62 63 [64] 65 66 ... 71
946  Using Arduino / Programming Questions / Re: Pulses per second? on: November 03, 2011, 06:54:15 pm
pulseIn() returns a value in microseconds. Since using unsigned longs means no fractions, the value of that equation will always be zero.
947  Using Arduino / Programming Questions / Re: Easier digital output on: November 03, 2011, 06:51:40 pm
If they're all on the same port, you can use Port Manipulation, or you could put all your pin numbers in an array and loop through the array:
Code:
byte pin_numbers[] = {3, 4, 6, 7, 8, 9}

for (byte i=0;i<6;i++) {
  digitalWrite(i, HIGH);
}

However, that is slower to execute. Then, there is always copy+paste smiley
948  Using Arduino / Programming Questions / Re: State of confusion on: November 02, 2011, 10:18:12 pm
Quiz:  What is misleading about the name of the 'Blink without delay' tutorial?

Well... it blinks... and it doesn't use delay... I give up.

Quote
The delay() function is one means for achieving a delay, but it ties up the entire processor in doing so.

Which is like the real connotations of the word, where a delay in a flight wastes everyone's time. Nobody says "I just bought my plane ticket but my flight is delayed until December," since they can do other things before December -- and doing one thing now (buying the plane ticket) and then doing another thing later (flying) is just like using millis in the Arduino language.
949  Using Arduino / Programming Questions / Re: State of confusion on: November 02, 2011, 08:46:35 pm
Delay is fine. However, the major problem with it is that you can only do one thing. In your example, you could turn the pump on every few minutes with delay, but if you want to add in something to turn on the water heater depending on the temperature of the water, you would have to completely restructure your code to not use delay. However, if it's just four lines of code, you might as well just use delay() and then write the more complicated stuff if the need arises.
950  Using Arduino / Programming Questions / Re: Countdown with TM1638 on: November 02, 2011, 07:56:19 pm
Sure. What exactly do you need help with, what have you done already, and what, specifically, do you want it to do? (5 minutes timer = something that beeps five minutes after a button is pressed? Or does it display the current time? Or do you want to make five timers that each count one minute?)
951  Using Arduino / Programming Questions / Re: Keyboard question on: November 01, 2011, 09:57:00 pm
You're going to have to disable auto-reset -- there's a trace you can cut on the back of the board, or a very specific valued resistor can go somewhere (google it).
952  Using Arduino / Programming Questions / Re: Infinite Loop when checking Client.connected()? on: November 01, 2011, 07:09:34 pm
In your if(!client.connected()) statement, there's nothing to break out of the while(1) loop you did earlier. While do you have the while(1) loop, anyway? If it's connected, you only go through one iteration before returning, and if it's not connected you stop the connection and probably want to break out of the loop immediately also.
953  Using Arduino / Programming Questions / Re: Keyboard question on: November 01, 2011, 07:02:25 pm
ASCII characters with SINGLE quotes (apostrophes) around them translate into the correct numbers.

Code:
/*There are all True*/
'b' == 98;
' ' == 32;
'A' == 65;
954  Using Arduino / Programming Questions / Re: Storing text/data charr array string on: November 01, 2011, 01:23:51 am
I made this for one of my projects, it might help out:

Code:
class CircularBuffer {
    public:
        CircularBuffer();
        void put(unsigned char c);
        void del();
        unsigned char get();
    private:
        static const uint8_t _size = 10;
        uint8_t _in, _out;
        char _buffer[_size];
        unsigned char increment(unsigned char);
        unsigned char decrement(unsigned char);
};

Code:
CircularBuffer::CircularBuffer() {
    _in = _out = 0;
}

inline unsigned char CircularBuffer::increment(unsigned char c) {
    return (c==_size-1)? 0 : c+1;
}

inline unsigned char CircularBuffer::decrement(unsigned char c) {
    return (c==0)? _size-1 : c-1;
}

void CircularBuffer::put (unsigned char c) {
    _in = increment(_in);
    //If _in == _out (we've wrapped around), delete the last value
    if (_in == _out) _out = increment(_out);
    _buffer[_in] = c; //Write c to buffer
}

void CircularBuffer::del () {
    //If there's anything in the buffer, move _in back
    if (_in != _out) _in = decrement(_in);
}

unsigned char CircularBuffer::get () {
    //If there's nothing in the buffer, return 0
    if (_out == _in) return 0;
    //Else, increment _out and return value
    _out = increment(_out);
    return _buffer[_out];
}
955  Using Arduino / Programming Questions / Re: Low power shutdown/failure/t'is quittin' time ... on: November 01, 2011, 01:18:07 am
What would be ideal is something like a LiPo protection circuit that completely cuts off power when the voltage is lower than a certain point, right? Then you just have to set it for above whatever the BOD is set at (+~1.5 for the regulator) and they should shut off at the same time.
956  Using Arduino / Programming Questions / Re: Waking from sleep mode. on: October 30, 2011, 10:11:36 pm
Because when I put it to sleep it will be asleep for weeks or months. In that time parameters would have changed. There is no point of the sketch running based on old data. When I want it to wake up I want it to run from the start of the sketch as if power has just been applied to it and reread its inputs.

If you wanted to, you could turn it off completely with something like this

There, you just hook your interrupt up to where it suggests putting a switch and trigger the OFF pin instead of sleeping.
957  Using Arduino / Programming Questions / Re: byte variable type on: October 30, 2011, 05:34:53 pm
Thanks for the replies. OK, here is the error message for

const byte arduinox[115][128] = { //

In file included from Test.cpp:9:
arduinoa.h:2: error: 'byte' does not name a type

The type "byte" is declared in Arduino.h (or WProgram.h). If you can't include Arduino.h, that explains that problem. Are you even attempting to include Arduino.h? There is usually an error message if avr-g++ cannot find it in its search path. It may be helpful to post more of your code.
958  Using Arduino / Programming Questions / Re: rotary encoder and robot distance on: October 30, 2011, 02:30:25 pm
I was thinking more along the lines of:
Code:
void loop() {
  servo1.writeMicroseconds(forward);
  Servo2.writeMicroseconds(forward);
  for (byte i=0;i<2;i++){
    while(digitalRead(photo) == HIGH); //Wait until photo is LOW
    while(digitalRead(photo) == LOW); //Wait until photo is HIGH
  }
  servo1.writeMicroseconds(stop);
  servo2.writeMicroseconds(stop);
  delay(1000);
  servo1.writeMicroseconds(forward);
  Servo2.writeMicroseconds(forward);
  for (byte i=0;i<4;i++){
    while(digitalRead(photo)==HIGH); //Wait until photo is LOW
    while(digitalRead(photo)==LOW); //Wait until photo is HIGH
  }
  servo1.writeMicroseconds(stop);
  servo2.writeMicroseconds(stop);
  delay(1000);
}

But, if it works for you and makes sense, great!
959  Using Arduino / Programming Questions / Re: rotary encoder and robot distance on: October 30, 2011, 01:19:58 pm
just wondering how is it useless?

If it's true, it increments pulse_count and prints some serial lines. If it's false, it increments pulse_count and prints the same serial lines.

Quote
what could i change it to, is there another way to count the pulses? well yes i am only reading it on one wheel. i think it will be a lot easier this way.

Oh wait, I think I get it... Are you trying to go forward 4 steps, pause, and then go forward 8 steps? You'll want to reset the pulse counter when it equals steps, but then it will just keep going 4 steps over and over. I just don't think your current function will work. What you could do is something like this:

Code:
void loop() {
  for (byte i=0;i<2;i++){
    while(digitalRead(photo) == HIGH); //Wait until photo is LOW
    while(digitalRead(photo) == LOW); //Wait until photo is HIGH
  }
  delay(1000);
  for (byte i=0;i<4;i++){
    while(digitalRead(photo)==HIGH); //Wait until photo is LOW
    while(digitalRead(photo)==LOW); //Wait until photo is HIGH
  }
  delay(1000);
}
960  Using Arduino / Programming Questions / Re: rotary encoder and robot distance on: October 30, 2011, 12:49:07 pm
I'm not sure if you're going to change this, but the "if" statement here is useless.
Code:
if (photo_State == HIGH) {
      pulse_Count++;
      Serial.print("number of pulsess:  ");
      Serial.println(pulse_Count, DEC);
  }
    else {
      pulse_Count++;
      Serial.print("number of pulsess:  ");
      Serial.println(pulse_Count, DEC);
  }

but that is pretty minor...

It appears that you only have one encoder for both motors. How does that work?
Pages: 1 ... 62 63 [64] 65 66 ... 71