mirror of
				https://github.com/digistump/DigistumpArduino.git
				synced 2025-11-03 13:04:48 -08:00 
			
		
		
		
	Initial import of support files for all Digistump boards - Digispark, Pro, DigiX - including libraries, examples, tools, and other support files for the Arduino IDE
This commit is contained in:
		@@ -0,0 +1,192 @@
 | 
			
		||||
/*
 | 
			
		||||
Sketch using <RcSeq> library, for automatically dropping a pneumatic Zodiac at sea and returning for it back to the deck of a supply vessel.
 | 
			
		||||
The sequence is launched after sending the 'g' (Go) character at the USB interface.
 | 
			
		||||
 | 
			
		||||
In this example, the declared sequence is:
 | 
			
		||||
1) The crane lifts the pneumatic Zodiac from the deck to the air and stops
 | 
			
		||||
2) The crane rotates (90°) to locate the pneumatic Zodiac above the sea
 | 
			
		||||
3) The crane drops down the pneumatic Zodiac at sea level
 | 
			
		||||
4) The crane stops during 6 seconds
 | 
			
		||||
5) The crane lifts up the pneumatic Zodiac from sea level to the air and stops
 | 
			
		||||
6) The crane rotates (90°) to locate the pneumatic Zodiac above the deck
 | 
			
		||||
7) The crane drops down the pneumatic Zodiac on the deck and stops. The sequence ends.
 | 
			
		||||
This sequence uses:
 | 
			
		||||
- 2 commands from USB interface ('g' and 't' characters from Digiterm or Digi Monitor)
 | 
			
		||||
- 2 servos (a "ROTATION" servo for the crane rotation and an "UP/DOWN" servo to drop and lift the pneumatic Zodiac)
 | 
			
		||||
 | 
			
		||||
IMPORTANT:
 | 
			
		||||
=========
 | 
			
		||||
For this sketch, which is using <DigiUSB> library:
 | 
			
		||||
1) Comment "#define RC_SEQ_WITH_SOFT_RC_PULSE_IN_SUPPORT" in "arduino-1.xx\libraries\RcSeq.h".
 | 
			
		||||
   This will disable the code to manage incoming RC pulses and save some flash memory.
 | 
			
		||||
2) Replace #define RING_BUFFER_SIZE 128 with #define RING_BUFFER_SIZE 32 in "arduino-1.xx\libraries\DigisparkUSB\DigiUSB.h".
 | 
			
		||||
3) The sequence will be launch by sending "g" character through USB link (using Digiterm or Digi Monitor).
 | 
			
		||||
   To check all the sequence is performed asynchronously, you can send 't' to toggle the LED during servo motion!
 | 
			
		||||
If step 1) and 2) are not done, this sketch won't compile because won't fit in programm memory of the DigiSpark!
 | 
			
		||||
 | 
			
		||||
RC Navy 2013
 | 
			
		||||
http://p.loussouarn.free.fr
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
static void ToggleLed(void); /* Declare Short Action: Toggle a LED */
 | 
			
		||||
 | 
			
		||||
/*************************************************/
 | 
			
		||||
/* STEP #1: Include the needed libraries         */
 | 
			
		||||
/*************************************************/
 | 
			
		||||
#include <DigiUSB.h> /* The Servo Sequence will be launched by sending "g" character (Go) at the USB interface */
 | 
			
		||||
#include <RcSeq.h>
 | 
			
		||||
#include <SoftRcPulseOut.h>
 | 
			
		||||
 | 
			
		||||
#define LED_PIN		                1
 | 
			
		||||
 | 
			
		||||
/*****************************************************************/
 | 
			
		||||
/* STEP #2: Enumeration of the servos used in the sequence       */
 | 
			
		||||
/*****************************************************************/
 | 
			
		||||
enum {ROTATION_SERVO=0, UP_DOWN_SERVO , SERVO_NB};
 | 
			
		||||
 | 
			
		||||
/*****************************************************************/
 | 
			
		||||
/* STEP #3: Servos Digital Pins assignment                       */
 | 
			
		||||
/*****************************************************************/
 | 
			
		||||
#define UP_DOWN_SERVO_PIN          2
 | 
			
		||||
/* /!\ Do not use Pin 3 (used by USB) /!\ */
 | 
			
		||||
/* /!\ Do not use Pin 4 (used by USB) /!\ */
 | 
			
		||||
#define ROTATION_SERVO_PIN          5
 | 
			
		||||
 | 
			
		||||
/**************************************************************************************/
 | 
			
		||||
/* STEP #4: Declaration of the angles of the servos for the different motions (in °)  */
 | 
			
		||||
/**************************************************************************************/
 | 
			
		||||
#define UP_DOWN_ON_DECK_POS		120 /* Zodiac on the deck  */
 | 
			
		||||
#define UP_DOWN_ON_AIR_POS		180 /* Zodiac in the air   */
 | 
			
		||||
#define UP_DOWN_ON_SEA_POS		0   /* Zodiac at sea level */
 | 
			
		||||
 | 
			
		||||
#define ROTATION_ABOVE_DECK_POS	90  /* crane at deck side  */
 | 
			
		||||
#define ROTATION_ABOVE_SEA_POS		0   /* crane at sea  side  */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/***************************************************************************************************************************************/
 | 
			
		||||
/* STEP #5: Do a temporal diagram showing the start up and the duration of each motions of each servo                                  */
 | 
			
		||||
/***************************************************************************************************************************************/
 | 
			
		||||
/*
 | 
			
		||||
All the start up values (time stamp) have as reference the moment of the sequence startup order (t=0).
 | 
			
		||||
 | 
			
		||||
                            UP_DOWN_SERVO MOTION             ROTATION_SERVO MOTION                 UP_DOWN_SERVO MOTION           NO MOTION MOUVEMENT(WAITING)        UP_DOWN_SERVO MOTION                     ROTATION_SERVO MOTION              UP_DOWN_SERVO MOTION
 | 
			
		||||
Order                  <--DECK_TO_AIR_DURATION_MS--> <--DECK_TO_SEA_ROTATION_DURATION_MS--> <--AIR_TO_SEA_FALLING_DURATION_MS--> <--DELAY_BEFORE_RISING_UP_MS--> <--SEA_TO_AIR_RISING_DURATION_MS--> <--SEA_TO_DECK_ROTATION_DURATION_MS--> <--AIR_TO_DECK_FALLING_DURATION_MS-->
 | 
			
		||||
  |-------------------|-----------------------------|--------------------------------------|------------------------------------|-------------------------------|-----------------------------------|--------------------------------------|-------------------------------------|-->Time Axis
 | 
			
		||||
  0       START_UP_DECK_TO_AIR_MS    START_UP_DECK_TO_SEA_ROTATION_MS       START_UP_AIR_TO_SEA_FALLING_MS                                        START_UP_SEA_TO_AIR_RISING_MS     START_UP_SEA_TO_DECK_ROTATION_MS         START_UP_AIR_TO_DECK_FALLING_MS
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/**************************************************************************************************************************************************/
 | 
			
		||||
/* STEP #6: With the help of the temporal diagram, declare start up time, the motion duration of servo and optional delay                         */
 | 
			
		||||
/**************************************************************************************************************************************************/
 | 
			
		||||
/* Tune below all the motion duration. Do not forget to add a trailer 'UL' for each value to force them in Unsigned Long type */
 | 
			
		||||
#define START_UP_DECK_TO_AIR_MS		0UL /* 0 for immediate start up, but you can put a delay here. Ex: 2000UL, will delay the startup of the whole sequence after 2 seconds */
 | 
			
		||||
#define DECK_TO_AIR_DURATION_MS		3000UL
 | 
			
		||||
 | 
			
		||||
#define START_UP_DECK_TO_SEA_ROTATION_MS	(START_UP_DECK_TO_AIR_MS + DECK_TO_AIR_DURATION_MS)
 | 
			
		||||
#define DECK_TO_SEA_ROTATION_DURATION_MS	3000UL
 | 
			
		||||
 | 
			
		||||
#define START_UP_AIR_TO_SEA_FALLING_MS		(START_UP_DECK_TO_SEA_ROTATION_MS + DECK_TO_SEA_ROTATION_DURATION_MS)
 | 
			
		||||
#define AIR_TO_SEA_FALLING_DURATION_MS		9000UL
 | 
			
		||||
 | 
			
		||||
#define DELAY_BEFORE_RISING_UP_MS		6000UL
 | 
			
		||||
 | 
			
		||||
#define START_UP_SEA_TO_AIR_RISING_MS		(START_UP_AIR_TO_SEA_FALLING_MS + AIR_TO_SEA_FALLING_DURATION_MS + DELAY_BEFORE_RISING_UP_MS)
 | 
			
		||||
#define SEA_TO_AIR_RISING_DURATION_MS		9000UL
 | 
			
		||||
 | 
			
		||||
#define START_UP_SEA_TO_DECK_ROTATION_MS	(START_UP_SEA_TO_AIR_RISING_MS + SEA_TO_AIR_RISING_DURATION_MS)
 | 
			
		||||
