Modifications

Cube de l'Au-delà

11 957 octets ajoutés, 8 avril 2018 à 18:06
aucun résumé de modification
A la fin de la prédiction, on envoie une information à IFTTT (il faut avoir un compte lié à son photon et au compte twitter sur le site) qui publie sur Twitter.
[https://drive.google.com/file/d/1niUx1CagJuj1ZdFCEcIysbb9WKwEJCai/view?usp=sharing TELECHARGER LE CODE DU CUBE(aussi disponible en bas de page)]
L’étape la plus difficile : la mise en place !
Un grand merci à Pierre Commenge et Clément Gault mais également aux animateurs de la Plateforme C pour leur aide.
 
//Code pour PHOTON permettant de créer un cube façon OUIJA qui prédit des mots au hasard.
 
//bibliothèque pour les bandeaux led
#include <neopixel.h>
 
 
#define PIXEL_PIN D2 //pin du bandeau
#define PIXEL_COUNT 26 //nb de leds du bandeau
#define PIXEL_TYPE WS2812B
 
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
 
 
long etat; // moment ou on appuie sur le bouton du téléphone
 
int mot; // variable du mot qui va sortir
int pression = A4; //bouton pression à pour capter l'argent
bool argent = false;
bool boutonc = false;
bool bouton_appuye = false;
bool hold = true;
 
String prediction; //prédiction du cube
 
int broche_bouton1 = D0; //bouton du téléphone
int bouton1 = D1; //boutons capacitifs autour du cube
int bouton2 = D3;
int bouton3 = D4;
int bouton4 = D5;
int cool ;
 
Servo servo;
const int moteur = A1;
 
 
void setup() {
 
Serial.begin(9600);
strip.begin();
strip.show();
 
 
//initialisation des pins
pinMode(broche_bouton1, INPUT);
pinMode(pression, INPUT);
 
pinMode(bouton1, INPUT);
pinMode(bouton2, INPUT);
pinMode(bouton3, INPUT);
pinMode(bouton4, INPUT);
 
strip.setBrightness(50);
 
}
 
void loop() {
 
//on teste la valeur du bouton pression dès le début
int valeurP = analogRead(pression);
 
//si tous les utilisateurs posent leur doigt sur le cube
if((digitalRead(bouton3) == 1) && (digitalRead(bouton4) == 1) && (digitalRead(bouton2) == 1) && (digitalRead(bouton1) == 1) && (boutonc == false)){
//on déclenche le moteur
servo.attach(moteur);
servo.write(0);
delay(1000);
servo.write(90);
delay(1000);
servo.detach();
//on change la bool pour faire qu'une seule fois la boucle
boutonc = true;
}
 
//si on met une piece
if(analogRead(pression) != valeurP) {
//on change la bool
argent = true;
}
 
//si on appuie sur le bouton, que tous les boutons on été appuyé simultannément au moins une fois et qu'on a mis de l'argent (ou qu'on appuie sur le bouton D6 pour directement accéder aux mots)
if ((digitalRead(broche_bouton1) == HIGH) && (bouton_appuye == false) && (argent) && (boutonc) || (digitalRead(D6) == 1)) {
//on calcule la durée
etat = millis();
bouton_appuye = true;
// grâce à la pin A0 on créé une variable random mot
randomSeed(analogRead(A0));
mot = int(random(12)+1);
}
 
//on lance les lettres au hasard entre le case 1 et 12
if ((millis()-etat<5000) && (bouton_appuye) && (hold)){
 
 
switch(mot){
case 1 : // NON
if(millis()-etat<2000) {
strip.setBrightness(50);
strip.setPixelColor(11, strip.Color(255, 255, 255)); //1
} else if(millis()-etat>3500) {
strip.setBrightness(50);
strip.setPixelColor(11, strip.Color(255, 255, 255)); //3
strip.setPixelColor(17, strip.Color(0, 0, 0));
delay(1500);
hold = false;
} else {
strip.setPixelColor(11, strip.Color(0, 0, 0)); //2
strip.setBrightness(50);
strip.setPixelColor(17, strip.Color(255, 255, 255));
}
 
 
prediction = "non";
 
 
break;
 
case 2 : // OUI
if(millis()-etat<2000) {
strip.setBrightness(50);
strip.setPixelColor(17, strip.Color(255, 255, 255)); //1
} else if(millis()-etat>3500) {
strip.setBrightness(50);
strip.setPixelColor(7, strip.Color(255, 255, 255)); //3
strip.setPixelColor(12, strip.Color(0, 0, 0));
delay(1500);
hold = false;
} else {
strip.setPixelColor(17, strip.Color(0, 0, 0)); //2
strip.setBrightness(50);
strip.setPixelColor(12, strip.Color(255, 255, 255));
}
 
prediction = "oui";
break;
 
case 3 : //BOF
if(millis()-etat<2000) {
strip.setBrightness(50);
strip.setPixelColor(5, strip.Color(255, 255, 255)); //1
} else if(millis()-etat>3500) {
strip.setBrightness(50);
strip.setPixelColor(1, strip.Color(255, 255, 255)); //3
strip.setPixelColor(17, strip.Color(0, 0, 0));
delay(1500);
hold = false;
} else {
strip.setPixelColor(5, strip.Color(0, 0, 0)); //2
strip.setBrightness(50);
strip.setPixelColor(17, strip.Color(255, 255, 255));
}
 
prediction = "bof";
break;
 
 
case 4 : //TKT
if(millis()-etat<2000) {
strip.setBrightness(50);
strip.setPixelColor(13, strip.Color(255, 255, 255)); //1
} else if(millis()-etat>3500) {
strip.setBrightness(50);
strip.setPixelColor(13, strip.Color(255, 255, 255)); //3
strip.setPixelColor(8, strip.Color(0, 0, 0));
delay(1500);
hold = false;
} else {
strip.setPixelColor(13, strip.Color(0, 0, 0)); //2
strip.setBrightness(50);
strip.setPixelColor(8, strip.Color(255, 255, 255));
}
 
prediction = "tkt";
break;
 
case 5 : //OMG
if(millis()-etat<2000) {
strip.setBrightness(50);
strip.setPixelColor(17, strip.Color(255, 255, 255)); //1
} else if(millis()-etat>3500) {
strip.setBrightness(50);
strip.setPixelColor(0, strip.Color(255, 255, 255)); //3
strip.setPixelColor(10, strip.Color(0, 0, 0));
delay(1500);
hold = false;
} else {
strip.setPixelColor(17, strip.Color(0, 0, 0)); //2
strip.setBrightness(50);
strip.setPixelColor(10, strip.Color(255, 255, 255));
}
 
prediction = "omg";
break;
 
case 6 : //NOP
if(millis()-etat<2000) {
strip.setBrightness(50);
strip.setPixelColor(11, strip.Color(255, 255, 255)); //1 N
} else if(millis()-etat>3500) {
strip.setBrightness(50);
strip.setPixelColor(16, strip.Color(255, 255, 255)); //3 P
strip.setPixelColor(17, strip.Color(0, 0, 0));
delay(1500);
hold = false;
} else {
strip.setPixelColor(11, strip.Color(0, 0, 0)); //2 O
strip.setBrightness(50);
strip.setPixelColor(17, strip.Color(255, 255, 255));
}
 
prediction = "nop";
break;
 
 
 
case 7 : //LOL
if(millis()-etat<2000) {
strip.setBrightness(50);
strip.setPixelColor(9, strip.Color(255, 255, 255)); //1 L
} else if(millis()-etat>3500) {
strip.setBrightness(50);
strip.setPixelColor(9, strip.Color(255, 255, 255)); //3 L
strip.setPixelColor(17, strip.Color(0, 0, 0));
 
delay(1500);
hold = false;
} else {
strip.setPixelColor(9, strip.Color(0, 0, 0)); //2 O
strip.setBrightness(50);
strip.setPixelColor(17, strip.Color(255, 255, 255));
}
prediction = "lol";
break;
 
 
case 8 : //LOL
if(millis()-etat<2000) {
strip.setBrightness(50);
strip.setPixelColor(9, strip.Color(255, 255, 255)); //1
} else if(millis()-etat>3500) {
strip.setBrightness(50);
strip.setPixelColor(9, strip.Color(255, 255, 255)); //3
strip.setPixelColor(17, strip.Color(0, 0, 0));
delay(1500);
hold = false;
} else {
strip.setPixelColor(9, strip.Color(0, 0, 0)); //2
strip.setBrightness(50);
strip.setPixelColor(17, strip.Color(255, 255, 255));
}
prediction = "lol";
break;
 
case 9 : //OUF
if(millis()-etat<2000) {
strip.setBrightness(50);
strip.setPixelColor(17, strip.Color(255, 255, 255)); //1 O
} else if(millis()-etat>3500) {
strip.setBrightness(50);
strip.setPixelColor(1, strip.Color(255, 255, 255)); //3 F
strip.setPixelColor(12, strip.Color(0, 0, 0));
delay(1500);
hold = false;
} else {
strip.setPixelColor(17, strip.Color(0, 0, 0)); //2 U
strip.setBrightness(50);
strip.setPixelColor(12, strip.Color(255, 255, 255));
}
 
prediction = "ouf";
break;
 
case 10 : //con
if(millis()-etat<2000) {
strip.setBrightness(50);
strip.setPixelColor(4, strip.Color(255, 255, 255)); //1 C
} else if(millis()-etat>3500) {
strip.setBrightness(50);
strip.setPixelColor(11, strip.Color(255, 255, 255)); //3 N
strip.setPixelColor(17, strip.Color(0, 0, 0));
delay(1500);
hold = false;
} else {
strip.setPixelColor(4, strip.Color(0, 0, 0)); //2 O
strip.setBrightness(50);
strip.setPixelColor(17, strip.Color(255, 255, 255));
}
 
prediction = "con";
break;
 
case 11 : //dsl
if(millis()-etat<2000) {
strip.setBrightness(50);
strip.setPixelColor(3, strip.Color(255, 255, 255)); //1 D
} else if(millis()-etat>3500) {
strip.setBrightness(50);
strip.setPixelColor(9, strip.Color(255, 255, 255)); //3 l
strip.setPixelColor(14, strip.Color(0, 0, 0));
delay(1500);
hold = false;
} else {
strip.setPixelColor(3, strip.Color(0, 0, 0)); //2 s
strip.setBrightness(50);
strip.setPixelColor(14, strip.Color(255, 255, 255));
}
 
prediction = "dsl";
break;
 
case 12 : //BOF
if(millis()-etat<2000) {
strip.setBrightness(50);
strip.setPixelColor(5, strip.Color(255, 255, 255)); //1
} else if(millis()-etat>3500) {
strip.setBrightness(50);
strip.setPixelColor(1, strip.Color(255, 255, 255)); //3
strip.setPixelColor(17, strip.Color(0, 0, 0));
delay(1500);
hold = false;
} else {
strip.setPixelColor(5, strip.Color(0, 0, 0)); //2
strip.setBrightness(50);
strip.setPixelColor(17, strip.Color(255, 255, 255));
}
 
prediction = "bof";
break;
 
 
 
}
//on envoie grâce a IFTTT un message avec le contenu de la prédiction
Particle.publish("prediction", "Les morts ont compris ta question, pour eux c'est... "+ prediction);
}
else {
// on arrete la boucle
bouton_appuye=false;
strip.setBrightness(0);
}
strip.show();
delay(300);
}
1 013
modifications