I need to have a panel with several switches - say, 6 for example - could be more (probably would need a Mega but the principle should be the same). Let me know if this makes sense:
I quess each switch would be connected to a digital i/o pin - all the switches on a +5v bus, feeding that to the connected i/o pin when pushed; the +5v supply having common ground with the Arduino.
I think a for loop constantly scanning the button pin numbers could call a generalized servo actuation routine that would actuate the servo when the button was set high.
The actuation routine would be passed one or more parameters from arrays of integers; one array would link button numbers to output pins (servo numbers - not necessarily the same?). Other arrays might link button number to start and stop position values.
The actuation routine would read servo position, and dependent on position move to the other position - would these need to be passed, or could they be determined by a read being more or less than 90 degrees? The individual servos may need some adjustment to the range of movement, and I envision editing the array defintion code as necessary to change the high and low positions
Other actuation events would include setting i/o pins to actuate DPDT latching relays to both energize the appropriate pins of 3 pin red/green LEDs (which color would be dependent on individual servo situations - or perhaps to individual LEDs on the panel) and to likewise feed external A or B sources to an external output. The LED state and external feed state would remain until switched again (press button 3 once, servo goes to desired position; LED lights accordingly, external feed is set accordingly); press button 3 again LED and output are switched. I think I may need an initializing routine for LEDs and feeds based on a read of servo positions.
I think that with two or three arrays I could furnish and adjust as necessary the various parameters.
I realize this is kind of long, and sincerely appreciate any guidance you can provide to a newbie to this language and system.
Write each part as a short function that can be developed and tested separately. See Planning and Implementing a Program. And before you start make sure to write down very precisely all the actions that are required.
If the relays and the LEDs operate synchronously one output pin may be useful for two actions.
Take advantage of the fact that LEDs are polarized. For example one output pin could cause swap a pair of LEDs.
If you are using electromechanical relays don't connect the coils directly to an Arduino. Put a transistor between them to handle the relay coil current.
Although there is a read() method in the Servo library all it does is to return the value passed to the last call to write() so be cautious about using it.
"If you are using electromechanical relays don't connect the coils directly to an Arduino. Put a transistor between them to handle the relay coil current."
Could you outline this a bit more for me - I'm a bit hardware impaired, trying to become less so - would a Darlington Array chip like a ULN-2004 do the job? What would the breadboard hookup look like?
UKHeliBob said:
"Although there is a read() method in the Servo library all it does is to return the value passed to the last call to write() so be cautious about using it."
"Write each part as a short function that can be developed and tested separately. See Planning and Implementing a Program. And before you start make sure to write down very precisely all the actions that are required."
A great link; that's pretty much what I'd planned to do from experience in other environments, but the specific Arduino environment examples are much appreciated.