const int LED_PIN[] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
const int BGG_PIN = 11;
const int BG_PIN = 12;
const int BD_PIN = 13;
const int BDD_PIN = A0;
volatile bool direction = true; // true: left to right, false: right to left
volatile unsigned int speed = 200; // Delay between LED transitions
volatile bool updateSpeed = false;
void setup() {
Serial.begin(9600); // Initialisation de la communication série pour le débogage
for (int i = 0; i < 9; i++) {
pinMode(LED_PIN[i], OUTPUT);
digitalWrite(LED_PIN[i], LOW);
}
pinMode(BGG_PIN, INPUT_PULLUP);
pinMode(BG_PIN, INPUT_PULLUP);
pinMode(BD_PIN, INPUT_PULLUP);
pinMode(BDD_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(BGG_PIN), slowDown, FALLING);
attachInterrupt(digitalPinToInterrupt(BG_PIN), moveLeft, FALLING);
attachInterrupt(digitalPinToInterrupt(BD_PIN), moveRight, FALLING);
attachInterrupt(digitalPinToInterrupt(BDD_PIN), speedUp, FALLING);
}
void loop() {
if (direction) {
for (int i = 0; i < 9; i++) {
digitalWrite(LED_PIN[i], HIGH);
delay(speed);
digitalWrite(LED_PIN[i], LOW);
}
} else {
for (int i = 8; i >= 0; i--) {
digitalWrite(LED_PIN[i], HIGH);
delay(speed);
digitalWrite(LED_PIN[i], LOW);
}
}
}
void moveLeft() {
Serial.println("Direction: Gauche"); // Débogage
direction = false;
}
void moveRight() {
Serial.println("Direction: Droite"); // Débogage
direction = true;
}
void speedUp() {
if (speed > 50) { // Minimum speed limit
speed -= 50;
Serial.print("Speed Up: "); // Débogage
Serial.println(speed); // Débogage
}
}
void slowDown() {
if (speed < 1000) { // Maximum speed limit
speed += 50;
Serial.print("Slow Down: "); // Débogage
Serial.println(speed); // Débogage
}
}
/*
const int LED_PIN[] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
const int BGG_PIN = 11;
const int BDD_PIN = 12;
volatile unsigned int speed = 200; // Delay between LED transitions
volatile bool updateSpeed = false;
volatile bool speedUpPressed = false;
volatile bool slowDownPressed = false;
void setup() {
for (int i = 0; i < 9; i++) {
pinMode(LED_PIN[i], OUTPUT);
digitalWrite(LED_PIN[i], LOW);
}
pinMode(BGG_PIN, INPUT_PULLUP);
pinMode(BDD_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(BGG_PIN), slowDown, FALLING);
attachInterrupt(digitalPinToInterrupt(BDD_PIN), speedUp, FALLING);
attachInterrupt(digitalPinToInterrupt(BGG_PIN), releaseSlowDown, RISING);
attachInterrupt(digitalPinToInterrupt(BDD_PIN), releaseSpeedUp, RISING);
}
void loop() {
for (int i = 0; i < 9; i++) {
digitalWrite(LED_PIN[i], HIGH);
delay(speed);
digitalWrite(LED_PIN[i], LOW);
}
for (int i = 8; i >= 0; i--) {
digitalWrite(LED_PIN[i], HIGH);
delay(speed);
digitalWrite(LED_PIN[i], LOW);
}
}
void speedUp() {
if (!speedUpPressed) {
if (speed > 50) { // Minimum speed limit
speed -= 50;
}
speedUpPressed = true;
}
}
void slowDown() {
if (!slowDownPressed) {
if (speed < 1000) { // Maximum speed limit
speed += 50;
}
slowDownPressed = true;
}
}
void releaseSpeedUp() {
speedUpPressed = false;
}
void releaseSlowDown() {
slowDownPressed = false;
}
const int LED_PIN[] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
const int BGG_PIN = 11;
const int BDD_PIN = 12;
const int BG_PIN = 13;
const int BD_PIN = A0;
volatile unsigned int speed = 200; // Delay between LED transitions
volatile bool updateSpeed = false;
volatile bool direction = true; // true: left to right, false: right to left
volatile bool speedUpPressed = false;
volatile bool slowDownPressed = false;
void setup() {
for (int i = 0; i < 9; i++) {
pinMode(LED_PIN[i], OUTPUT);
digitalWrite(LED_PIN[i], LOW);
}
pinMode(BGG_PIN, INPUT_PULLUP);
pinMode(BDD_PIN, INPUT_PULLUP);
pinMode(BG_PIN, INPUT_PULLUP);
pinMode(BD_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(BGG_PIN), slowDown, FALLING);
attachInterrupt(digitalPinToInterrupt(BDD_PIN), speedUp, FALLING);
attachInterrupt(digitalPinToInterrupt(BGG_PIN), releaseSlowDown, RISING);
attachInterrupt(digitalPinToInterrupt(BDD_PIN), releaseSpeedUp, RISING);
attachInterrupt(digitalPinToInterrupt(BG_PIN), moveLeft, CHANGE);
attachInterrupt(digitalPinToInterrupt(BD_PIN), moveRight, CHANGE);
}
void loop() {
if (direction) {
for (int i = 0; i < 9; i++) {
digitalWrite(LED_PIN[i], HIGH);
delay(speed);
digitalWrite(LED_PIN[i], LOW);
}
} else {
for (int i = 8; i >= 0; i--) {
digitalWrite(LED_PIN[i], HIGH);
delay(speed);
digitalWrite(LED_PIN[i], LOW);
}
}
}
void speedUp() {
if (!speedUpPressed) {
if (speed > 50) { // Minimum speed limit
speed -= 50;
}
speedUpPressed = true;
}
}
void slowDown() {
if (!slowDownPressed) {
if (speed < 1000) { // Maximum speed limit
speed += 50;
}
slowDownPressed = true;
}
}
void releaseSpeedUp() {
speedUpPressed = false;
}
void releaseSlowDown() {
slowDownPressed = false;
}
void moveLeft() {
direction = false; // Change direction to right to left
}
void moveRight() {
direction = true; // Change direction to left to right
}
*/