L’objectif du projet est de créer une table de jeu de rôle conçue pour 4 joueurs, avec une tour à dés rétractable pour chaque joueur. Au centre de la table, il y aura un écran affichant la carte du jeu, et les personnages seront représentés par des tokens physiques que les joueurs pourront placer sur cet écran. Chaque joueur disposera également d’une tablette contenant sa fiche de personnage.
Boite du Arduino
Pour la boîte de rangement, j’ai opté pour une belle boîte en bois provenant de ma grand-mère. Malheureusement, nous avons déjà mangé tous les gâteaux qu’elle contenait !
De plus, il faudra court-circuiter l’alimentation afin qu’elle puisse démarrer sans carte mère.
Je coupe l’alimentation du fils CPU pour le brancher sur le Arduino
La table
Le code du arduino
#include <ArduinoMotorCarrier.h>
#define INTERRUPT_PIN 6
//Variable to store the battery voltage
static float batteryVoltage;
//low battery limit (discharged)
static float batteryLimit;
//Variable to change the motor speed and direction
int duty = 100;
// Variables 1M1
int btnVal1 = 0;
bool btnState1 = false;
bool oldbtnState1 = false;
bool motorStateM1 = false;
// Variables 2M2
int btnVal2 = 0;
bool btnState2 = false;
bool oldbtnState2 = false;
bool motorStateM2 = false;
// Variables 3M3
int btnVal3 = 0;
bool btnState3 = false;
bool oldbtnState3 = false;
bool motorStateM3 = false;
// Variables 4M4
int btnVal4 = 0;
bool btnState4 = false;
bool oldbtnState4 = false;
bool motorStateM4 = false;
void setup() {
//Serial port initialization
Serial.begin(115200);
//Establishing the communication with the motor shield
if (controller.begin()) {
Serial.print("MKR Motor Shield connected, firmware version ");
Serial.println(controller.getFWVersion());
} else {
Serial.println("Couldn't connect! Is the red led blinking? You may need to update the firmware with FWUpdater sketch");
while (1);
}
// Reboot the motor controller; brings every value back to default
Serial.println("reboot");
controller.reboot();
delay(500);
//Take the battery status
float batteryVoltage = (float)battery.getRaw() / 77;
Serial.print("Battery voltage: ");
Serial.println(batteryVoltage);
M1.setDuty(0);
M2.setDuty(0);
M3.setDuty(0);
M4.setDuty(0);
batteryLimit = 9.50; //Around 9V for a 3S LiPo battery
}
void loop() {
//Take the battery status
batteryVoltage = (float)battery.getRaw() / 77;
//Reset to the default values if the battery levels are lower than 11V
if (batteryVoltage < batteryLimit) {
Serial.println(" ");
Serial.println("WARNING: LOW BATTERY");
Serial.println("ALL SYSTEMS DOWN");
M1.setDuty(0);
M2.setDuty(0);
M3.setDuty(0);
M4.setDuty(0);
while (batteryVoltage < batteryLimit) {
batteryVoltage = (float)battery.getRaw() / 77;
controller.ping();
//wait
delay(50);
}
} else {
//Motor test
PushBtnB1M1();
PushBtnB2M2();
PushBtnB3M3();
PushBtnB4M4();
delay(500);
float batteryVoltage = (float)battery.getRaw() / 77;
Serial.println(" ");
Serial.print("Battery voltage: ");
Serial.println(batteryVoltage);
//Keep active the communication MKR1000 & MKRMotorCarrier
//Ping the samd11
controller.ping();
//wait
delay(50);
}
}
void PushBtnB1M1() {
btnVal1 = digitalRead(1);
Serial.println(" ");
Serial.print(F("Button 1 D1: "));
Serial.print(btnVal1);
if (btnVal1 == 0) {
btnVal1 = digitalRead(1);
delay(300);
if (btnVal1 == 0) {
btnVal1 = digitalRead(1);
delay(300);
if (btnVal1 == 0) {
Serial.println(" ");
Serial.print(F("Button 1 enable: "));
Serial.print(btnVal1);
btnState1 = true;
}
}
} else {
btnState1 = false;
}
if (oldbtnState1 != btnState1) {
if (btnState1 == true) {
Serial.println(" ");
Serial.print(F("Button was pressed"));
Serial.print(F("-->"));
Serial.print(F("Motor 1"));
motorStateM1 = !motorStateM1;
if (motorStateM1) {
M1.setDuty(100);
} else {
M1.setDuty(-100);
}
}
}
oldbtnState1 = btnState1;
}
void PushBtnB2M2() {
btnVal2 = digitalRead(6);
Serial.println(" ");
Serial.print(F("Button 2 D6: "));
Serial.print(btnVal2);
if (btnVal2 == 0) {
btnVal2 = digitalRead(6);
delay(300);
if (btnVal2 == 0) {
btnVal2 = digitalRead(6);
delay(300);
if (btnVal2 == 0) {
Serial.println(" ");
Serial.print(F("Button 2 enable: "));
Serial.print(btnVal2);
btnState2 = true;
}
}
} else {
btnState2 = false;
}
if (oldbtnState2 != btnState2) {
if (btnState2 == true) {
Serial.println(" ");
Serial.print(F("Button was pressed"));
Serial.print(F("-->"));
Serial.print(F("LED "));
motorStateM2 = !motorStateM2;
if (motorStateM2) {
M2.setDuty(100);
} else {
M2.setDuty(-100);
}
}
}
oldbtnState2 = btnState2;
}
void PushBtnB3M3() {
btnVal3 = analogRead(A2);
Serial.println(" ");
Serial.print(F("Button 3 A2: "));
Serial.print(btnVal3);
if (btnVal3 < 20) {
btnVal3 = analogRead(A2);
delay(300);
if (btnVal3 < 20) {
btnVal3 = analogRead(A2);
delay(300);
if (btnVal3 < 20) {
Serial.println(" ");
Serial.print(F("Button 3 enable: "));
Serial.print(btnVal3);
btnState3 = true;
}
}
} else {
btnState3 = false;
}
if (oldbtnState3 != btnState3) {
if (btnState3 == true) {
Serial.println(" ");
Serial.print(F("Button was pressed"));
Serial.print(F("-->"));
Serial.print(F("LED "));
motorStateM3 = !motorStateM3;
if (motorStateM3) {
M3.setDuty(100);
} else {
M3.setDuty(-100);
}
}
}
oldbtnState3 = btnState3;
}
void PushBtnB4M4() {
btnVal4 = analogRead(A6);
Serial.println(" ");
Serial.print(F("Button 4 A6: "));
Serial.print(btnVal4);
if (btnVal4 < 20) {
btnVal4 = analogRead(A6);
delay(300);
if (btnVal4 < 20) {
btnVal4 = analogRead(A6);
delay(300);
if (btnVal4 < 20) {
Serial.println(" ");
Serial.print(F("Button 4 enable: "));
Serial.print(btnVal4);
btnState4 = true;
}
}
} else {
btnState4 = false;
}
if (oldbtnState4 != btnState4) {
if (btnState4 == true) {
Serial.println(" ");
Serial.print(F("Button was pressed"));
Serial.print(F("-->"));
Serial.print(F("LED "));
motorStateM4 = !motorStateM4;
if (motorStateM4) {
M4.setDuty(100);
} else {
M4.setDuty(-100);
}
}
}
oldbtnState4 = btnState4;
}