Description :
Voici un projet pour pouvoir animer vos boutons de votre borne Arcade ainsi que des rubans de led
Prérequis :
Matériel :
- 1 x Carte Arduino Mega 2560
- 1 x PCA9685 Pilote d’asservissement PWM 16 canaux 12 bits
- 18 x Résistance 10 KΩ
- 2 x Résistance 330 Ω
- 1 x Condensateur 1000uF
- 1 x Alimentation 5v
- 2 x Ruban de LED RGB ws2812b
- Fils de connexion
En option si LED pas en 5v :
- 10 x Résistance 100 Ω (Pour LED Bleue et blanche 3,2 V)
- 8 x Résistance 330 Ω (Pour LED Rouge 2,02 V )
Version IDE :
Bibliothèque :
-
Adafruit_NeoPixel.h
-
Adafruit_PWMServoDriver.h
Vidéo de démonstration :
Schéma de câblage :
Download Code :
Borne Arcade V1.0 |
//Pins des boutons A
const int buttonA[] = { 23, 29, 31, 33, 37, 39, 25, 35, 27 };
//Pins des boutons B
const int buttonB[] = { 22, 28, 30, 32, 36, 38, 24, 34, 26 };
//Pins des Leds A
const int SortieledsA[] = { 5, 4, 3, 2, 1, 0, 7, 6, 6 };
//Pins des Leds B
const int SortieledsB[] = { 10, 11, 12, 13, 14, 15, 8, 9, 9 };
//Gestion des boutons et joysticks
bool buttonEtatA[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
bool buttonEtatB[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int LedslumensA[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int LedslumensB[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/////////////////
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#include <Adafruit_NeoPixel.h>
#define PINStrip1 12
#define NUMPIXELSStrip1 35
Adafruit_NeoPixel pixelsStrip1(NUMPIXELSStrip1, PINStrip1, NEO_GRB + NEO_KHZ800);
#define PINStrip2 11
#define NUMPIXELSStrip2 35
Adafruit_NeoPixel pixelsStrip2(NUMPIXELSStrip2, PINStrip2, NEO_GRB + NEO_KHZ800);
/////////////////
unsigned long currentTime = 0;
unsigned long previousTime = 0;
unsigned long previousTimeStripsleds = 0;
int Cyclestripsleds;
int SensCyclestrips;
int Stripsledsvar1;
int Stripsledsvar2;
int TpspauseStrips;
void setup() {
Serial.begin(9600);
//Initialise les boutons A en entrée
for (int i = 0; i <= 8; i++) {
pinMode(buttonA[i], INPUT);
//Serial.println(buttonB[i]);
}
//Initialise les boutons B en entrée
for (int i = 0; i <= 8; i++) {
pinMode(buttonB[i], INPUT);
//Serial.println(buttonB[i]);
}
pwm.begin();
pwm.setOscillatorFrequency(27000000);
pwm.setPWMFreq(1600);
Wire.setClock(400000);
pixelsStrip1.begin();
pixelsStrip2.begin();
pixelsStrip1.clear();
pixelsStrip2.clear();
pixelsStrip1.show();
pixelsStrip2.show();
}
void loop() {
currentTime = millis();
int scrutarduino = currentTime - previousTime;
//Serial.println(scrutarduino);
previousTime = currentTime;
pwm.setPWM(SortieledsA[7], 0, 4095);
pwm.setPWM(SortieledsB[7], 0, 4095);
boutons();
Leds_Boutons_Anim1();
Strips_leds_Anim1();
}
void boutons() {
//Lecture des boutons A
for (int a = 0; a <= 8; a++) {
buttonEtatA[a] = digitalRead(buttonA[a]);
}
for (int a = 0; a <= 8; a++) {
if (buttonEtatA[a] == HIGH) {
Serial.println(buttonA[a]);
} else {
}
}
//Lecture des boutons B
for (int b = 0; b <= 8; b++) {
buttonEtatB[b] = digitalRead(buttonB[b]);
}
for (int b = 0; b <= 8; b++) {
if (buttonEtatB[b] == HIGH) {
Serial.println(buttonB[b]);
} else {
}
}
}
void Leds_Boutons_Anim1() {
for (int a = 0; a <= 6; a++) {
if (buttonEtatA[a] == HIGH) {
LedslumensA[a] = 4096;
//Serial.println(buttonA[a]);
}
if (LedslumensA[a] > 0) {
LedslumensA[a] = LedslumensA[a] - 15;
}
pwm.setPWM(SortieledsA[a], 0, LedslumensA[a]);
}
for (int b = 0; b <= 6; b++) {
if (buttonEtatB[b] == HIGH) {
LedslumensB[b] = 4096;
//Serial.println(buttonB[b]);
}
if (LedslumensB[b] > 0) {
LedslumensB[b] = LedslumensB[b] - 15;
}
pwm.setPWM(SortieledsB[b], 0, LedslumensB[b]);
}
}
void Strips_leds_Anim1() {
if (Cyclestripsleds == 0) {
Stripsledsvar1 = 17;
Stripsledsvar2 = 17;
Cyclestripsleds = 1;
SensCyclestrips = 0;
TpspauseStrips = 0;
}
if ((currentTime - previousTimeStripsleds) > 100) {
previousTimeStripsleds = currentTime;
if (Stripsledsvar1 >= 0 && Stripsledsvar1 < NUMPIXELSStrip1 && SensCyclestrips == 0) {
if (Stripsledsvar1 == 17 || Stripsledsvar1 == 16 || Stripsledsvar1 == 15) {
pixelsStrip1.setPixelColor(Stripsledsvar1, pixelsStrip1.Color(150, 150, 150));
pixelsStrip2.setPixelColor(Stripsledsvar1, pixelsStrip2.Color(150, 0, 0));
} else {
pixelsStrip1.setPixelColor(Stripsledsvar1, pixelsStrip1.Color(150, 0, 0));
pixelsStrip2.setPixelColor(Stripsledsvar1, pixelsStrip2.Color(150, 150, 150));
}
}
if (Stripsledsvar2 >= 0 && Stripsledsvar2 < NUMPIXELSStrip2 && SensCyclestrips == 0) {
if (Stripsledsvar2 == 17 || Stripsledsvar2 == 18 || Stripsledsvar2 == 19) {
pixelsStrip1.setPixelColor(Stripsledsvar2, pixelsStrip1.Color(150, 150, 150));
pixelsStrip2.setPixelColor(Stripsledsvar2, pixelsStrip2.Color(150, 0, 0));
} else {
pixelsStrip1.setPixelColor(Stripsledsvar2, pixelsStrip1.Color(150, 0, 0));
pixelsStrip2.setPixelColor(Stripsledsvar2, pixelsStrip2.Color(150, 150, 150));
}
}
if (Stripsledsvar1 >= 0 && Stripsledsvar1 < NUMPIXELSStrip1 && SensCyclestrips == 1) {
if (Stripsledsvar1 == 17 || Stripsledsvar1 == 16 || Stripsledsvar1 == 15) {
pixelsStrip1.setPixelColor(Stripsledsvar1, pixelsStrip1.Color(150, 150, 150));
pixelsStrip2.setPixelColor(Stripsledsvar1, pixelsStrip2.Color(150, 0, 0));
} else {
pixelsStrip1.setPixelColor(Stripsledsvar1, pixelsStrip1.Color(0, 0, 0));
pixelsStrip2.setPixelColor(Stripsledsvar1, pixelsStrip2.Color(0, 0, 0));
}
}
if (Stripsledsvar2 >= 0 && Stripsledsvar2 < NUMPIXELSStrip2 && SensCyclestrips == 1) {
if (Stripsledsvar2 == 17 || Stripsledsvar2 == 18 || Stripsledsvar2 == 19) {
pixelsStrip1.setPixelColor(Stripsledsvar2, pixelsStrip1.Color(150, 150, 150));
pixelsStrip2.setPixelColor(Stripsledsvar2, pixelsStrip2.Color(150, 0, 0));
} else {
pixelsStrip1.setPixelColor(Stripsledsvar2, pixelsStrip1.Color(0, 0, 0));
pixelsStrip2.setPixelColor(Stripsledsvar2, pixelsStrip2.Color(0, 0, 0));
}
}
pixelsStrip1.show();
pixelsStrip2.show();
if (Stripsledsvar1 > 0 && SensCyclestrips == 0) {
Stripsledsvar1--;
}
if (Stripsledsvar1 < 17 && SensCyclestrips == 1) {
Stripsledsvar1++;
}
if (Stripsledsvar2 < NUMPIXELSStrip2 && SensCyclestrips == 0) {
Stripsledsvar2++;
}
if (Stripsledsvar2 > 17 && SensCyclestrips == 1) {
Stripsledsvar2--;
}
if (Stripsledsvar1 == 0 || Stripsledsvar2 == NUMPIXELSStrip2) {
if (TpspauseStrips < 50) {
TpspauseStrips++;
} else {
SensCyclestrips = 1;
TpspauseStrips = 0;
}
}
if (Stripsledsvar1 == 17 || Stripsledsvar2 == 17) {
if (TpspauseStrips < 50) {
TpspauseStrips++;
} else {
SensCyclestrips = 0;
TpspauseStrips = 0;
}
}
}
}
Nombre de vues: 504