I am making an interactive bulletin board that displays a special catheter being placed by pushing a button. This will use two servos with each moving an EL wire to show the movement. The button I was going to hook up to the reset button for simplicity. I am still stuck on my code though and thought maybe someone could help me. I would like for the servo to move for about 3 seconds in each direction (0-180) and the EL wire to flash in increasing intensity until the servo reaches zenith(180), then reverse. I also want my arduino to sleep conserving battery life. I have tested parts of this with pasted pieces and they work OK. So now I'm on the nitty gritty of putting it all together. :~
#include <TimedAction.h>
#include <Servo.h>
#include <avr/sleep.h>
TimedAction ELWireAblink = TimedAction(500,ELWireAblink1);//Blink EL Wire at Interval
TimedAction ELWireBblink = TimedAction(500,ELWireBblink2);//Blink EL Wire at Interval
TimedAction MyServo1Action = TimedAction(15,MyServo1Action1);//Moves Servo
TimedAction MyServo2Action = TimedAction(15,MyServo2Action2);//Moves Servo
#define relayPin 13
#define elwireAPin 2
#define elwireBPin 3
//#define MyServo1Pin 9
//#define MyServo2Pin 10
boolean relayPinState = false;
boolean ELWireAState = false;
boolean ELWireBState = false;
//boolean MyServo1State = false;
//boolean MyServo2State = false;
Servo servo1; // create servo object to control a servo
Servo servo2; // a maximum of eight servo objects can be created
int pos = 5; // variable to store the servo position
int sleepStatus = 4; // variable to store a request for sleep
int count = 3; // counter
void wakeUpNow() //I am not using this here since I will be using the reset button to wake the arduino up
// here the interrupt is handled after wakeup
{
// execute code here after wake-up before returning to the loop() function
// timers and code using timers (serial.print and more...) will not work here.
// we don't really need to execute any special functions here, since we
// just want the thing to wake up
}
void setup()
{
pinMode(relayPin, OUTPUT);//Drives Relay for ELWire Power
pinMode(elwireAPin, OUTPUT);//Lights ELWire
pinMode(elwireBPin, OUTPUT);//Lights ELWire
digitalWrite(elwireAPin,ELWireAState);
digitalWrite(elwireBPin,ELWireBState);
digitalWrite(relayPin,relayPinState);
servo1.attach(9); // attaches the servo on pin 9 to the servo object
servo2.attach(10);// attaches the servo on pin 10 to the servo object
servo1.write(0);//Sets the Servo to the start postion
servo2.write(0);//Sets the Servo to the start postion
/* Now it is time to enable an interrupt. In the function call
* attachInterrupt(A, B, C)
* A can be either 0 or 1 for interrupts on pin 2 or 3.
*
* B Name of a function you want to execute while in interrupt A.
*
* C Trigger mode of the interrupt pin. can be:
* LOW a low level trigger
* CHANGE a change in level trigger
* RISING a rising edge of a level trigger
* FALLING a falling edge of a level trigger
*
* In all but the IDLE sleep modes only LOW can be used.
*/
// use interrupt 0 (pin 2) and run function
// wakeUpNow when pin 2 gets LOW
}
void sleepNow() // here we put the arduino to sleep
{
/* Now is the time to set the sleep mode. In the Atmega8 datasheet
* http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf on page 35
* there is a list of sleep modes which explains which clocks and
* wake up sources are available in which sleep mode.
*
* In the avr/sleep.h file, the call names of these sleep modes are to be found:
*
* The 5 different modes are:
* SLEEP_MODE_IDLE -the least power savings
* SLEEP_MODE_ADC
* SLEEP_MODE_PWR_SAVE
* SLEEP_MODE_STANDBY
* SLEEP_MODE_PWR_DOWN -the most power savings
*
* For now, we want as much power savings as possible, so we
* choose the according
* sleep mode: SLEEP_MODE_PWR_DOWN
*
*/
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
sleep_enable(); // enables the sleep bit in the mcucr register
// so sleep is possible. just a safety pin
/* Now it is time to enable an interrupt. We do it here so an
* accidentally pushed interrupt button doesn't interrupt
* our running program. if you want to be able to run
* interrupt code besides the sleep function, place it in
* setup() for example.
*
* In the function call attachInterrupt(A, B, C)
* A can be either 0 or 1 for interrupts on pin 2 or 3.
*
* B Name of a function you want to execute at interrupt for A.
*
* C Trigger mode of the interrupt pin. can be:
* LOW a low level triggers
* CHANGE a change in level triggers
* RISING a rising edge of a level triggers
* FALLING a falling edge of a level triggers
*
* In all but the IDLE sleep modes only LOW can be used.
*/
// use interrupt 0 (pin 2) and run function
// wakeUpNow when pin 2 gets LOW
sleep_mode(); // here the device is actually put to sleep!!
// THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
sleep_disable(); // first thing after waking from sleep:
// disable sleep...
// disables interrupt 0 on pin 2 so the
// wakeUpNow code will not be executed
// during normal running time.
}
void loop()
{
digitalWrite(relayPin, HIGH);//Turns on Relay for ELWire
ELWireAblink.check();//Trigger ELWire 0.5 Seconds
ELWireBblink.check();//Trigger ELWire 0.5 Seconds
MyServo1Action.check();//Moves the first Servo
MyServo2Action.check();//Moves the second Servo
void ELWireAblink1(){//This is where I have left off
//This is OLD code for Servo Movement
//for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
//{ // in steps of 1 degree
// servo1.write(pos); // tell servo to go to position in variable 'pos'
// delay(25); // waits 15ms for the servo to reach the position
//}
//for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
//{
// servo2.write(pos); // tell servo to go to position in variable 'pos'
// delay(25);
// } // waits 15ms for the servo to reach the position
digitalWrite(13,LOW);//Turns the Relay Off
sleepNow(); // sleep function called here to conserve energy
}