Show Posts
Pages: 1 ... 11 12 [13] 14 15 ... 24
181  Using Arduino / Programming Questions / Re: Reading the value of an output pin? on: January 14, 2013, 01:44:01 pm
Here's the basic logic that I use to handle relays.

Code:
byte relayPin;                             // point to the relay's pin
int relayState = LOW;                  // keeps the relay state as HIGH or LOW

void setup(){
     pinMode(relayPin, OUTPUT);            // set the pin to output
     digitalWrite(relayPin, relayState);    // write the current state to it
}

// now we'll check the relay to see if it should be on or off
void loop(){
     int flag = LOW;                   // start with a flag set to low
     if (The relay should be on for whatever reason)   // obviously not real code
     {
          flag = HIGH;
     }
     // now compare the flag to the relayState
     if (flag != relayState)
     {
          relayState = flag;                                  // assign flag's value to relayState
          digitalWrite(relayPin, relayState);         // write this new state to the pin
     }
}

It's pretty sane and easily allows for more than one reason to keep the relay on. The relay only gets changed if needed.
182  Community / Bar Sport / Re: Aaron Swartz sucide on: January 12, 2013, 04:51:17 pm
Same age as my son. Terrible.

The world can be an unkind place to the genius.
183  Using Arduino / Programming Questions / Re: Help with this code to blink the LCD screen on my MEGA. Please help.... on: January 11, 2013, 04:33:01 pm
Looks to me like your guy sent you a library. It's up to you to wrap it with some code to do what you want. What you want will likely be a cross between blink without delay and the method that library has for controlling the backlight.

Would it be accurate to guess that you have two files  LCD4884.h and  LCD4884.cpp?
184  Using Arduino / Programming Questions / Re: time functions such as hourFormat12() on: January 11, 2013, 04:30:06 pm
Unix time is in seconds. I took a look at the time library header and it appears that hourFormat12() should return the hour in a 12 hour format (as opposed to hour() which is 24) it also appears to have an overload to return the hour when passed Unix time.

Have you tried the hour() method to see if that works?

Personally, I only ever use a 24 hour clock.
185  Using Arduino / Programming Questions / Re: time functions such as hourFormat12() on: January 11, 2013, 11:39:33 am
Code:
setTime(pctime);   // Sync Arduino clock to the time received on the serial port

The rest of that is overhead for reading the input from serial. Program your buttons to get hours, minutes, seconds (if you want), convert to a Unix time and pass as a parameter to the setTime() function. If you need the date set you'll have to include that in your Unix time parameter.
186  Using Arduino / Programming Questions / Re: Millis(), an interesting problem on: January 10, 2013, 01:44:36 pm
It can only stay in that while loop for one iteration. You immediately assign t2 the current millis() which will obviously make it larger than t1. Looks to me like you should update t1 not t2 in that loop.

You've really just programmed your own delay() which isn't a good way to do this. Read through and understand the blink without delay for the better way to do this.
187  Using Arduino / Project Guidance / Re: switch case question on: January 09, 2013, 11:56:51 am
I just skimmed your code and one thing I see is that it doesn't appear that you have a way to show the mode without changing it. If you were playing a game that used different sided dies then it would be nice to see the mode before shaking.

My approach to this would be to use two push buttons. One to display and one to change modes. I would have it display the mode as long as one button was held down. I'd also make it so that you have to display the mode before you can change it. So you'd hold down that button to display the mode then use the other button to change through the modes. This would also make accidentally changing modes more difficult.
188  Using Arduino / Project Guidance / Re: switch case question on: January 08, 2013, 04:21:30 pm
Yes you can but I don't see why you'd need to in this case.

It sounds to me like you select a mode once, then roll as often as you want.  You could use an array to store how many sides each mode represents then use the mode as the index. I don't really see a need for a switch statement at all but you must have another idea.

Code:
// I see it like this
int mode = 0;
int dice[] = {2, 4, 6, 8, 10, 12, 20}; // or whatever your dice are

void loop(){

// Check the button and increment mode with rollover (0..6)

// if the device is shaken call the random function (I'll assume it's seeded)

int rollResult = random(dice[mode]); // you may want to add one to this

// display roll result

}

// there is quite a bit of code assumed in these comments I was really just demonstrating my logic

189  Using Arduino / Programming Questions / Re: NUMBER_MOTOR'was not declared in this scope on: January 08, 2013, 09:54:21 am
You'll need to post the code to get help here. Remember to use the code tags - the little edit icon with the # on it.

If the code is too long attach it.

There are some very helpful people here but none are psychic.
190  Using Arduino / Project Guidance / Re: code question on: January 07, 2013, 07:59:16 pm
Code:
delay (5000)

That line is missing the semi-colon.

You know that in the second line of the errors you posted that 116 is a line number. It's a good place to start looking. Usually the error is before the line where the compiler starts puking.
191  Using Arduino / Project Guidance / Re: code question on: January 07, 2013, 05:40:01 pm
Code:
void motion ();

That's probably causing a bunch of those last errors. The semi-colon ends a statement and it looks like you were declaring a function. You have no curly braces just a semi-colon. This incorrectly declared function is also the apparent cause of the first (not declared in this scope) error.
192  Using Arduino / Programming Questions / Re: Arduino Class C++ on: December 31, 2012, 12:25:14 pm
There is an excellent tutorial on classes (and other stuff) at cplusplus.com

http://cplusplus.com/doc/tutorial/classes/
193  Using Arduino / Programming Questions / Re: Quick Question about updating a variable in 'void loop()' on: December 29, 2012, 09:09:18 pm
Code:
int SPACE = map(analogRead(3), 0, 256, 0, 1024); /* Delay time between steps (mapped from approx. 0-1s)

This declaration only declares a variable named SPACE and assigns it the value of the mapped read on the right of the = sign. Before setup runs this is likely no good. To update it this reading has to happen frequently like once a loop.

Code:
//So instead of
SPACE = SPACE;

//  in loop() use

SPACE = map(analogRead(3), 0, 256, 0, 1024);
Or you could make SPACE a function.
Code:
int SPACE(void) {
     return map(analogRead(3), 0, 256, 0, 1024);
}

Then replace every reference to SPACE with the call to the function SPACE() and get a fresh reading each time. No need to read in loop() this way.

From my experience with Arduino I'd just read it in loop() and use the variable approach. The way it appears you thought it should work is more like the function.
194  Using Arduino / Programming Questions / Re: Im sure there is a better way to do this... on: December 29, 2012, 04:22:40 pm
Code:
byte (orange = 0);

My guess is that the brackets eliminated a previous compile error about redeclaration of a variable.

Throwing bits of punctuation and brackets at your code to get it to pass through the compiler, is a sure way to some serious head scratching down the road when things aren't working.

I know, lessons learned the hard way.
195  Using Arduino / Programming Questions / Re: new here and have no clue on: December 28, 2012, 03:33:11 pm
I don't think the OP was written by an 80 year old. The grammar doesn't really match. Most 80 year olds I know are apt to over punctuate, not ignore it entirely. Also, 80 year olds picking up something new are eager beavers when it comes to learning.

Coincidentally a good friend's dad (he's 80) is going to start playing with Arduinos. This was no surprise to me. The last words he'd ever say is that he didn't want to learn something new.

I think the OP is a sock puppet.
Pages: 1 ... 11 12 [13] 14 15 ... 24