Initialisation dépot
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#include <Arduino.h>
|
||||
#include <Servo.h>
|
||||
|
||||
#define DCC_SIGNAL_PIN 2
|
||||
#define LED_PIN 3
|
||||
#define PWM_PIN 5
|
||||
#define SERVO_PIN 6
|
||||
|
||||
Servo servoMotor;
|
||||
volatile bool dccSignalReceived = false;
|
||||
|
||||
void IRAM_ATTR handleDccSignal() {
|
||||
dccSignalReceived = true;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
pinMode(DCC_SIGNAL_PIN, INPUT);
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
pinMode(PWM_PIN, OUTPUT);
|
||||
|
||||
servoMotor.attach(SERVO_PIN);
|
||||
servoMotor.write(90); // position centrale
|
||||
|
||||
attachInterrupt(digitalPinToInterrupt(DCC_SIGNAL_PIN), handleDccSignal, RISING);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (dccSignalReceived) {
|
||||
dccSignalReceived = false;
|
||||
|
||||
// TODO: Décoder la commande DCC et piloter les sorties
|
||||
digitalWrite(LED_PIN, !digitalRead(LED_PIN));
|
||||
analogWrite(PWM_PIN, digitalRead(PWM_PIN) ? 0 : 255);
|
||||
servoMotor.write(0);
|
||||
delay(250);
|
||||
servoMotor.write(180);
|
||||
delay(250);
|
||||
servoMotor.write(90);
|
||||
}
|
||||
|
||||
delay(10);
|
||||
}
|
||||
Reference in New Issue
Block a user