Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 283
61  Using Arduino / Programming Questions / Re: Time and TimeAlarms Libraries – Ask here for help or suggestions on: August 10, 2014, 01:13:17 am
Hey guys,

I happen to have a question about TimeAlarms. Can you use the TimeAlarm library to activate a servo motor at a certain time? And also, can you sync the RTC DS1307 to the TimeAlarm?  If you can, how do you? Any help would be appreciated. Thanks.
The answer to both of these is yes.  Look at the example with the TimeAlarms library to see how to carry out actions at specific times or to repeat them at specific intervals.  The TimeAlarms library makes use of the Time library which makes it possible to synch the alarms with an RTC.  Simply set the time using the RTC and it becomes available to TimeAlarms.
62  Using Arduino / Programming Questions / Re: Time and TimeAlarms Libraries – Ask here for help or suggestions on: August 10, 2014, 01:07:19 am
Quote
i didn't know there were a library folder there too..
The libraries folder in the sketch folder is designed to hold user contributed libraries that are available to all versions of the IDE of which there may be several installed as it is upgraded.  The libraries folder under the main Arduino folder is designed to hold libraries supplied with the IDE of which there could potentially be more/different versions specific to an IDE version.
63  Using Arduino / Programming Questions / Re: Time and TimeAlarms Libraries – Ask here for help or suggestions on: August 09, 2014, 02:50:19 pm
It would be better to put the Time library in the correct place which is the libraries folder of the sketch folder.

Like this C:\Users\Bob\Documents\Arduino\libraries

The point about having the library folder one level too deep still stands though.
64  Using Arduino / Programming Questions / Re: Combining Codes on: August 09, 2014, 02:10:59 pm
Quote
I've read about there being an alarm library I think, although I've never used it
TimeAlarms is probably what you are thinking of.  Very easy to use.
65  Using Arduino / Programming Questions / Re: When to use interrupt? on: August 08, 2014, 11:33:38 am
Scott Adams
Quote
You can never underestimate the general public
66  Using Arduino / Programming Questions / Re: When to use interrupt? on: August 08, 2014, 10:43:38 am
Wow.  Less reaction than I expected so far.
Of course the correct use of interrupts is predicated on the user understanding them as is the use of polling an input pin.

Quote
I've got the fryer on, making chips
The doorbell rings.
I go to answer the door.
I have a twenty minute conversation with the postman.
(My house burns down.)
That could happen just as easily if you listened for the doorbell using polling as it could using interrupts.

It is quite fun being on the Dark side sometimes (I must have been reading too much Harry Potter recently) even if you are only pretending  smiley
67  Using Arduino / Programming Questions / Re: Run script or java on: August 08, 2014, 10:27:23 am
I assume that you have stopped and started the IDE since installing the library and that other libraries installed in the same folder work OK.  The most common cause of problems with libraries is that they are installed in the wrong place, usually the Arduino libraries folder. that the folder does not have the same name as the .h and .cpp files or that an extra folder has been created under the sketch folder\libraries\library folder.

What is the full path to the Time.h file ?
68  Using Arduino / Programming Questions / Re: Run script or java on: August 08, 2014, 05:01:00 am
Quote
Blink.ino:2:17: fatal error: Time.h: No such file or directory
Seems fairly self explanatory to me. 
Do you have a file named Time.h in a folder called Time in the libraries folder of your sketch directory ?
69  Using Arduino / Programming Questions / Re: When to use interrupt? on: August 08, 2014, 04:48:13 am
Gotcha, thanks.
Bear in mind that is only my take on it.

There is no reason, for instance, why an interrupt should not be used to respond to a button press even if it can be done by simply polling the input.  In fact, turning Devil's advocate, I could make a case to encourage people to use interrupts more often as long as they understand what they are doing.  It's just a shame that there are not more interrupts available (pin change interrupts excepted) on most Arduinos.

Stands back, puts on flack jacket and awaits comments.