#define SEA_TO_DECK_ROTATION_DURATION_MS	3000UL
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define START_UP_AIR_TO_DECK_FALLING_MS	(START_UP_SEA_TO_DECK_ROTATION_MS + SEA_TO_DECK_ROTATION_DURATION_MS)
 | 
			
		||||
#define AIR_TO_DECK_FALLING_DURATION_MS	3000UL
 | 
			
		||||
 | 
			
		||||
/********************************************************************************************************************/
 | 
			
		||||
/* STEP #7: Declare here the percentage of motion to be performed at half speed for servo start up and stop         */
 | 
			
		||||
/********************************************************************************************************************/
 | 
			
		||||
#define START_STOP_PER_CENT			5L /* Percentage of motion performed at half speed for servo start and servo stop (Soft start and Soft stop) */
 | 
			
		||||
/* Note: due to the lack of programm memory on the DigiSpark, this feature is not used */
 | 
			
		||||
 | 
			
		||||
/************************************************************************************************************/
 | 
			
		||||
/* STEP #11: Use a "SequenceSt_t" structure table to declare the servo sequence                             */
 | 
			
		||||
/* For each table entry, arguments are:                                                                     */
 | 
			
		||||
/* - Servo Index                                                                                            */
 | 
			
		||||
/* - Initial Servo Position in °                                                                            */
 | 
			
		||||
/* - Final   Servo Position in °                                                                            */
 | 
			
		||||
/* - Motion Start Time Stamp in ms                                                                          */
 | 
			
		||||
/* - Motion duration in ms between initial and final position                                               */
 | 
			
		||||
/* - Percentage of motion performed at half speed for servo start and servo stop (Soft start and Soft stop) */
 | 
			
		||||
/* Note: START_STOP_PER_CENT not used (MOTION_WITHOUT_SOFT_START_AND_STOP() macro used)                     */
 | 
			
		||||
/************************************************************************************************************/
 | 
			
		||||
