1
Vos projets / Re : Éclairage voitures
« le: Aujourd'hui à 01:38:56 pm »
Voila pour illustrer la version la plus basique
Le forum LOCODUINO est consacré aux discussions ayant trait à l'utilisation de l'Arduino dans les automatismes et les animations pour le train miniature. Nous avons eu récemment quelques inscriptions de personnes ayant des projets plus généraux mais surtout inapplicables au train miniature. Si votre projet ou vos questions ne concernent pas le modélisme ferroviaire, ne vous inscrivez pas, vous perdriez votre temps et nous aussi.
Cette section vous permet de consulter les contributions (messages, sujets et fichiers joints) d'un utilisateur. Vous ne pourrez voir que les contributions des zones auxquelles vous avez accès.
#include "Comparator.h"
void INIT_COMPARATOR()
{
//COMPARATOR:
//POSITIV SIDE: AS FLOATING VALUE INPUT:
Comparator.input_p = comparator::in_p::in0; //INPUT P0 PIN_PA7
//Comparator.input_p = comparator::in_p::in1; //INPUT P1 PIN_PB5
//Comparator.input_p = comparator::in_p::in2; //INPUT P2 PIN_PB1
//Comparator.input_p = comparator::in_p::in3; //INPUT P3 PIN_PB6
//NEGATIV SIDE: AS REFERENCE VALUE INPUT:
//Comparator.input_n = comparator::in_n::in0; //INPUT N0 PIN_PA6
Comparator.input_n = comparator::in_n::in1; //INPUT N1 PIN_PB4
//Comparator.input_n = comparator::in_n::in2; //INPUT N2 PIN_PB0
Comparator.reference = comparator::ref::disable;
Comparator.hysteresis = comparator::hyst::disable;
Comparator.output = comparator::out::enable; //OUTÜT PIN_PA5
//Comparator.output = comparator::out::disable; // No output pin, signal not inverted internally
//Comparator.output = comparator::out::disable_invert; // No output pin, signal inverted internally
//Comparator.output = comparator::out::enable; // Enable output pin (PA7), signal not inverted internally
//Comparator.output = comparator::out::invert; // Enable output pin (PA7), signal inverted internally
//Comparator.output = comparator::out::enable_invert; // Identical to out::invert
Comparator.init();
Comparator.start(); // Start comparator
}
void setup() {
INIT_COMPARATOR();
}
void loop() {
}
Comparator.output = comparator::out::invert;
#include <ccl.h>
/**
* \brief Initialize CCL peripheral
* \return Return value 0 if success
*/
int8_t DIGITAL_GLUE_LOGIC_0_init()
{
// CCL.SEQCTRL0 = CCL_SEQSEL_DISABLE_gc; /* Sequential logic disabled */
// CCL.SEQCTRL1 = CCL_SEQSEL_DISABLE_gc; /* Sequential logic disabled */
CCL.TRUTH0 = 4; /* Truth 0: 4 */
// CCL.LUT0CTRLC = CCL_INSEL2_MASK_gc; /* Masked input */
CCL.LUT0CTRLB = CCL_INSEL0_AC0_gc /* AC0 OUT input source */
| CCL_INSEL1_IN1_gc; /* IO pin LUTn-IN1 input source */
CCL.LUT0CTRLA = CCL_CLKSRC_CLKPER_gc /* Peripheral Clock */
| CCL_EDGEDET_DIS_gc /* Edge detector is disabled */
| CCL_FILTSEL_DISABLE_gc /* Filter disabled */
| 1 << CCL_ENABLE_bp /* LUT Enable: enabled */
| 1 << CCL_OUTEN_bp; /* Output Enable: enabled */
CCL.TRUTH1 = 1; /* Truth 1: 1 */
CCL.LUT1CTRLC = CCL_INSEL2_EVENTB_gc; /* Event input source B */
CCL.LUT1CTRLB = CCL_INSEL0_AC0_gc /* AC0 OUT input source */
| CCL_INSEL1_EVENTA_gc; /* Event input source A */
CCL.LUT1CTRLA = CCL_CLKSRC_CLKPER_gc /* Peripheral Clock */
| CCL_FILTSEL_DISABLE_gc /* Filter disabled */
| 1 << CCL_ENABLE_bp /* LUT Enable: enabled */
| 1 << CCL_OUTEN_bp; /* Output Enable: enabled */
CCL.TRUTH2 = 4; /* Truth 2: 4 */
CCL.LUT2CTRLC = CCL_INSEL2_IN2_gc; /* IO pin LUTn-IN2 input source */
CCL.LUT2CTRLB = CCL_INSEL0_AC0_gc /* AC0 OUT input source */
| CCL_INSEL1_IN1_gc; /* IO pin LUTn-IN1 input source */
CCL.LUT2CTRLA = CCL_CLKSRC_CLKPER_gc /* Peripheral Clock */
| CCL_EDGEDET_DIS_gc /* Edge detector is disabled */
| CCL_FILTSEL_DISABLE_gc /* Filter disabled */
| 1 << CCL_ENABLE_bp /* LUT Enable: enabled */
| 0 << CCL_OUTEN_bp; /* Output Enable: disabled */
CCL.TRUTH3 = 4; /* Truth 3: 4 */
CCL.LUT3CTRLC = CCL_INSEL2_EVENTB_gc; /* Event input source B */
CCL.LUT3CTRLB = CCL_INSEL0_AC0_gc /* AC0 OUT input source */
| CCL_INSEL1_EVENTA_gc; /* Event input source A */
CCL.LUT3CTRLA = CCL_CLKSRC_CLKPER_gc /* Peripheral Clock */
| CCL_EDGEDET_DIS_gc /* Edge detector is disabled */
| CCL_FILTSEL_DISABLE_gc /* Filter disabled */
| 1 << CCL_ENABLE_bp /* LUT Enable: enabled */
| 0 << CCL_OUTEN_bp; /* Output Enable: disabled */
CCL.CTRLA = 1 << CCL_ENABLE_bp /* Enable: enabled */
| 0 << CCL_RUNSTDBY_bp; /* Run in Standby: disabled */
// CCL.INTCTRL0 = CCL_INTMODE0_BOTH_gc /* Sense both edges */
// | CCL_INTMODE1_BOTH_gc /* Sense both edges */
// | CCL_INTMODE2_BOTH_gc /* Sense both edges */
// | CCL_INTMODE3_BOTH_gc; /* Sense both edges */
return 0;
}
#include "Logic.h"
#include "Event.h"
//PIN_PB0 PIN_PB1 and PIN_PB3 are mapped by default on LOGIC BLOCK CCL LUT2
void INIT_LOGIC_BLOCK2()
{
Logic2.enable; //ENABLE LUT2
Logic2.input0 = logic::in::input; //input PIN_PB0
//Logic2.input1 = logic::in::input; //input PIN_PB11
Logic2.input1 = logic::in::event_a; //event_a OF LUT2
Logic2.input2 = logic::in::masked; //masked = not used
//Logic2.output = logic::out::enable; //active output
Logic2.output = logic::out::disable; //disable output
//Logic2.output_swap = logic::out::no_swap; // Use position, pin 3 on the port so here PIN_PB3
//Logic2.output_swap = logic::out::pin_swap; // Use alternative position, pin 6 on the port so here PIN_PB6
Logic2.truth = 0x08; //AND OUT ON IF BOTH IN ARE HIGH
Logic2.init();
Logic2.start();
}
void INIT_EVENT()
{
Event0.assign_generator_pin(gen0::pin_pa1);
Event0.set_user(user::ccl2_event_a); //EVENT A OF LUT2
Event0.start();
Event1.assign_generator(gen::ccl2_out);
//Event1.set_user_pin(user::evouta_pin_pa2); //route on PA2
Event1.set_user_pin(user::evouta_pin_pa7); //route on PA7
Event1.start();
}
Logic2.output = logic::out::enable; //enable OUTPUT PIN
le routage se fait sur la broche par défaut soit PIN_PA3 ( la librairie met par défaut la broche usuelleLogic2.output_swap = logic::out::no_swap; //use PIN_PA3 as OUTPUT for LUT2
Logic2.output = logic::out::enable; //active OUTPUT
Logic2.output_swap = logic::out::pin_swap; // Use alternative position, pin 6 on the port so here PIN_PB6
#include "Logic.h"
#include "Event.h"
//PIN_PB0 PIN_PB1 and PIN_PB3 are mapped by default on LOGIC BLOCK CCL LUT2
void INIT_LOGIC_BLOCK2()
{
Logic2.enable; //ENABLE LUT2
Logic2.input0 = logic::in::input; //input PIN_PB0
//Logic2.input1 = logic::in::input; //input PIN_PB11
Logic2.input1 = logic::in::event_a; //event_a OF LUT2
Logic2.input2 = logic::in::masked; //masked = not used
Logic2.output = logic::out::enable; //active output
//Logic2.output_swap = logic::out::no_swap; // Use position, pin 3 on the port so here PIN_PB3
Logic2.output_swap = logic::out::pin_swap; // Use alternative position, pin 6 on the port so here PIN_PB6
Logic2.truth = 0x08; //AND OUT ON IF BOTH IN ARE HIGH
Logic2.init();
Logic2.start();
}
void INIT_EVENT()
{
Event0.assign_generator_pin(gen0::pin_pa1);
Event0.Event3.set_user(user::ccl2_event_a); //EVENT A OF LUT2
Event0.start();
}
void setup() {
PORTA.DIRCLR = PIN1_bm; //INPUT for PIN_PA1 = pinMode(PIN_PA1,INPUT) but faster!!
INIT_EVENT();
INIT_LOGIC_BLOCK2();
}
void loop() {
}
#include "Logic.h"
#include "Event.h"
//PIN_PB0 PIN_PB1 and PIN_PB3 are mapped by default on LOGIC BLOCK CCL LUT2
void INIT_LOGIC_BLOCK2()
{
Logic2.enable; //ENABLE LUT2
Logic2.input0 = logic::in::input; //input PIN_PB0
//Logic2.input1 = logic::in::input; //input PIN_PB1
Logic2.input1 = logic::in::event_a; //event_a OF LUT2
Logic2.input2 = logic::in::masked; //masked = not used
Logic2.output = logic::out::enable; //enable OUTPUT
Logic2.output_swap = logic::out::no_swap; //use PIN_PA3
Logic2.truth = 0x08; //AND OUT ON IF BOTH IN ARE HIGH
Logic2.init();
Logic2.start();
}
void INIT_EVENT()
{
Event0.assign_generator_pin(gen0::pin_pa1);
Event0.set_user(user::ccl2_event_a); //EVENT A OF LUT2
Event0.start();
}
void setup() {
PORTA.DIRCLR = PIN1_bm; //INPUT for PIN_PA1 = pinMode(PIN_PA1,INPUT) but faster!!
INIT_EVENT();
INIT_LOGIC_BLOCK2();
}
void loop() {
}
#include "Logic.h"
//PIN_PB0 PIN_PB1 and PIN_PB3 are mapped by default on LOGIC BLOCK CCL LUT2
void INIT_LOGIC_BLOCK2()
{
Logic2.enable; //ENABLE LUT2
Logic2.input0 = logic::in::input; //input PIN_PB0
Logic2.input1 = logic::in::input; //input PIN_PB1
Logic2.input2 = logic::in::masked; //masked = not used
Logic2.output = logic::out::enable; //use OUTPUT
Logic2.output_swap = logic::out::no_swap; // use PIN_PB3 as OUTPUT
Logic2.truth = 0x08; //AND OUT ON IF BOTH IN ARE HIGH
Logic2.init();
Logic2.start();
}
void setup() {
INIT_LOGIC_BLOCK2();
}
void loop() {
}
/*
* WE USE:
* PIN_PB0 PIN_PB1 as INPUT
* PIN_PB3 as OUTPUT
*/
#define ENTREE_1 PIN_PB0
#define ENTREE_2 PIN_PB1
#define SORTIE_1 PIN_PB3
void setup() {
// put your setup code here, to run once:
pinMode(ENTREE_1,INPUT);
pinMode(ENTREE_2,INPUT);
pinMode(SORTIE_1,OUTPUT);
}
void loop() {
bool IN1 = digitalRead(ENTREE_1);
bool IN2 = digitalRead(ENTREE_2);
bool OUT_STATE = IN1 & IN2;
digitalWrite(SORTIE_1,OUT_STATE);
}
#define SORTIE1_ON PORTB.OUTSET = PIN3_bm
#define SORTIE1_OFF PORTB.OUTCLR = PIN3_bm
#define IN1 GPIOR0
#define IN2 GPIOR1
#define OUT_STATE GPIOR3
void setup() {
// put your setup code here, to run once:
//PIN_PB0 AS INPUT:
PORTB.DIRSET = PIN0_bm;
//PIN_PB1 AS INPUT:
PORTB.DIRSET = PIN1_bm;
//PIN_PB3 AS OUTPUT
PORTB.DIRCLR = PIN3_bm;
}
void loop() {
// put your main code here, to run repeatedly:
IN1 = PORTB.IN & PIN0_bm;
IN2 = PORTB.IN & PIN1_bm;
OUTSTATE = IN1 & IN2;
if(OUTSTATE)
{
SORTIE1_ON;
}
else
{
SORTIE1_OFF;
}
}