70  Using Arduino / Programming Questions / Re: When to use interrupt? on: August 08, 2014, 03:07:11 am
Quote
What sort of circumstances typically warrant the use of an interrupt?
When the action to be reacted to could happen at any time and needs to be noticed without delay or could itself be so transient as to possibly be missed otherwise.

An example in my case is reading the input from encoders on robot wheels to count the number of turns of the wheel.  These inputs are used to ensure that each wheel is running at the same speed by adjusting one or both if a mismatch is detected.  Meanwhile the robot is scanning for obstructions by rotating a servo, flashing LEDs to indicate its current state etc. 

The encoder signal could arrive at any time and is by its nature is transient so could be missed.  Instead the ISR flags receipt of the input, increases a counter and exits.  The value of the counters is compared next time through loop(), during which time it is possible that they have been incremented several times, and the wheel speed(s) are adjusted.

If the encoders were polled in loop() then they could be in one of 2 states but the ISR ensures that the number of state transitions are counted correctly.
71  Using Arduino / Programming Questions / Re: Teach me what I'm doing wrong (again) on: August 08, 2014, 02:56:12 am
Using a FSM the system stays in a state until it is changed either by time elapsing of by an input changing.  So, yes, you can have the system stay in a state for an indefinite period of time by not using elapsed time as an exit condition for the state.

Here is some psuedo code to illustrate the principle.  It aims to wait with an LED off until a button is pressed then to blink the LED until the button is pressed again.  It can of course be extended to do other things and have more states.
Code:
state = 0
start of loop()
  switch state
    case 0
      wait for a button press
      if button A becomes pressed
        state = 10
        save start time
        turn on LED A
      end if
     
      case 10
        if period has elapsed
          state = 11
          save start time
          turn off LED A
        end if
       
        if button A becomes pressed
          turn off LED A
          state = 0
        end if
       
        case 11
        if period has elapsed
          state = 10
          save start time
          turn on LED A
        end if
       
        if button A becomes pressed
          state = 0
        end if
       
  end switch
end of loop() 
It is, of course, not real code but should show you the shape of what you are aiming for.
72  Using Arduino / Programming Questions / Re: How Arduino know which pins from a potentiometer connected on: August 08, 2014, 02:28:46 am
Code:
#define no_samples 44100
uint16_t nSineTable[no_samples];//storing 12 bit samples in 16 bit variable.
What Arduino is this being run on ?
73  Using Arduino / Programming Questions / Re: Teach me what I'm doing wrong (again) on: August 08, 2014, 02:23:14 am
Quote
Essentially what I want the code to do is to continually repeat this code

I just saw your latest post and see that it is the flashing LEDs that you want to repeat.  The for loop will do that but will extend the delay time by 5 so the program will become unresponsive for longer.  If you want to have the LEDs flash continuously until interrupted by an input then look at using the timing principle used in the BlinkWithoutDelay example in the IDE.

Save a start time and check frequently whether the required time period has elapsed.  If so then do whatever is required next.  If not then do something else such as reading an input and reacting to it.  At any point in time your program will be in a known state so the BWD principle lends itself well to being used as part of a Finite State Machine, which sound scary but isn't.

When the timing period finishes or input is detected change a state variable to a new value.  Then in loop() use if statements or switch/case to execute the required commands for that state.  Start by writing out all the states on paper, the conditions needed to exit each state and the state number to move to on exit.  The program then almost writes itself.
74  Using Arduino / Programming Questions / Re: Serial port communication keeps disconnecting for unknown reason on: August 08, 2014, 01:34:08 am
Quote
So its actually 3 different serial ports that use the same baud rate.
How many serial ports on the Arduino are they connected to and how ?
75  Using Arduino / Programming Questions / Re: Adafruit Motor Shield 2 Motors MATLAB on: August 07, 2014, 02:52:47 pm
A suggestion for you.  Forget about using MATLAB to control the motors for now and write a program to do it on the Arduino, perhaps as a series of actions to be taken each time through loop()
Pages: 1 ... 3 4 [5] 6 7 ... 283