SequenceSt_t ZodiacSequence[] PROGMEM = {
 | 
			
		||||
	SHORT_ACTION_TO_PERFORM(ToggleLed, START_UP_DECK_TO_AIR_MS) /* Switch ON the Led at the beginning of the sequence */
 | 
			
		||||
	SHORT_ACTION_TO_PERFORM(ToggleLed, START_UP_AIR_TO_DECK_FALLING_MS+AIR_TO_DECK_FALLING_DURATION_MS) /* Switch OFF the Led at the beginning of the sequence: You are not obliged to put this line at the end of the table */
 | 
			
		||||
	/* 1) The crane lifts the pneumatic Zodiac from the deck to the air and stops */
 | 
			
		||||
	MOTION_WITHOUT_SOFT_START_AND_STOP(UP_DOWN_SERVO, UP_DOWN_ON_DECK_POS, UP_DOWN_ON_AIR_POS, START_UP_DECK_TO_AIR_MS, DECK_TO_AIR_DURATION_MS)
 | 
			
		||||
	/* 2) The crane rotates (90°) to locate the pneumatic Zodiac above the sea */
 | 
			
		||||
	MOTION_WITHOUT_SOFT_START_AND_STOP(ROTATION_SERVO, ROTATION_ABOVE_DECK_POS, ROTATION_ABOVE_SEA_POS, START_UP_DECK_TO_SEA_ROTATION_MS, DECK_TO_SEA_ROTATION_DURATION_MS)
 | 
			
		||||
	/* 3) The crane drops down the pneumatic Zodiac at sea level */
 | 
			
		||||
	MOTION_WITHOUT_SOFT_START_AND_STOP(UP_DOWN_SERVO, UP_DOWN_ON_AIR_POS, UP_DOWN_ON_SEA_POS, START_UP_AIR_TO_SEA_FALLING_MS, AIR_TO_SEA_FALLING_DURATION_MS)
 | 
			
		||||
	/* 4) The crane stops during 6 seconds and 5) The crane lifts up the pneumatic Zodiac from sea level to the air and stops */
 | 
			
		||||
	MOTION_WITHOUT_SOFT_START_AND_STOP(UP_DOWN_SERVO, UP_DOWN_ON_SEA_POS, UP_DOWN_ON_AIR_POS, START_UP_SEA_TO_AIR_RISING_MS, SEA_TO_AIR_RISING_DURATION_MS)
 | 
			
		||||
	/* 6) The crane rotates (90°) to locate the pneumatic Zodiac above the deck */
 | 
			
		||||
	MOTION_WITHOUT_SOFT_START_AND_STOP(ROTATION_SERVO, ROTATION_ABOVE_SEA_POS, ROTATION_ABOVE_DECK_POS, START_UP_SEA_TO_DECK_ROTATION_MS, SEA_TO_DECK_ROTATION_DURATION_MS)
 | 
			
		||||
	/* 7) The crane drops down the pneumatic Zodiac on the deck and stops. The sequence ends. */
 | 
			
		||||
	MOTION_WITHOUT_SOFT_START_AND_STOP(UP_DOWN_SERVO, UP_DOWN_ON_AIR_POS, UP_DOWN_ON_DECK_POS, START_UP_AIR_TO_DECK_FALLING_MS, AIR_TO_DECK_FALLING_DURATION_MS)                                    
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
void setup()
 | 
			
		||||
{
 | 
			
		||||
    pinMode(LED_PIN, OUTPUT);
 | 
			
		||||
    
 | 
			
		||||
    DigiUSB.begin();
 | 
			
		||||
 | 
			
		||||
/***************************************************************************/
 | 
			
		||||
/* STEP #9: Init <RcSeq> library                                           */
 | 
			
		||||
/***************************************************************************/
 | 
			
		||||
    RcSeq_Init();
 | 
			
		||||
 | 
			
		||||
/****************************************************************************************/
 | 
			
		||||
/* STEP #10: declare the servo command signals with their digital pin number            */
 | 
			
		||||
/****************************************************************************************/
 | 
			
		||||
    RcSeq_DeclareServo(UP_DOWN_SERVO,  UP_DOWN_SERVO_PIN);
 | 
			
		||||
    RcSeq_DeclareServo(ROTATION_SERVO, ROTATION_SERVO_PIN);
 | 
			
		||||
    
 | 
			
		||||
/**************************************************************************************************************************/
 | 
			
		||||
/* STEP #11: declare the sequence command signal (0), the stick level (0), and the sequence to call                       */
 | 
			
		||||
/**************************************************************************************************************************/
 | 
			
		||||
    RcSeq_DeclareCommandAndSequence(0, 0, RC_SEQUENCE(ZodiacSequence)); /* 0,0 since there's no RC command */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop()
 | 
			
		||||
{
 | 
			
		||||
char RxChar;
 | 
			
		||||
  
 | 
			
		||||
/***********************************************************************************************************************************/
 | 
			
		||||
/* STEP #12: call the refresh function inside the loop() to catch RC commands and to manage the servo positions                    */
 | 
			
		||||
/***********************************************************************************************************************************/
 | 
			
		||||
    RcSeq_Refresh();
 | 
			
		||||
 | 
			
		||||
/****************************************************************************************************************/
 | 
			
		||||
/* STEP  #13: the sequence can be launched directly by calling the RcSeq_LaunchSequence() function              */
 | 
			
		||||
/****************************************************************************************************************/
 | 
			
		||||
    if(DigiUSB.available())
 | 
			
		||||
    {
 | 
			
		||||
        RxChar=DigiUSB.read();
 | 
			
		||||
        if(RxChar=='g') /* Go ! */
 | 
			
		||||
        {
 | 
			
		||||
            RcSeq_LaunchSequence(ZodiacSequence);
 | 
			
		||||
        }
 | 
			
		||||
        if(RxChar=='t') /* Toggle LED ! */
 | 
			
		||||
        {
 | 
			
		||||
            RcSeq_LaunchShortAction(ToggleLed); /* You can toggle LED during Servo Motion! */
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    DigiUSB.refresh();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void ToggleLed(void)
 | 
			
		||||
{
 | 
			
		||||
static boolean Status=LOW;
 | 
			
		||||
    Status=!Status; /* Toggle Status */
 | 
			
		||||
    digitalWrite(LED_PIN, Status);
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,123 @@
 | 
			
		||||
#include <RcSeq.h>
 | 
			
		||||
#include <TinyPinChange.h>
 | 
			
		||||
#include <SoftRcPulseIn.h>
 | 
			
		||||
#include <SoftRcPulseOut.h>
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
This sketch demonstrates how to easily transform a proportionnal RC channel into 5 digital commands with an ATtiny85.
 | 
			
		||||
RC Navy (2013)
 | 
			
		||||
http://P.loussouarn.free.fr
 | 
			
		||||
 | 
			
		||||
COMMMAND OF 5 digital outputs from 5 push button replacing a potentiometer in the RC transmitter:
 | 
			
		||||
================================================================================================
 | 
			
		||||
   Output pins: #1, #2, #3, #4, #5 of an ATtiny85 or a Digispark
 | 
			
		||||
   The receiver output channel is connected to pin#0 of an ATtiny85 or a Digispark
 | 
			
		||||
   A furtive pressure on the push button on the transmitter toggles the corresponding output on the ATtiny85 or a Digispark
 | 
			
		||||
   connected to the receiver output channel.
 | 
			
		||||
   Version with RcSeq library inspired by: http://bateaux.trucs.free.fr/huit_sorties.html
 | 
			
		||||
 | 
			
		||||
Modification at RC Transmitter side:
 | 
			
		||||
===================================
 | 
			
		||||
                                                Custom keyboard with push buttons
 | 
			
		||||
                                                =================================
 | 
			
		||||
  Stick Potentiometer                       1K        1K        1K        1K        1K        1K
 | 
			
		||||
  ===================                   .--###---+---###---+---###---+---###---+---###---+---###---.
 | 
			
		||||
      .-.  .--.                     .-. |      _.|       _.|       _.|       _.|       _.|         |
 | 
			
		||||
      |O|--'  |                     |O|-' PB1 |_|   PB2 |_|   PB3 |_|   PB4 |_|   PB5 |_|          |  PB# = Push Button #
 | 
			
		||||
      | |     #     Replaced with   | |         '|        '|        '|        '|        '|         |
 | 
			
		||||
      |O|---->#     ============>   |O|----------+---------+---------+---------+---------+---###---+
 | 
			
		||||
      | |     #                     | |                                                     100K   |
 | 
			
		||||
      |O|--   |                     |O|------------------------------------------------------------'
 | 
			
		||||
      '-'  '--'                     '-'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
At RC Receiver side: (The following sketch is related to this ATtiny85 or Digispark)
 | 
			
		||||
===================
 | 
			
		||||
 | 
			
		||||
                        .---------------.
 | 
			
		||||
                        |               |       
 | 
			
		||||
                        |        ,------+------.
 | 
			
		||||
                        |        |     VDD     |1
 | 
			
		||||
                        |        |             +-- LED, Relay, etc...
 | 
			
		||||
                        |        |             |
 | 
			
		||||
                        |        |             |2
 | 
			
		||||
                        |        |             +-- LED, Relay, etc...
 | 
			
		||||
                        |        |             |
 | 
			
		||||
                        |        |   ATtiny85  |3
 | 
			
		||||
                        |        |      or     +-- LED, Relay, etc...
 | 
			
		||||
     .------------.     |        |  Digispark  |
 | 
			
		||||
     |            |-----'       0|             |4
 | 
			
		||||
     |   Channel#1|--------------+             +-- LED, Relay, etc...
 | 
			
		||||
     |            |-----.        |             |
 | 
			
		||||
     |     RC     |     |        |             |5
 | 
			
		||||
     |  RECEIVER  |     |        |             +-- LED, Relay, etc...
 | 
			
		||||
     |            |     |        |     GND     |
 | 
			
		||||
     |            |-    |        '------+------'
 | 
			
		||||
     |   Channel#2|-    |               | 
 | 
			
		||||
     |            |-    '---------------' 
 | 
			
		||||
     '------------'
 | 
			
		||||
 | 
			
		||||
Note:
 | 
			
		||||
====
 | 
			
		||||
- Decoupling capacitors are not drawn.
 | 
			
		||||
- This sketch can easily be extended to 8 outputs by using an ATtiny84 which has more pins.
 | 
			
		||||
- This sketch cannot work if you are using DigiUSB library as this one monopolizes the "pin change interrupt vector" (which is very time sensitive).
 | 
			
		||||
- On the other side, its possible to communicate with exterior world by using <SoftSerial>, a library mainly derived from <SoftwareSerial>, but which
 | 
			
		||||
  allow to share the pin change interrupt vector through the <TinyPinChange> library.
 | 
			
		||||
 | 
			
		||||
================================================================================================*/
 | 
			
		||||
 | 
			
		||||
/* Channel Declaration */
 | 
			
		||||
enum {RC_CHANNEL, RC_CHANNEL_NB}; /* Here, as there is a single channel, we could  used a simple "#define RC_CHANNEL 0" rather an enumeration */
 | 
			
		||||
 | 
			
		||||
//==============================================================================================
 | 
			
		||||
/* Channel Signal of the Receiver */
 | 
			
		||||
#define RX_CHANNEL_SIGNAL_PIN  0
 | 
			
		||||
 | 
			
		||||
//==============================================================================================
 | 
			
		||||
/* Declaration of the custom keyboard": the pulse width of the push buttons do not need to be equidistant */
 | 
			
		||||
enum {PUSH_BUTTON1, PUSH_BUTTON2, PUSH_BUTTON3, PUSH_BUTTON4, PUSH_BUTTON5, PUSH_BUTTON_NBR};
 | 
			
		||||
#define TOLERANCE  40 /* Tolerance  +/- (in microseconds): CAUTION, no overlap allowed between 2 adjacent active areas . active area width = 2 x TOLERANCE (us) */
 | 
			
		||||
KeyMap_t CustomKeyboard[] PROGMEM ={ {CENTER_VALUE_US(1100,TOLERANCE)}, /* PUSH_BUTTON1: +/-40 us */
 | 
			
		||||
                                     {CENTER_VALUE_US(1300,TOLERANCE)}, /* PUSH_BUTTON2: +/-40 us */
 | 
			
		||||
                                     {CENTER_VALUE_US(1500,TOLERANCE)}, /* PUSH_BUTTON3: +/-40 us */
 | 
			
		||||
                                     {CENTER_VALUE_US(1700,TOLERANCE)}, /* PUSH_BUTTON4: +/-40 us */
 | 
			
		||||
                                     {CENTER_VALUE_US(1900,TOLERANCE)}, /* PUSH_BUTTON5: +/-40 us */
 | 
			
		||||
                                  };
 | 
			
		||||
 | 
			
		||||
//==============================================================================================
 | 
			
		||||
/* Trick: a macro to write a single time the ToggleAction#() function */
 | 
			
		||||
#define DECLARE_TOGGLE_ACTION(Idx) \
 | 
			
		||||
void ToggleAction##Idx(void)       \
 | 
			
		||||
{                                  \
 | 
			
		||||
static boolean Etat=HIGH;          \
 | 
			
		||||
    digitalWrite(Idx, Etat);       \
 | 
			
		||||
    Etat=!Etat;                    \
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Declaration of the actions using the DECLARE_TOGGLE_ACTION(Idx) macro with Idx = The number of the action and the pin number (The ##Idx will be automatically replaced with the Idx value */
 | 
			
		||||
DECLARE_TOGGLE_ACTION(1)
 | 
			
		||||
DECLARE_TOGGLE_ACTION(2)
 | 
			
		||||
DECLARE_TOGGLE_ACTION(3)
 | 
			
		||||
DECLARE_TOGGLE_ACTION(4)
 | 
			
		||||
DECLARE_TOGGLE_ACTION(5)
 | 
			
		||||
 | 
			
		||||
//==============================================================================================
 | 
			
		||||
void setup()
 | 
			
		||||
{
 | 
			
		||||
    RcSeq_Init();
 | 
			
		||||
    RcSeq_DeclareSignal(RC_CHANNEL, RX_CHANNEL_SIGNAL_PIN); /* RC_CHANNEL Channel is assigned to RX_CHANNEL_SIGNAL_PIN pin */
 | 
			
		||||
    RcSeq_DeclareCustomKeyboard(RC_CHANNEL, RC_CUSTOM_KEYBOARD(CustomKeyboard)); /* The CustomKeyboard map is assigned to the RC_CHANNEL Channel */
 | 
			
		||||
    RcSeq_DeclareCommandAndShortAction(RC_CHANNEL, PUSH_BUTTON1, ToggleAction1);pinMode(1,OUTPUT); /* The ToggleAction1 is assigned to the PUSH_BUTTON1 push button #1 */
 | 
			
		||||
    RcSeq_DeclareCommandAndShortAction(RC_CHANNEL, PUSH_BUTTON2, ToggleAction2);pinMode(2,OUTPUT); /* The ToggleAction2 is assigned to the PUSH_BUTTON1 push button #2 */
 | 
			
		||||
    RcSeq_DeclareCommandAndShortAction(RC_CHANNEL, PUSH_BUTTON3, ToggleAction3);pinMode(3,OUTPUT); /* The ToggleAction3 is assigned to the PUSH_BUTTON1 push button #3 */
 | 
			
		||||
    RcSeq_DeclareCommandAndShortAction(RC_CHANNEL, PUSH_BUTTON4, ToggleAction4);pinMode(4,OUTPUT); /* The ToggleAction4 is assigned to the PUSH_BUTTON1 push button #4 */
 | 
			
		||||
    RcSeq_DeclareCommandAndShortAction(RC_CHANNEL, PUSH_BUTTON5, ToggleAction5);pinMode(5,OUTPUT); /* The ToggleAction5 is assigned to the PUSH_BUTTON1 push button #5 */
 | 
			
		||||
}
 | 
			
		||||
//==============================================================================================
 | 
			
		||||
void loop()
 | 
			
		||||
{
 | 
			
		||||
    RcSeq_Refresh(); /* This function performs all the needed job asynchronously (non blocking) */
 | 
			
		||||
}
 | 
			
		||||
//============================ END OF SKETCH =================================================
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,140 @@
 | 
			
		||||
/*
 | 
			
		||||
Ce sketch de demo de la librairie RcSeq montre comment configurer tres facilement la commande d'actions ou de sequences de servo predefinies.
 | 
			
		||||
La commande peut etre:
 | 
			
		||||
- un manche de l'emetteur RC avec possibilité de definir jusqu'a 8 positions "actives" (le nombre de position doit etre pair: neutre au milieu)
 | 
			
		||||
- un clavier: un montage resistances/boutons-poussoirs remplacant le potentiometre du manche d'un emetteur RC
 | 
			
		||||
  (les resistances doivent etre d'egales valeurs avec une 2 resistances identiques "au centre/neutre" pour la zone inactive)
 | 
			
		||||
- un clavier "maison": un montage resistances/boutons-poussoirs remplacant le potentiometre du manche d'un emetteur RC avec des resistances pas forcement identiques
 | 
			
		||||
  (la largeur d'impulsion pour chaque bouton-poussoir est define dans une table, une tolerance est egalement prevue)
 | 
			
		||||
Les 3 exemples sont traites dans ce sketch de demo.
 | 
			
		||||
*/
 | 
			
		||||
#include <RcSeq.h>
 | 
			
		||||
#include <TinyPinChange.h>  /* Ne pas oublier d'inclure la librairie <TinyPinChange>  qui est utilisee par la librairie <RcSeq> */
 | 
			
		||||
#include <SoftRcPulseIn.h>  /* Ne pas oublier d'inclure la librairie <SoftRcPulseIn>  qui est utilisee par la librairie <RcSeq> */
 | 
			
		||||
#include <SoftRcPulseOut.h> /* Ne pas oublier d'inclure la librairie <SoftRcPulseOut> qui est utilisee par la librairie <RcSeq> */
 | 
			
		||||
 | 
			
		||||
enum {RC_VOIE1, RC_VOIE2, RC_VOIE3, NBR_VOIES_RC}; /* Declaration des voies */
 | 
			
		||||
 | 
			
		||||
enum {BP1, BP2, NBR_BP}; /* Declaration des Boutons-Poussoirs (On peut aller jusqu'à BP8) */
 | 
			
		||||
 | 
			
		||||
enum {POS_MINUS1, POS_PLUS1,NBR_POS}; /* Declaration des positions du Manche on peut aller de POS_MOINS2 à POS_PLUS2 (4 Positions actives Max)*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* Declaration d'un clavier "Maison": les impulsions des Boutons-Poussoirs n'ont pas besoin d'etre equidistantes */
 | 
			
		||||
enum {BP_MAISON1, BP_MAISON2, BP_MAISON3, NBR_BP_MAISON};
 | 
			
		||||
#define TOLERANCE  40 /* Tolerance en + ou en - (en micro-seconde) */
 | 
			
		||||
KeyMap_t ClavierMaison[] PROGMEM ={  {VALEUR_CENTRALE_US(1100,TOLERANCE)}, /* BP_MAISON1: 1100 +/-40 us */
 | 
			
		||||
                                     {VALEUR_CENTRALE_US(1300,TOLERANCE)}, /* BP_MAISON2: 1300 +/-40 us */
 | 
			
		||||
                                     {VALEUR_CENTRALE_US(1700,TOLERANCE)}, /* BP_MAISON3: 1700 +/-40 us */
 | 
			
		||||
                                  };
 | 
			
		||||
 | 
			
		||||
enum {AZIMUT=0, ELEVATION , NBR_SERVO}; /* Delaration de tous les servos, 2 dans cet exemple (On peut déclaer jusqu'à 8 servos) */
 | 
			
		||||
 | 
			
		||||
/* Declaration des broches reliees aux sorties du recepteur RC */
 | 
			
		||||
#define BROCHE_SIGNAL_RECEPTEUR_VOIE1         8
 | 
			
		||||
#define BROCHE_SIGNAL_RECEPTEUR_VOIE2         2
 | 
			
		||||
#define BROCHE_SIGNAL_RECEPTEUR_VOIE3         9
 | 
			
		||||
 | 
			
		||||
/* Declaration des broches de commande des servos */
 | 
			
		||||
#define BROCHE_SIGNAL_SERVO_EL                3
 | 
			
		||||
#define BROCHE_SIGNAL_SERVO_AZ                4
 | 
			
		||||
 | 
			
		||||
/* Declaration des differents angles des servos */
 | 
			
		||||
#define ELEVATION_POS_PONT                    120 /* position zodiac sur pont   (Pos A) */
 | 
			
		||||
#define ELEVATION_POS_HAUT                    180 /* position zodiac en haut    (Pos B) */
 | 
			
		||||
#define ELEVATION_POS_MER                     0   /* position zodiac dans l'eau (pos C) */
 | 
			
		||||
 | 
			
		||||
#define AZIMUT_POS_PONT                       90 /* position rotation sur pont */
 | 
			
		||||
#define AZIMUT_POS_MER                        0  /* position rotation sur mer  */
 | 
			
		||||
 | 
			
		||||
/* Declaration des moments de demarrage ainsi que la duree des mouvement de servo */
 | 
			
		||||
#define DEMARRAGE_MONTEE_PONT_HAUT_MS           0L /* 0 pour demarrage immediat, mais on peut mettre une tempo ici. Ex 2000L, va differer la sequence complete de 2 secondes */
 | 
			
		||||
#define DUREE_MONTEE_PONT_HAUT_MS            3000L
 | 
			
		||||
 | 
			
		||||
#define DEMARRAGE_ROTATION_PONT_MER_MS       (DEMARRAGE_MONTEE_PONT_HAUT_MS+DUREE_MONTEE_PONT_HAUT_MS)
 | 
			
		||||
#define DUREE_ROTATION_PONT_MER_MS           3000L
 | 
			
		||||
 | 
			
		||||
#define DEMARRAGE_DESCENTE_HAUT_MER_MS       (DEMARRAGE_ROTATION_PONT_MER_MS+DUREE_ROTATION_PONT_MER_MS)
 | 
			
		||||
#define DUREE_DESCENTE_HAUT_MER_MS           9000L
 | 
			
		||||
 | 
			
		||||
#define ATTENTE_AVANT_REMONTEE_MS            6000L /* Exemple d'utilisation d'une temporisation */
 | 
			
		||||
 | 
			
		||||
#define DEMARRAGE_MONTEE_MER_HAUT_MS         (DEMARRAGE_DESCENTE_HAUT_MER_MS+DUREE_DESCENTE_HAUT_MER_MS+ATTENTE_AVANT_REMONTEE_MS)
 | 
			
		||||
#define DUREE_MONTEE_MER_HAUT_MS             9000L
 | 
			
		||||
 | 
			
		||||
#define DEMARRAGE_ROTATION_MER_PONT_MS       (DEMARRAGE_MONTEE_MER_HAUT_MS+DUREE_MONTEE_MER_HAUT_MS)
 | 
			
		||||
#define DUREE_ROTATION_MER_PONT_MS           3000L
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define DEMARRAGE_DESCENTE_HAUT_PONT_MS      (DEMARRAGE_ROTATION_MER_PONT_MS+DUREE_ROTATION_MER_PONT_MS)
 | 
			
		||||
#define DUREE_DESCENTE_HAUT_PONT_MS          3000L
 | 
			
		||||
 | 
			
		||||
#define DEM_ARRET_POUR_CENT                  5 /* Pourcentage du mouvement devant etre effectue a mi-vitesse pour demarrage servo et arret servo (Soft start et Soft stop) */
 | 
			
		||||
 | 
			
		||||
/* Declaration de la table de sequence des mouvements des servo et des actions courtes */
 | 
			
		||||
SequenceSt_t SequenceServoEtActionCourte[] PROGMEM = {
 | 
			
		||||
    ACTION_COURTE_A_EFFECTUER(InverseLed,DEMARRAGE_MONTEE_PONT_HAUT_MS)
 | 
			
		||||
    /* Montee du Zodiac du pont vers la position haute */
 | 
			
		||||
    MVT_AVEC_DEBUT_ET_FIN_MVT_LENTS(ELEVATION,ELEVATION_POS_PONT,ELEVATION_POS_HAUT,DEMARRAGE_MONTEE_PONT_HAUT_MS,DUREE_MONTEE_PONT_HAUT_MS,DEM_ARRET_POUR_CENT)
 | 
			
		||||
    /* Rotation Grue du pont vers la mer */
 | 
			
		||||
    MVT_AVEC_DEBUT_ET_FIN_MVT_LENTS(AZIMUT,AZIMUT_POS_PONT,AZIMUT_POS_MER,DEMARRAGE_ROTATION_PONT_MER_MS,DUREE_ROTATION_PONT_MER_MS,DEM_ARRET_POUR_CENT)
 | 
			
		||||
    /* Descente du Zodiac depuis la position haute vers la la mer */
 | 
			
		||||
    MVT_AVEC_DEBUT_ET_FIN_MVT_LENTS(ELEVATION,ELEVATION_POS_HAUT,ELEVATION_POS_MER,DEMARRAGE_DESCENTE_HAUT_MER_MS,DUREE_DESCENTE_HAUT_MER_MS,DEM_ARRET_POUR_CENT)
 | 
			
		||||
    ACTION_COURTE_A_EFFECTUER(InverseLed,DEMARRAGE_DESCENTE_HAUT_MER_MS+DUREE_DESCENTE_HAUT_MER_MS)
 | 
			
		||||
    ACTION_COURTE_A_EFFECTUER(InverseLed,DEMARRAGE_MONTEE_MER_HAUT_MS)
 | 
			
		||||
    /* Montee du Zodiac de la mer vers la position haute */
 | 
			
		||||
    MVT_AVEC_DEBUT_ET_FIN_MVT_LENTS(ELEVATION,ELEVATION_POS_MER,ELEVATION_POS_HAUT,DEMARRAGE_MONTEE_MER_HAUT_MS,DUREE_MONTEE_MER_HAUT_MS,DEM_ARRET_POUR_CENT)
 | 
			
		||||
    /* Rotation Grue de la mer vers le pont */
 | 
			
		||||
    MVT_AVEC_DEBUT_ET_FIN_MVT_LENTS(AZIMUT,AZIMUT_POS_MER,AZIMUT_POS_PONT,DEMARRAGE_ROTATION_MER_PONT_MS,DUREE_ROTATION_MER_PONT_MS,DEM_ARRET_POUR_CENT)
 | 
			
		||||
    /* Descente du Zodiac de la position haute vers le pont */
 | 
			
		||||
    MVT_AVEC_DEBUT_ET_FIN_MVT_LENTS(ELEVATION,ELEVATION_POS_HAUT,ELEVATION_POS_PONT,DEMARRAGE_DESCENTE_HAUT_PONT_MS,DUREE_DESCENTE_HAUT_PONT_MS,DEM_ARRET_POUR_CENT)                                   
 | 
			
		||||
    ACTION_COURTE_A_EFFECTUER(InverseLed,DEMARRAGE_DESCENTE_HAUT_PONT_MS+DUREE_DESCENTE_HAUT_PONT_MS)
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
#define LED		13
 | 
			
		||||
 | 
			
		||||
void setup()
 | 
			
		||||
{
 | 
			
		||||
#if !defined(__AVR_ATtiny24__) && !defined(__AVR_ATtiny44__) && !defined(__AVR_ATtiny84__) && !defined(__AVR_ATtiny25__) && !defined(__AVR_ATtiny45__) && !defined(__AVR_ATtiny85__)
 | 
			
		||||
    Serial.begin(9600);
 | 
			
		||||
    Serial.print("RcSeq library V");Serial.print(RcSeq_LibTextVersionRevision());Serial.print(" demo: RcSeqDemo");
 | 
			
		||||
#endif
 | 
			
		||||
    RcSeq_Init();
 | 
			
		||||
    
 | 
			
		||||
    /* Declaration des Servos */
 | 
			
		||||
    RcSeq_DeclareServo(ELEVATION, BROCHE_SIGNAL_SERVO_EL);
 | 
			
		||||
    RcSeq_DeclareServo(AZIMUT,    BROCHE_SIGNAL_SERVO_AZ);
 | 
			
		||||
 | 
			
		||||
    /* Commande d'une action courte et d'une sequence de servos avec 2 BP du clavier de la VOIE1 */
 | 
			
		||||
    RcSeq_DeclareSignal(RC_VOIE1,BROCHE_SIGNAL_RECEPTEUR_VOIE1);
 | 
			
		||||
    RcSeq_DeclareClavier(RC_VOIE1, 1000, 2000, NBR_BP);
 | 
			
		||||
    RcSeq_DeclareCommandeEtActionCourte(RC_VOIE1, BP1, InverseLed);
 | 
			
		||||
    RcSeq_DeclareCommandeEtSequence(RC_VOIE1, BP2, RC_SEQUENCE(SequenceServoEtActionCourte));
 | 
			
		||||
 | 
			
		||||
    /* Commande d'une action courte et d'une sequence de servos avec le manche de la VOIE2 */
 | 
			
		||||
    RcSeq_DeclareSignal(RC_VOIE2,BROCHE_SIGNAL_RECEPTEUR_VOIE2);
 | 
			
		||||
    RcSeq_DeclareManche(RC_VOIE2, 1000, 2000, NBR_POS);
 | 
			
		||||
    RcSeq_DeclareCommandeEtActionCourte(RC_VOIE2, POS_MINUS1, InverseLed);
 | 
			
		||||
    RcSeq_DeclareCommandeEtSequence(RC_VOIE2, POS_PLUS1, RC_SEQUENCE(SequenceServoEtActionCourte));
 | 
			
		||||
 | 
			
		||||
    /* Commande d'une action courte et d'une sequence de servos avec le clavier "maison" de la VOIE3 */
 | 
			
		||||
    RcSeq_DeclareSignal(RC_VOIE3,BROCHE_SIGNAL_RECEPTEUR_VOIE3);
 | 
			
		||||
    RcSeq_DeclareClavierMaison(RC_VOIE3, RC_CLAVIER_MAISON(ClavierMaison));
 | 
			
		||||
    RcSeq_DeclareCommandeEtActionCourte(RC_VOIE3, BP_MAISON1, InverseLed);
 | 
			
		||||
    RcSeq_DeclareCommandeEtSequence(RC_VOIE3, BP_MAISON3, RC_SEQUENCE(SequenceServoEtActionCourte));
 | 
			
		||||
 | 
			
		||||
    pinMode(LED, OUTPUT);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop()
 | 
			
		||||
{
 | 
			
		||||
    RcSeq_Rafraichit();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Action associee au BP1 de la VOIE1 ou au manche position basse de la VOIE2 ou au BP_MAISON1 de la VOIE3 */
 | 
			
		||||
void InverseLed(void)
 | 
			
		||||
{
 | 
			
		||||
static boolean Etat=HIGH; /* static, pour conserver l'etat entre 2 appels de la fonction */
 | 
			
		||||
    digitalWrite(LED, Etat);
 | 
			
		||||
    Etat=!Etat; /* AU prochain appel de InverseLed(), l'etat de la LED sera inverse */
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,218 @@
 | 
			
		||||
/*
 | 
			
		||||
IMPORTANT:
 | 
			
		||||
=========
 | 
			
		||||
La librairie "RcSeq" utilise la technique de programmation dite "asynchrone", c'est-a-dire qu'aucun appel a des fonctions bloquantes telles que la fonction delay()
 | 
			
		||||
ou la fonction pulseIn() n'est effectue.
 | 
			
		||||
Ceci se traduit par un temps de boucle principale inferieur a 70 micro-secondes bien que les servos soient rafraichis toutes les 20ms a l'aide de la methode
 | 
			
		||||
Rafraichit() qui doit etre appelee dans la fonction loop(). Cela laisse donc enormement de temps au micro-controleur pour faire "en meme temps" d'autres taches.
 | 
			
		||||
Par exemple dans ce sketch, il est possible d'envoyer la commande 'i' via la serial console pour inverser l'etat de la LED connectee a la pin digitale 13 pendant
 | 
			
		||||
que les servos sont en mouvement.
 | 
			
		||||
 | 
			
		||||
Ce sketch illustre l'utilisation de la librairie "RcSeq" qui permet de sequencer tres facilement des servos et des actions courtes a l'aide de la librairie "SoftwareServo".
 | 
			
		||||
Les actions courtes doivent durer moins de 20ms pour ne pas perturber la commande des servos.
 | 
			
		||||
Si ce sketch est charge dans une carte UNO, il est possible de lancer la sequence en tapant 'g' puis Entree dans la serial console de l'EDI Arduino.
 | 
			
		||||
En tapant 'i' puis Entree, l'action InverseLed() est executee. Comme "RcSeq" est asynchrone, il est possible de le faire pendant que les servos tournent.
 | 
			
		||||
La possibilite de lancer les sequence et action courte via la serial console evite de sortir et cabler l'ensemble RC pour lancer la sequence et l'action.
 | 
			
		||||
 | 
			
		||||
Dans cet exemple, la sequence declaree est la mise a l'eau d'un Zodiac avec une grue depuis un bateau de service type baliseur:
 | 
			
		||||
1) La grue souleve le Zodiac en position haute puis s'arrete
 | 
			
		||||
2) La grue fait une rotation de 90° pour positionner le Zodiac au dessus de l'eau
 | 
			
		||||
3) La grue descend le Zodiac au niveau de l'eau
 | 
			
		||||
4) La grue reste sans action pendant 6 secondes
 | 
			
		||||
5) La grue remonte le Zodiac en position haute puis s'arrete
 | 
			
		||||
6) La grue fait une rotation de 90° pour positionner le Zodiac au dessus du pont
 | 
			
		||||
7) La grue descend le Zodiac en position basse puis s'arrete. La sequence est terminee.
 | 
			
		||||
Cette sequence utilise:
 | 
			
		||||
- 2 commande RC sur le meme manche (Impulsion d'au moins 1/4 de seconde en position mi-course pour l'action courte et extreme pour la sequnce avec le manche de l'emetteur RC)
 | 
			
		||||
  ou la commande 'i' ou 'g' depuis la serial console de l'EDI Arduino
 | 
			
		||||
- 2 servos (un servo "Azimut" pour les rotations et un servo "Elevation" pour la montee/descente)
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/***************************************************/
 | 
			
		||||
/* ETAPE N°1: Inclure les 4 librairies necessaires */
 | 
			
		||||
/***************************************************/
 | 
			
		||||
#include <RcSeq.h>
 | 
			
		||||
#include <TinyPinChange.h>  /* Ne pas oublier d'inclure la librairie <TinyPinChange>  qui est utilisee par la librairie <RcSeq> */
 | 
			
		||||
#include <SoftRcPulseIn.h>  /* Ne pas oublier d'inclure la librairie <SoftRcPulseIn>  qui est utilisee par la librairie <RcSeq> */
 | 
			
		||||
#include <SoftRcPulseOut.h> /* Ne pas oublier d'inclure la librairie <SoftRcPulseOut> qui est utilisee par la librairie <RcSeq> */
 | 
			
		||||
 | 
			
		||||
/*****************************************************/
 | 
			
		||||
/* ETAPE N°2: Enumeration des signaux de commande RC */
 | 
			
		||||
/*****************************************************/
 | 
			
		||||
enum {SIGNAL_RC=0, NBR_SIGNAL}; /* Delaration de tous les signaux de commande (sortie voie du recepteur), un seul dans cet exemple */
 | 
			
		||||
 | 
			
		||||
/****************************************************************/
 | 
			
		||||
/* ETAPE N°3: Enumeration des differentes position du manche RC */
 | 
			
		||||
/****************************************************************/
 | 
			
		||||
enum {RC_IMPULSION_NIVEAU_MOINS_2, RC_IMPULSION_NIVEAU_MOINS_1, RC_IMPULSION_NIVEAU_PLUS_1, RC_IMPULSION_NIVEAU_PLUS_2, NBR_RC_IMPULSIONS};
 | 
			
		||||
 | 
			
		||||
/*****************************************************************/
 | 
			
		||||
/* ETAPE N°4: Enumeration des servos utilisés pour les sequences */
 | 
			
		||||
/*****************************************************************/
 | 
			
		||||
enum {AZIMUT=0, ELEVATION , NBR_SERVO}; /* Delaration de tous les servos, 2 dans cet exemple */
 | 
			
		||||
 | 
			
		||||
/*********************************************************************************/
 | 
			
		||||
/* ETAPE N°5: Affectation des broches Digitales (PIN) des signaux de commande RC */
 | 
			
		||||
/*********************************************************************************/
 | 
			
		||||
#define BROCHE_SIGNAL_RECEPTEUR         2
 | 
			
		||||
 | 
			
		||||
/*****************************************************************************************/
 | 
			
		||||
/* ETAPE N°6: Affectation des broches Digitales (PIN) des signaux de commande des servos */
 | 
			
		||||
/*****************************************************************************************/
 | 
			
		||||
#define BROCHE_SIGNAL_SERVO_EL          3
 | 
			
		||||
#define BROCHE_SIGNAL_SERVO_AZ          4
 | 
			
		||||
 | 
			
		||||
/**************************************************************************************/
 | 
			
		||||
/* ETAPE N°7: Declaration des angles des servos pour les differents mouvements (en °) */
 | 
			
		||||
/**************************************************************************************/
 | 
			
		||||
#define ELEVATION_POS_PONT              120 /* position zodiac sur pont   (Pos A) */
 | 
			
		||||
#define ELEVATION_POS_HAUT              180 /* position zodiac en haut    (Pos B) */
 | 
			
		||||
#define ELEVATION_POS_MER               0   /* position zodiac dans l'eau (pos C) */
 | 
			
		||||
 | 
			
		||||
#define AZIMUT_POS_PONT                 90 /* position rotation sur pont */
 | 
			
		||||
#define AZIMUT_POS_MER                  0  /* position rotation sur mer  */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/***************************************************************************************************************************************/
 | 
			
		||||
/* ETAPE N°8: Faire un croquis temporel faisant apparaitre les moments de demarrages et les duree des mouvements des differents servos */
 | 
			
		||||
/***************************************************************************************************************************************/
 | 
			
		||||
/*
 | 
			
		||||
Toutes les valeurs de demarrage ont comme reference le moment de l'ordre de demarrage de sequence (t=0).
 | 
			
		||||
 | 
			
		||||
                           MOUVEMENT SERVO ELEVATION         MOUVEMENT SERVO AZIMUT            MOUVEMENT SERVO ELEVATION      AUCUN MOUVEMENT(ATTENTE)        MOUVEMENT SERVO ELEVATION          MOUVEMENT SERVO AZIMUT            MOUVEMENT SERVO ELEVATION
 | 
			
		||||
Ordre                  <---DUREE_MONTEE_PONT_HAUT_MS--> <--DUREE_ROTATION_PONT_MER_MS----> <--DUREE_DESCENTE_HAUT_MER_MS--><--ATTENTE_AVANT_REMONTEE_MS--><---DUREE_MONTEE_MER_HAUT_MS---><----DUREE_ROTATION_MER_PONT_MS-----><--DUREE_DESCENTE_HAUT_PONT_MS-->
 | 
			
		||||
  |-------------------|--------------------------------|----------------------------------|--------------------------------|------------------------------|-------------------------------|------------------------------------|--------------------------------|-->Axe du Temps
 | 
			
		||||
  0     DEMARRAGE_MONTEE_PONT_HAUT_MS   DEMARRAGE_ROTATION_PONT_MER_MS     DEMARRAGE_DESCENTE_HAUT_MER_MS                                  DEMARRAGE_MONTEE_MER_HAUT_MS    DEMARRAGE_ROTATION_MER_PONT_MS        DEMARRAGE_DESCENTE_HAUT_PONT_MS
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/**************************************************************************************************************************************************/
 | 
			
		||||
/* ETAPE N°9: A l'aide du croquis temporel, declarer les moments de demarrage, les durees des movement de servo et les eventuelles temporisations */
 | 
			
		||||
/**************************************************************************************************************************************************/
 | 
			
		||||
/* Regler ci-dessous les temps de mouvement en ms. Ne pas oulier de d'ajouter un 'L' a la fin de la valeur pour forcer les valeurs en type Long */
 | 
			
		||||
#define DEMARRAGE_MONTEE_PONT_HAUT_MS           0L /* 0 pour demarrage immediat, mais on peut mettre une tempo ici. Ex 2000L, va differer la sequence complete de 2 secondes */
 | 
			
		||||
#define DUREE_MONTEE_PONT_HAUT_MS            3000L
 | 
			
		||||
 | 
			
		||||
#define DEMARRAGE_ROTATION_PONT_MER_MS       (DEMARRAGE_MONTEE_PONT_HAUT_MS+DUREE_MONTEE_PONT_HAUT_MS)
 | 
			
		||||
#define DUREE_ROTATION_PONT_MER_MS           3000L
 | 
			
		||||
 | 
			
		||||
#define DEMARRAGE_DESCENTE_HAUT_MER_MS       (DEMARRAGE_ROTATION_PONT_MER_MS+DUREE_ROTATION_PONT_MER_MS)
 | 
			
		||||
#define DUREE_DESCENTE_HAUT_MER_MS           9000L
 | 
			
		||||
 | 
			
		||||
#define ATTENTE_AVANT_REMONTEE_MS            6000L /* Exemple d'utilisation d'une temporisation */
 | 
			
		||||
 | 
			
		||||
#define DEMARRAGE_MONTEE_MER_HAUT_MS         (DEMARRAGE_DESCENTE_HAUT_MER_MS+DUREE_DESCENTE_HAUT_MER_MS+ATTENTE_AVANT_REMONTEE_MS)
 | 
			
		||||
#define DUREE_MONTEE_MER_HAUT_MS             9000L
 | 
			
		||||
 | 
			
		||||
#define DEMARRAGE_ROTATION_MER_PONT_MS       (DEMARRAGE_MONTEE_MER_HAUT_MS+DUREE_MONTEE_MER_HAUT_MS)
 | 
			
		||||
#define DUREE_ROTATION_MER_PONT_MS           3000L
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define DEMARRAGE_DESCENTE_HAUT_PONT_MS      (DEMARRAGE_ROTATION_MER_PONT_MS+DUREE_ROTATION_MER_PONT_MS)
 | 
			
		||||
#define DUREE_DESCENTE_HAUT_PONT_MS          3000L
 | 
			
		||||
 | 
			
		||||
/********************************************************************************************************************/
 | 
			
		||||
/* ETAPE N°10: Declarer le pourcentage de mouvement devant etre a mi-vitesse pour les demarrage et arret des servos */
 | 
			
		||||
/********************************************************************************************************************/
 | 
			
		||||
#define DEM_ARRET_POUR_CENT                  5 /* Pourcentage du mouvement devant etre effectue a mi-vitesse pour demarrage servo et arret servo (Soft start et Soft stop) */
 | 
			
		||||
 | 
			
		||||
/***************************************************************************************************************************************************************/
 | 
			
		||||
/* ETAPE N°11: Dans une structure de type "SequenceSt_t", a l'aide de la macro MVT_AVEC_DEBUT_ET_FIN_MVT_LENTS(), declarer le N° de servo, l'angle initial,    */
 | 
			
		||||
/* l'angle final, le moment de demarrage, la duree du mouvement et le pourcentage de mouvement devant etre a mi-vitesse pour les demarrage et arret des servos */
 | 
			
		||||
/* Il est possible d'inclure des actions courtes. Il suffit d'utiliser la macro ACTION_COURTE_A_EFFECTUER() en donnant le nom de la fonction a appeler et le   */
 | 
			
		||||
/* moment ou l'action doit avoir lieu. Dans cet exemple, la LED s'allume pendant que les servos tournent et s'eteint pendant la pause de 6 secondes.           */
 | 
			
		||||
/***************************************************************************************************************************************************************/
 | 
			
		||||
SequenceSt_t SequencePlus2[] PROGMEM = {
 | 
			
		||||
	ACTION_COURTE_A_EFFECTUER(InverseLed,DEMARRAGE_MONTEE_PONT_HAUT_MS)
 | 
			
		||||
	/* Montee du Zodiac du pont vers la position haute */
 | 
			
		||||
	MVT_AVEC_DEBUT_ET_FIN_MVT_LENTS(ELEVATION,ELEVATION_POS_PONT,ELEVATION_POS_HAUT,DEMARRAGE_MONTEE_PONT_HAUT_MS,DUREE_MONTEE_PONT_HAUT_MS,DEM_ARRET_POUR_CENT)
 | 
			
		||||
	/* Rotation Grue du pont vers la mer */
 | 
			
		||||
	MVT_AVEC_DEBUT_ET_FIN_MVT_LENTS(AZIMUT,AZIMUT_POS_PONT,AZIMUT_POS_MER,DEMARRAGE_ROTATION_PONT_MER_MS,DUREE_ROTATION_PONT_MER_MS,DEM_ARRET_POUR_CENT)
 | 
			
		||||
	/* Descente du Zodiac depuis la position haute vers la la mer */
 | 
			
		||||
	MVT_AVEC_DEBUT_ET_FIN_MVT_LENTS(ELEVATION,ELEVATION_POS_HAUT,ELEVATION_POS_MER,DEMARRAGE_DESCENTE_HAUT_MER_MS,DUREE_DESCENTE_HAUT_MER_MS,DEM_ARRET_POUR_CENT)
 | 
			
		||||
	ACTION_COURTE_A_EFFECTUER(InverseLed,DEMARRAGE_DESCENTE_HAUT_MER_MS+DUREE_DESCENTE_HAUT_MER_MS)
 | 
			
		||||
	ACTION_COURTE_A_EFFECTUER(InverseLed,DEMARRAGE_MONTEE_MER_HAUT_MS)
 | 
			
		||||
	/* Montee du Zodiac de la mer vers la position haute */
 | 
			
		||||
	MVT_AVEC_DEBUT_ET_FIN_MVT_LENTS(ELEVATION,ELEVATION_POS_MER,ELEVATION_POS_HAUT,DEMARRAGE_MONTEE_MER_HAUT_MS,DUREE_MONTEE_MER_HAUT_MS,DEM_ARRET_POUR_CENT)
 | 
			
		||||
	/* Rotation Grue de la mer vers le pont */
 | 
			
		||||
	MVT_AVEC_DEBUT_ET_FIN_MVT_LENTS(AZIMUT,AZIMUT_POS_MER,AZIMUT_POS_PONT,DEMARRAGE_ROTATION_MER_PONT_MS,DUREE_ROTATION_MER_PONT_MS,DEM_ARRET_POUR_CENT)
 | 
			
		||||
	/* Descente du Zodiac de la position haute vers le pont */
 | 
			
		||||
	MVT_AVEC_DEBUT_ET_FIN_MVT_LENTS(ELEVATION,ELEVATION_POS_HAUT,ELEVATION_POS_PONT,DEMARRAGE_DESCENTE_HAUT_PONT_MS,DUREE_DESCENTE_HAUT_PONT_MS,DEM_ARRET_POUR_CENT)                                    
 | 
			
		||||
	ACTION_COURTE_A_EFFECTUER(InverseLed,DEMARRAGE_DESCENTE_HAUT_PONT_MS+DUREE_DESCENTE_HAUT_PONT_MS)
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
#define LED		13
 | 
			
		||||
 | 
			
		||||
void setup()
 | 
			
		||||
{
 | 
			
		||||
  
 | 
			
		||||
#if !defined(__AVR_ATtiny24__) && !defined(__AVR_ATtiny44__) && !defined(__AVR_ATtiny84__) && !defined(__AVR_ATtiny25__) && !defined(__AVR_ATtiny45__) && !defined(__AVR_ATtiny85__)
 | 
			
		||||
    Serial.begin(9600);
 | 
			
		||||
    Serial.print("RcSeq library V");Serial.print(RcSeq_LibTextVersionRevision());Serial.print(" demo: RcSeqZodiac");
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/***************************************************************************/
 | 
			
		||||
/* ETAPE N°12: Appeler la fonction d'initialisation de la libraire "RcSeq" */
 | 
			
		||||
/***************************************************************************/
 | 
			
		||||
    RcSeq_Init();
 | 
			
		||||
 | 
			
		||||
/**************************************************************************************/
 | 
			
		||||
/* ETAPE N°13: declarer le(s) signal(aux) de commande RC avec leur N° de pin digitale */
 | 
			
		||||
/**************************************************************************************/
 | 
			
		||||
    RcSeq_DeclareSignal(SIGNAL_RC,BROCHE_SIGNAL_RECEPTEUR);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************************/
 | 
			
		||||
/* ETAPE N°14: que le signal RC est associe a un manche qui a NBR_RC_IMPULSIONS positions */
 | 
			
		||||
/*****************************************************************************************/
 | 
			
		||||
    RcSeq_DeclareManche(SIGNAL_RC, 1000, 2000, NBR_RC_IMPULSIONS);
 | 
			
		||||
    
 | 
			
		||||
/********************************************************************************************/
 | 
			
		||||
/* ETAPE N°15: declarer le(s) signal(aux) ce commande de servo avec leur N° de pin digitale */
 | 
			
		||||
/********************************************************************************************/
 | 
			
		||||
    RcSeq_DeclareServo(ELEVATION, BROCHE_SIGNAL_SERVO_EL);
 | 
			
		||||
    RcSeq_DeclareServo(AZIMUT,    BROCHE_SIGNAL_SERVO_AZ);
 | 
			
		||||
    
 | 
			
		||||
/**************************************************************************************************************************/
 | 
			
		||||
/* ETAPE N°16: declarer le signal de commande de sequence, le niveau du manche, et la sequence ou action courte a appeler */
 | 
			
		||||
/**************************************************************************************************************************/
 | 
			
		||||
    RcSeq_DeclareCommandeEtSequence(SIGNAL_RC, RC_IMPULSION_NIVEAU_PLUS_2, RC_SEQUENCE(SequencePlus2)); // Voici comment declarer une sequence actionnee par une impulsion Niveau Plus 2 (manche en position extreme pendant au moins 250 ms)
 | 
			
		||||
 | 
			
		||||
    pinMode(LED, OUTPUT);
 | 
			
		||||
    RcSeq_DeclareCommandeEtActionCourte(SIGNAL_RC, RC_IMPULSION_NIVEAU_MOINS_1, InverseLed); // Voici comment declarer une action actionnee par une impulsion Niveau Moins 1 (manche en position mi-course pendant au moins 250 ms)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop()
 | 
			
		||||
{
 | 
			
		||||
  
 | 
			
		||||
/***********************************************************************************************************************************/
 | 
			
		||||
/* ETAPE N°17: appeler la fonction Rafraichit dans la fonction loop() pour capter les commandes RC et gerer la position des servos */
 | 
			
		||||
/***********************************************************************************************************************************/
 | 
			
		||||
    RcSeq_Rafraichit();
 | 
			
		||||
 | 
			
		||||
/******************************************************************************************************/
 | 
			
		||||
/* ETAPE N°18: optionnellement, autoriser le lancement des Sequences ou Actions via la serial console */
 | 
			
		||||
/******************************************************************************************************/
 | 
			
		||||
#if !defined(__AVR_ATtiny24__) && !defined(__AVR_ATtiny44__) && !defined(__AVR_ATtiny84__) && !defined(__AVR_ATtiny25__) && !defined(__AVR_ATtiny45__) && !defined(__AVR_ATtiny85__)
 | 
			
		||||
int RxChar;
 | 
			
		||||
    /* Lance la sequence en envoyant le caractere 'g' dans la serial console: cela permet de tester la sequence de servo avec une carte UNO sans utiliser d'ensemble RC */
 | 
			
		||||
    if(Serial.available() > 0)
 | 
			
		||||
    {
 | 
			
		||||
        RxChar=Serial.read();
 | 
			
		||||
        if(tolower(RxChar)=='g') /* Go ! */
 | 
			
		||||
        {
 | 
			
		||||
            RcSeq_LanceSequence(SequencePlus2);
 | 
			
		||||
        }
 | 
			
		||||
        if(tolower(RxChar)=='i') /* inverse led ! */
 | 
			
		||||
        {
 | 
			
		||||
            RcSeq_LanceActionCourte(InverseLed);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Action associee au manche a mi-course */
 | 
			
		||||
void InverseLed(void)
 | 
			
		||||
{
 | 
			
		||||
static boolean Etat=HIGH; /* static, pour conserver l'etat entre 2 appels de la fonction */
 | 
			
		||||
	digitalWrite(LED, Etat);
 | 
			
		||||
	Etat=!Etat; /* AU prochain appel de InverseLed(), l'etat de la LED sera inverse */
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,76 @@
 | 
			
		||||
#include <RcSeq.h>
 | 
			
		||||
#include <TinyPinChange.h>  /* Ne pas oublier d'inclure la librairie <TinyPinChange>  qui est utilisee par la librairie <RcSeq> */
 | 
			
		||||
#include <SoftRcPulseIn.h>  /* Ne pas oublier d'inclure la librairie <SoftRcPulseIn>  qui est utilisee par la librairie <RcSeq> */
 | 
			
		||||
#include <SoftRcPulseOut.h> /* Ne pas oublier d'inclure la librairie <SoftRcPulseOut> qui est utilisee par la librairie <RcSeq> */
 | 
			
		||||
 | 
			
		||||
/*================= COMMMANDE DE 8 SORTIES ON/OFF PAR 8 INTERS POUSSOIR  ========================
 | 
			
		||||
   Les 8 relais ou sont connectés aux prise n°1,2,3,4,5,6,7,8 d'un ATtiny84
 | 
			
		||||
   La voie du récepteur est connecté à la prise n°0 de l'ATtiny84
 | 
			
		||||
   Un appui furtif sur un bouton fait actionne le relais correspondant qui reste collé.
 | 
			
		||||
   Un deuxième appui furtif sur le même bouton fait décoller le relais correspondant.
 | 
			
		||||
   Version avec librairie RcSeq d'apres l'exemple de http://bateaux.trucs.free.fr/huit_sorties.html
 | 
			
		||||
================================================================================================*/
 | 
			
		||||
 | 
			
		||||
/* Declaration des voies */
 | 
			
		||||
enum {RC_VOIE, NBR_VOIES_RC}; /* Ici, comme il n'y a qu'une voie, on aurait pu faire un simple "#define RC_VOIE 0" a la place de l'enumeration */
 | 
			
		||||
 | 
			
		||||
//==============================================================================================
 | 
			
		||||
/* Declaration du signal du recepteur */
 | 
			
		||||
#define BROCHE_SIGNAL_RECEPTEUR_VOIE  0
 | 
			
		||||
 | 
			
		||||
//==============================================================================================
 | 
			
		||||
/* Declaration d'un clavier "Maison": les impulsions des Boutons-Poussoirs n'ont pas besoin d'etre equidistantes */
 | 
			
		||||
enum {BP1, BP2, BP3, BP4, BP5, BP6, BP7, BP8, NBR_BP};
 | 
			
		||||
#define TOLERANCE  40 /* Tolerance en + ou en - (en micro-seconde): ATTENTION, il ne doit pas y avoir recouvrement entre 2 zones actives adjascentes. Zone active = 2 x TOLERANCE (us) */
 | 
			
		||||
KeyMap_t ClavierMaison[] PROGMEM ={  {VALEUR_CENTRALE_US(1100,TOLERANCE)}, /* BP1: +/-40 us */
 | 
			
		||||
                                     {VALEUR_CENTRALE_US(1200,TOLERANCE)}, /* BP2: +/-40 us */
 | 
			
		||||
                                     {VALEUR_CENTRALE_US(1300,TOLERANCE)}, /* BP3: +/-40 us */
 | 
			
		||||
                                     {VALEUR_CENTRALE_US(1400,TOLERANCE)}, /* BP4: +/-40 us */
 | 
			
		||||
                                     {VALEUR_CENTRALE_US(1600,TOLERANCE)}, /* BP5: +/-40 us */
 | 
			
		||||
                                     {VALEUR_CENTRALE_US(1700,TOLERANCE)}, /* BP6: +/-40 us */
 | 
			
		||||
                                     {VALEUR_CENTRALE_US(1800,TOLERANCE)}, /* BP7: +/-40 us */
 | 
			
		||||
                                     {VALEUR_CENTRALE_US(1900,TOLERANCE)}, /* BP8: +/-40 us */
 | 
			
		||||
                                  };
 | 
			
		||||
 | 
			
		||||
//==============================================================================================
 | 
			
		||||
/* Astuce: une macro pour n'ecrire qu'une seule fois la fonction ActionX() */
 | 
			
		||||
#define DECLARE_ACTION(Idx)  \
 | 
			
		||||
void Action##Idx(void)       \
 | 
			
		||||
{                            \
 | 
			
		||||
static boolean Etat=HIGH;    \
 | 
			
		||||
    digitalWrite(Idx, Etat); \
 | 
			
		||||
    Etat=!Etat;              \
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Declaration des actions en utilisant la macro DECLARE_ACTION(Idx) avec Idx = le numero de l'action et de la pin (le ##Idx sera remplace automatiquement par la valeur de Idx */
 | 
			
		||||
DECLARE_ACTION(1)
 | 
			
		||||
DECLARE_ACTION(2)
 | 
			
		||||
DECLARE_ACTION(3)
 | 
			
		||||
DECLARE_ACTION(4)
 | 
			
		||||
DECLARE_ACTION(5)
 | 
			
		||||
DECLARE_ACTION(6)
 | 
			
		||||
DECLARE_ACTION(7)
 | 
			
		||||
DECLARE_ACTION(8)
 | 
			
		||||
 | 
			
		||||
//==============================================================================================
 | 
			
		||||
void setup()
 | 
			
		||||
{
 | 
			
		||||
    RcSeq_Init();
 | 
			
		||||
    RcSeq_DeclareSignal(RC_VOIE, BROCHE_SIGNAL_RECEPTEUR_VOIE);
 | 
			
		||||
    RcSeq_DeclareClavierMaison(RC_VOIE, RC_CLAVIER_MAISON(ClavierMaison));
 | 
			
		||||
    RcSeq_DeclareCommandeEtActionCourte(RC_VOIE, BP1, Action1);pinMode(1,OUTPUT);
 | 
			
		||||
    RcSeq_DeclareCommandeEtActionCourte(RC_VOIE, BP2, Action2);pinMode(2,OUTPUT);
 | 
			
		||||
    RcSeq_DeclareCommandeEtActionCourte(RC_VOIE, BP3, Action3);pinMode(3,OUTPUT);
 | 
			
		||||
    RcSeq_DeclareCommandeEtActionCourte(RC_VOIE, BP4, Action4);pinMode(4,OUTPUT);
 | 
			
		||||
    RcSeq_DeclareCommandeEtActionCourte(RC_VOIE, BP5, Action5);pinMode(5,OUTPUT);
 | 
			
		||||
    RcSeq_DeclareCommandeEtActionCourte(RC_VOIE, BP6, Action6);pinMode(6,OUTPUT);
 | 
			
		||||
    RcSeq_DeclareCommandeEtActionCourte(RC_VOIE, BP7, Action7);pinMode(7,OUTPUT);
 | 
			
		||||
    RcSeq_DeclareCommandeEtActionCourte(RC_VOIE, BP8, Action8);pinMode(8,OUTPUT);
 | 
			
		||||
}
 | 
			
		||||
//==============================================================================================
 | 
			
		||||
void loop()
 | 
			
		||||
{
 | 
			
		||||
    RcSeq_Rafraichit();  
 | 
			
		||||
}
 | 
			
		||||
//============================ FIN DU PROGRAMME =================================================
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user