Modifications

StartUpGenerator

5 720 octets ajoutés, 3 avril 2018 à 14:52
aucun résumé de modification
Rester appuyé au min 3 s sur un bouton sous un piège à souris.<br />
[[File:6.jpg|700px]]
 
== Branchement & Programmation ==
 
[[File:29894325_1825262810872437_162955786_o.png|700px]]<br />
<br />
 
 
//START UP GENERATOR
// le Cube connecté qui prédit l'avenir de votre startup
 
//LIBRAIRIES IMPRIMANTES : les ports peuvent être redéfinis ci-dessous
#include "SoftwareSerial.h"
#include "Adafruit_Thermal.h"
#include <avr/pgmspace.h>
 
//LIBRAIRIES AUDIO : attention à ne pas utiliser les ports ci-dessous
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
#define BREAKOUT_RESET 9 // VS1053 reset pin (output)
#define BREAKOUT_CS 10 // VS1053 chip select pin (output)
#define BREAKOUT_DCS 8 // VS1053 Data/command select pin (output)
// These are the pins used for the music maker shield
#define SHIELD_RESET -1 // VS1053 reset pin (unused!)
#define SHIELD_CS 7 // VS1053 chip select pin (output)
#define SHIELD_DCS 6 // VS1053 Data/command select pin (output)
// These are common pins between breakout and shield
#define CARDCS 4 // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3 // VS1053 Data request, ideally an Interrupt pin
Adafruit_VS1053_FilePlayer musicPlayer =
// create shield-example object!
Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
 
 
 
//BOUTONS
 
//bouton piste 1
const int buttonPin1 = 39;
int buttonState1 = 0;
 
//bouton piste 2
const int buttonPin2 = 2;
int buttonState2 = 0;
 
//bouton piste 3
const int buttonPin3 = 16;
int buttonState3 = 0;
 
//capteur imprimer
const int buttonPressure = A0;
int pressureState = 0;
 
//tweet
//const int tweetPin = 41;
//int tweetState = 0;
 
//led
const int ledPin13 = 13;
 
 
//PRINTER
//Paramètres de l'imprimante
String s;
int n;
boolean b = false;
Adafruit_Thermal printer(5, 22); //ports utilisés : 5 = fil rouge, 22 = fil jaune;
 
 
//millis
unsigned long previousMillis = 0;
unsigned long currentMillis;
unsigned long interval = 5000; //delay pour la led
 
 
void setup() {
 
//PRINTER
Serial.begin(9600);
printer.begin();
 
//Initialisation entrée et sorties
pinMode(ledPin13, OUTPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin1, INPUT);
pinMode(buttonPressure, INPUT);
pinMode(buttonPin3, INPUT);
//pinMode(tweetPin, OUTPUT);
 
//AUDIO
if (! musicPlayer.begin()) { // initialise the music player
Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
while (1);
}
Serial.println(F("VS1053 found"));
if (!SD.begin(CARDCS)) {
Serial.println(F("SD failed, or not present"));
while (1); // don't do anything more
}
// list files
printDirectory(SD.open("/"), 0);
musicPlayer.setVolume(20, 20);
musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT); // DREQ int
 
}
 
void loop() {
 
//Initiatlisation - Vérifications
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
//tweetState = digitalRead(tweetPin);
pressureState = analogRead(buttonPressure);
//Serial.print("val:");
//Serial.println(pressureState);
 
//algorithme
 
//PART 1 : La piste 1 se lance
if (buttonState1 == HIGH) {
digitalWrite(ledPin13, HIGH);
musicPlayer.playFullFile("track001.mp3");
Serial.println("bouton1appuyé");
}
 
//PART 2 : la piste 2 se lance
if (buttonState2 == HIGH) {
musicPlayer.playFullFile("track002.mp3");
Serial.println("bouton2appuyé");
/*au bout de 3 secondes la led s'allume
currentMillis = millis();
 
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
//Led
digitalWrite(ledPin13, LOW);
unsigned long currentMillis = millis();
}
musicPlayer.playFullFile("track003.mp3");*/
}
 
//PART 3 : la piste 3 se lance
//Serial.println(buttonState3);
 
if (buttonState3 == HIGH) {
digitalWrite(ledPin13, HIGH);
musicPlayer.playFullFile("track004.mp3");
Serial.println("bouton3appuyé");
}
 
 
//PART 4 : l'imprimante imprime + envoie IFFTT
if (pressureState > 500) {
digitalWrite(ledPin13, LOW);
b = true; // lancer l'impression
//tweetState = 1;
//tweetState = 0;
}
 
 
//FONCTION IMPRIMANTE
if (b) {
Serial.println("button2");
//Serial.println("hello");
n = random(34);
ligne1(n);
printer.feed(1);
printer.boldOn();
n = random(34);
ligne2(n);
n = random(34);
printer.boldOff();//text en gras
ligne3(n);
printer.feed(1);
n = random(34);
ligne4(n);
printer.feed(1);
n = random(34);
ligne5(n);
 
printer.feed(5); //space
printer.sleep(); // Tell printer to sleep
printer.wake(); // MUST call wake() before printing again, even if reset
printer.setDefault(); // Restore printer to defaults
b = false;
}
 
 
}
 
 
/// File listing helper
void printDirectory(File dir, int numTabs) {
while (true) {
 
File entry = dir.openNextFile();
if (! entry) {
// no more files
//Serial.println("*nomorefiles*");
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
Serial.print('\t');
}
Serial.print(entry.name());
if (entry.isDirectory()) {
Serial.println("/");
printDirectory(entry, numTabs + 1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}
}
 
 
//imprimer une led : test
 
 
/*buttonState1 = digitalRead(22);
//Serial.println(buttonState1);
if (buttonState1 == HIGH) {
// turn LED on:
digitalWrite(ledPin13, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin13, LOW);
}*/
906
modifications