#ifdef __AVR__
#include <avr/pgmspace.h>
#else
#define PROGMEM
#endif
#include "Playtune.h"
const unsigned char PROGMEM score [] = {
0,4, 0x90,76, 0x91,52, 1,6, 0x92,64, 0,15, 0x81, 0,233, 0x80, 0x90,71, 0x91,52, 0,15, 0x82, 0,217, 0x80,
0,15, 0x90,72, 0x92,64, 0,14, 0x81, 0,220, 0x80, 0,15, 0x90,74, 0x91,52, 0,14, 0x82, 0,237, 0x92,64, 0,15,
0x81, 0,236, 0x80, 0,1, 0x90,72, 0x91,52, 0,15, 0x82, 0,223, 0x80, 0,16, 0x90,71, 0x92,64, 0,15, 0x81, 0,226,
0x80, 0,18, 0x90,69, 0x91,45, 0,13, 0x82, 1,1, 0x92,57, 0,15, 0x81, 0,233, 0x80, 0x90,69, 0x91,45, 0,15,
0x82, 0,217, 0x80, 0,15, 0x90,72, 0x92,57, 0,14, 0x81, 0,220, 0x80, 0,15, 0x90,76, 0x91,45, 0,15, 0x82, 0,234,
0x92,57, 0,15, 0x81, 0,231, 0x80, 0x90,74, 0x91,45, 0,15, 0x82, 0,217, 0x80, 0,15, 0x90,72, 0x92,57, 0,15,
0x81, 0,217, 0x80, 0,18, 0x90,71, 0x91,44, 0,12, 0x82, 0,252, 0x92,56, 0,15, 0x81, 0,233, 0x80, 0x90,71, 0x91,44,
0,15, 0x82, 0,217, 0x80, 0,15, 0x90,72, 0x92,56, 0,14, 0x81, 0,220, 0x80, 0,15, 0x90,74, 0x91,44, 0,15,
0x82, 0,234, 0x92,56, 0,15, 0x81, 0,231, 0x80, 0x90,76, 0x91,44, 0,15, 0x82, 0,232, 0x92,56, 0,15, 0x81, 0,232,
0x80, 0,3, 0x90,72, 0x91,45, 0,12, 0x82, 0,252, 0x92,57, 0,15, 0x81, 0,233, 0x80, 0x90,69, 0x91,45, 0,15,
0x82, 0,232, 0x92,57, 0,14, 0x81, 0,234, 0x80, 0,1, 0x90,69, 0x91,45, 0,15, 0x82, 0,234, 0x92,57, 0,15,
0x81, 0,231, 0x80, 0x90,47, 0x91,59, 0,15, 0x82, 0,201, 0x81, 0,31, 0x91,48, 0x92,60, 0,15, 0x80, 0,202, 0x82,
0,33, 0x90,50, 0,12, 0x81, 0,252, 0x91,62, 0,15, 0x80, 0,233, 0x90,74, 0x92,50, 0,15, 0x81, 0,232, 0x91,62,
0,14, 0x82, 0,234, 0x80, 0,1, 0x90,77, 0x92,50, 0,14, 0x81, 0,220, 0x80, 0,15, 0x90,81, 0x91,62, 0,15,
0x82, 0,231, 0x92,50, 0,15, 0x81, 0,217, 0x80, 0,15, 0x90,62, 0,15, 0x82, 0,235, 0x91,79, 0x92,50, 0,12,
0x80, 0,237, 0x81, 0,15, 0x90,77, 0x91,62, 0,15, 0x82, 0,218, 0x80, 0,15, 0x90,76, 0x92,48, 0,15, 0x81, 0,232,
0x91,60, 0,14, 0x82, 0,235, 0x92,48, 0,14, 0x81, 0,235, 0x91,60, 0,15, 0x82, 0,231, 0x80, 0x90,72, 0x92,48,
0,15, 0x81, 0,217, 0x80, 0,15, 0x90,76, 0x91,60, 0,15, 0x82, 0,235, 0x92,48, 0,12, 0x81, 0,252, 0x91,60,
0,15, 0x82, 0,233, 0x80, 0x90,74, 0x92,48, 0,15, 0x81, 0,221, 0x80, 0,11, 0x90,72, 0x91,60, 0,14, 0x82, 0,220,
0x80, 0,15, 0x90,71, 0x92,44, 0,14, 0x81, 0,235, 0x91,56, 0,14, 0x82, 0,232, 0x92,44, 0,15, 0x81, 0,230,
0x80, 0,2, 0x90,72, 0x91,56, 0,15, 0x82, 0,217, 0x80, 0,18, 0x90,74, 0x92,44, 0,12, 0x81, 0,252, 0x91,56,
0,15, 0x82, 0,218, 0x80, 0,15, 0x90,76, 0x92,44, 0,15, 0x81, 0,232, 0x91,56, 0,14, 0x82, 0,234, 0x80, 0,1,
0x90,72, 0x92,45, 0,14, 0x81, 0,235, 0x91,57, 0,14, 0x82, 0,232, 0x80, 0x90,69, 0x92,45, 0,15, 0x81, 0,232,
0x91,57, 0,15, 0x82, 0,232, 0x80, 0,3, 0x90,69, 0x92,45, 0,12, 0x81, 0,252, 0x91,57, 0,15, 0x82, 0,233,
0x80, 0x90,45, 0,15, 0x81, 0,232, 0x91,57, 0,14, 0x80, 0,249, 0x81, 3,210, 0x90,76, 0x91,45, 1,8, 0x92,57,
0,15, 0x81, 0,233, 0x91,45, 0,15, 0x82, 0,232, 0x92,57, 0,14, 0x81, 0,234, 0x80, 0,1, 0x90,72, 0x91,45,
0,14, 0x82, 0,235, 0x92,57, 0,14, 0x81, 0,232, 0x91,45, 0,15, 0x82, 0,232, 0x92,57, 0,15, 0x81, 0,232,
0x80, 0,2, 0x90,74, 0x91,44, 0,13, 0x82, 0,252, 0x92,56, 0,15, 0x81, 0,233, 0x91,44, 0,15, 0x82, 0,232,
0x92,56, 0,14, 0x81, 0,234, 0x80, 0,1, 0x90,71, 0x91,44, 0,14, 0x82, 0,235, 0x92,56, 0,14, 0x81, 0,232,
0x91,44, 0,15, 0x82, 0,232, 0x92,56, 0,15, 0x81, 0,232, 0x80, 0,2, 0x90,72, 0x91,45, 0,13, 0x82, 0,252,
0x92,57, 0,15, 0x81, 0,233, 0x91,45, 0,15, 0x82, 0,232, 0x92,57, 0,14, 0x81, 0,234, 0x80, 0,1, 0x90,69,
0x91,45, 0,14, 0x82, 0,235, 0x92,57, 0,14, 0x81, 0,232, 0x91,45, 0,15, 0x82, 0,232, 0x92,57, 0,15, 0x81,
0,232, 0x80, 0,2, 0x90,68, 0x91,44, 0,13, 0x82, 0,252, 0x92,56, 0,15, 0x81, 0,233, 0x91,44, 0,15, 0x82,
0,232, 0x92,56, 0,14, 0x81, 0,234, 0x80, 0,1, 0x90,71, 0x91,44, 0,14, 0x82, 0,235, 0x92,56, 0,14, 0x81,
0,232, 0x91,44, 0,15, 0x82, 0,232, 0x92,56, 0,15, 0x81, 0,232, 0x80, 0,2, 0x90,76, 0x91,45, 0,13, 0x82,
0,252, 0x92,57, 0,15, 0x81, 0,233, 0x91,45, 0,15, 0x82, 0,232, 0x92,57, 0,14, 0x81, 0,234, 0x80, 0,1,
0x90,72, 0x91,45, 0,14, 0x82, 0,235, 0x92,57, 0,14, 0x81, 0,232, 0x91,45, 0,15, 0x82, 0,232, 0x92,57, 0,15,
0x81, 0,232, 0x80, 0,2, 0x90,74, 0x91,44, 0,13, 0x82, 0,252, 0x92,56, 0,15, 0x81, 0,233, 0x91,44, 0,15,
0x82, 0,232, 0x92,56, 0,14, 0x81, 0,234, 0x80, 0,1, 0x90,71, 0x91,44, 0,14, 0x82, 0,235, 0x92,56, 0,14,
0x81, 0,232, 0x91,44, 0,15, 0x82, 0,232, 0x92,56, 0,15, 0x81, 0,232, 0x80, 0,2, 0x90,72, 0x91,45, 0,13,
0x82, 0,252, 0x92,57, 0,15, 0x81, 0,233, 0x80, 0x90,76, 0x91,45, 0,15, 0x82, 0,232, 0x92,57, 0,14, 0x81, 0,234,
0x80, 0,1, 0x90,81, 0x91,45, 0,14, 0x82, 0,235, 0x92,57, 0,14, 0x81, 0,232, 0x91,45, 0,15, 0x82, 0,232,
0x92,57, 0,15, 0x81, 0,232, 0x80, 0,2, 0x90,80, 0x91,44, 0,13, 0x82, 0,252, 0x92,56, 0,15, 0x81, 0,233,
0x91,44, 0,15, 0x82, 0,232, 0x92,56, 0,14, 0x81, 0,235, 0x91,44, 0,14, 0x82, 0,235, 0x92,56, 0,14, 0x81,
0,232, 0x91,44, 0,15, 0x82, 0,232, 0x92,56, 0,15, 0x81, 0,232, 0x80, 0,15, 0x82, 0xF0};
Playtune pt;
//#include "tetris.c"
#include <LiquidCrystal.h>
#define ligne_0 2
#define ligne_1 3
#define ligne_2 4
#define ligne_3 5
LiquidCrystal lcd(27, 28, 29, 30, 31, 32);
#define colonne_0 8
#define colonne_1 9
#define colonne_2 10
#define colonne_3 11
#define BoutonA 14
#define BoutonB 16
char test ="0";
int buzzer = 45;
int octave = 0;
int alteration = 0;
int rep1=0;
int rep2=0;
int rep3=0;
int rep4=0;
int rep5=0;
int rep6=0;
int rep7=0;
int rep8=0;
int rep9=0;
int rep10=0;
/*
void Do(int octave, int alteration){
if(octave == 0){ //octave de base
if( alteration == 0 ){ //bécarre
tone (7, 261.63, 20);
}
if( alteration == 1 ) { //dièse
tone (7, 277.18, 20);
}
if( alteration == -1 ) { //bémol
Si (-1, 0);
}
}
if(octave == -1){ //octave plus grave
if( alteration == 0 ){
tone (7, 130.81, 20);
}
if( alteration == 1 ) {
tone (7, 138.59, 20);
}
if( alteration == -1 ) {
tone (7, 123.47, 20);
}
}
if(octave == 1){ //octave plus aigue
if( alteration == 0 ){
tone (7, 523.25, 20);
}
if( alteration == 1 ) {
tone (7, 554.37, 20);
}
if( alteration == -1 ) {
Si (0, 0);
}
}
}
void Re (int octave, int alteration){
if(octave == 0){
if( alteration == 0 ){
tone (7, 293.66, 20);
}
if( alteration == 1 ) {
tone (7, 311.13, 20);
}
if( alteration == -1 ) {
Do (0,1);
}
}
if(octave == -1){
if( alteration == 0 ){
tone (7, 146.83, 20);
}
if( alteration == 1 ) {
tone (7, 155.56, 20);
}
if( alteration == -1 ) {
Do (-1,1);
}
}
if(octave == 1){
if( alteration == 0 ){
tone (7, 587.33, 20);
}
if( alteration == 1 ) {
tone (7, 622.25, 20);
}
if( alteration == -1 ) {
Do (1, 1);
}
}
}
void Mi(int octave, int alteration){
if(octave == 0){
if( alteration == 0 ){
tone (7, 329.63, 20);
}
if( alteration == 1 ) {
Fa(0,0);
}
if( alteration == -1 ) {
Re (0, 1);
}
}
if(octave == -1){
if( alteration == 0 ){
tone (7, 164.81, 20);
}
if( alteration == 1 ) {
Fa (-1, 0);
}
if( alteration == -1 ) {
Re(-1,1);
}
}
if(octave == 1){
if( alteration == 0 ){
tone (7, 659.26, 20);
}
if( alteration == 1 ) {
Fa (1,0);
}
if( alteration == -1 ) {
Re (1, 1);
}
}
}
void Fa(int octave, int alteration){
if(octave == 0){
if( alteration == 0 ){
tone (7, 349.23, 20);
}
if( alteration == 1 ) {
tone (7, 369.99,20);
}
if( alteration == -1 ) {
Mi (0, 0);
}
}
if(octave == -1){
if( alteration == 0 ){
tone (7, 174.61, 20);
}
if( alteration == 1 ) {
tone (7, 185, 20);
}
if( alteration == -1 ) {
Mi(-1, 0);
}
}
if(octave == 1){
if( alteration == 0 ){
tone (7, 698.46, 20);
}
if( alteration == 1 ) {
tone (7, 739.99, 20);
}
if( alteration == -1 ) {
Mi (1, 0);
}
}
}
void Sol (int octave, int alteration){
if(octave == 0){
if( alteration == 0 ){
tone (7, 392, 20);
}
if( alteration == 1 ) {
tone (7, 415.3, 20);
}
if( alteration == -1 ) {
Fa (0, 1);
}
}
if(octave == -1){
if( alteration == 0 ){
tone (7, 196, 20);
}
if( alteration == 1 ) {
tone (7, 207.65, 20);
}
if( alteration == -1 ) {
Fa (-1, 1);
}
}
if(octave == 1){
if( alteration == 0 ){
tone (7, 783.99, 20);
}
if( alteration == 1 ) {
tone (7, 830.61, 20);
}
if( alteration == -1 ) {
Fa (1, 1);
}
}
}
void La (int octave, int alteration){
if(octave == 0){
if( alteration == 0 ){
tone (7, 440, 20);
}
if( alteration == 1 ) {
tone (7, 466.16, 20);
}
if( alteration == -1 ) {
Sol (0, 1);
}
}
if(octave == -1){
if( alteration == 0 ){
tone (7, 220, 20);
}
if( alteration == 1 ) {
tone (7, 233.08, 20);
}
if( alteration == -1 ) {
Sol (-1, 1);
}
}
if(octave == 1){
if( alteration == 0 ){
tone (7, 880, 20);
}
if( alteration == 1 ) {
tone (7, 932.33, 20);
}
if( alteration == -1 ) {
Sol (1, 1);
}
}
}
void Si (int octave, int alteration){
if(octave == 0){
if( alteration == 0 ){
tone (7, 493.88, 20);
}
if( alteration == 1 ) {
Do (1,0);
}
if( alteration == -1 ) {
La (0, 1);
}
}
if(octave == -1){
if( alteration == 0 ){
tone (7, 246.94, 20);
}
if( alteration == 1 ) {
tone (7, 261.63, 20);
}
if( alteration == -1 ) {
La (-1, 1);
}
}
if(octave == 1){
if( alteration == 0 ){
tone (7, 987.77, 20);
}
if( alteration == 1 ) {
tone (7, 1046.5, 20);
}
if( alteration == -1 ) {
La (1, 1);
}
}
}*/
int x=0;
void setup() {
Serial.begin(9600);
pinMode(BoutonB, INPUT_PULLUP);
pinMode(BoutonA, INPUT_PULLUP);
pinMode(ligne_0, OUTPUT);
pinMode(ligne_1, OUTPUT);
pinMode(ligne_2, OUTPUT);
pinMode(ligne_3, OUTPUT);
pinMode(colonne_0, INPUT_PULLUP);
pinMode(colonne_1, INPUT_PULLUP);
pinMode(colonne_2, INPUT_PULLUP);
pinMode(colonne_3, INPUT_PULLUP);
const int pinBuzzer = 45;
lcd.begin(16, 2);
pt.tune_initchan (45);
pt.tune_initchan (46);
pt.tune_initchan (47);
#define DBUG 1
#if DBUG
Serial.begin(9600);
Serial.println("Debug");
#endif
}
void loop() {
int etat_colonne_0 = HIGH;
int etat_colonne_1 = HIGH;
int etat_colonne_2 = HIGH;
int etat_colonne_3 = HIGH;
digitalWrite(ligne_0, LOW);
digitalWrite(ligne_1, HIGH);
digitalWrite(ligne_2, HIGH);
digitalWrite(ligne_3, HIGH);
etat_colonne_0 = digitalRead(colonne_0);
etat_colonne_1 = digitalRead(colonne_1);
etat_colonne_2 = digitalRead(colonne_2);
etat_colonne_3 = digitalRead(colonne_3);
/*
// Si on a la colonne 0 à LOW, c'est que le bouton 1 est pressé
if(etat_colonne_0 == LOW) {
Do (octave, alteration);
}
if(etat_colonne_0 == LOW) {
while (rep1 == 0) {
lcd.clear();
lcd.print("Do");
rep1=1;
}
}
if(etat_colonne_0 == HIGH) {
rep1=0;
}
// Si on a la colonne 1 à LOW, c'est que le bouton 2 est pressé
if(etat_colonne_1 == LOW) {
Re (octave, alteration);
}
if(etat_colonne_1 == LOW) {
while (rep2 == 0) {
lcd.clear();
lcd.print("Re");
rep2=1;
}
}
if(etat_colonne_1 == HIGH) {
rep2=0;
}
// Si on a la colonne 2 à LOW, c'est que le bouton 3 est pressé
if(etat_colonne_2 == LOW) {
Mi (octave, alteration);
}
if(etat_colonne_2 == LOW) {
while (rep3 == 0) {
lcd.clear();
lcd.print("Mi");
rep3=1;
}
}
if(etat_colonne_2 == HIGH) {
rep3=0;
}
//Bouton A (octave grave)
if(etat_colonne_3 == LOW) {
octave=-1;
}
if(etat_colonne_3 == LOW) {
while (rep8 == 0) {
lcd.clear();
lcd.print("Octave grave");
rep8=1;
}
}
if(etat_colonne_3 == HIGH) {
rep8=0;
}
// On met la ligne 1 à 0V et les autres au 5V
digitalWrite(ligne_0, HIGH);
digitalWrite(ligne_1, LOW);
digitalWrite(ligne_2, HIGH);
digitalWrite(ligne_3, HIGH);
// On recupère l'état des colonnes
etat_colonne_0 = digitalRead(colonne_0);
etat_colonne_1 = digitalRead(colonne_1);
etat_colonne_2 = digitalRead(colonne_2);
etat_colonne_3 = digitalRead(colonne_3);
//bouton 4 (Fa)
if(etat_colonne_0 == LOW) {
Fa (octave, alteration);
}
if(etat_colonne_0 == LOW) {
while (rep4 == 0) {
lcd.clear();
lcd.print("Fa");
rep4=1;
}
}
if(etat_colonne_0 == HIGH) {
rep4=0;
}
//bouton 5 (sol)
if(etat_colonne_1 == LOW) {
Sol (octave, alteration);
}
if(etat_colonne_1 == LOW) {
while (rep5 == 0) {
lcd.clear();
lcd.print("Sol");
rep5=1;
}
}
if(etat_colonne_1 == HIGH) {
rep5=0;
}
//bouton 6 (la)
if(etat_colonne_2 == LOW) {
La (octave, alteration);
}
if(etat_colonne_2 == LOW) {
while (rep6 == 0) {
lcd.clear();
lcd.print("La");
rep6=1;
}
}
if(etat_colonne_2 == HIGH) {
rep6=0;
}
//bouton B (octave départ)
if(etat_colonne_3 == LOW) {
octave=0;
}
if(etat_colonne_3 == LOW) {
while (rep9 == 0) {
lcd.clear();
lcd.print("Octave de depart");
rep9=1;
}
}
if(etat_colonne_3 == HIGH) {
rep9=0;
}
// On met la ligne 2 à 0V et les autres au 5V
digitalWrite(ligne_0, HIGH);
digitalWrite(ligne_1, HIGH);
digitalWrite(ligne_2, LOW);
digitalWrite(ligne_3, HIGH);
// On recupère l'état des colonnes
etat_colonne_0 = digitalRead(colonne_0);
etat_colonne_1 = digitalRead(colonne_1);
etat_colonne_2 = digitalRead(colonne_2);
etat_colonne_3 = digitalRead(colonne_3);
//bouton 7 (si)
if(etat_colonne_0 == LOW) {
Si (octave, alteration);
}
if(etat_colonne_0 == LOW) {
while (rep7 == 0) {
lcd.clear();
lcd.print("Si");
rep7=1;
}
}
if(etat_colonne_0 == HIGH) {
rep7=0;
}
/* //bouton 8
if(etat_colonne_1 == LOW) {
Serial.println("Pause");
}*/
/* //bouton 9
if(etat_colonne_2 == LOW) {
Serial.println("Play");
}
//bouton C (octave aigue
if(etat_colonne_3 == LOW) {
octave=1;
}
if(etat_colonne_3 == LOW) {
while (rep10 == 0) {
lcd.clear();
lcd.print("Octave aigue");
rep10=1;
}
}
if(etat_colonne_3 == HIGH) {
rep10=0;
}
// On met la ligne 3 à 0V et les autres au 5V
digitalWrite(ligne_0, HIGH);
digitalWrite(ligne_1, HIGH);
digitalWrite(ligne_2, HIGH);
digitalWrite(ligne_3, LOW);
// On recupère l'état des colonnes
etat_colonne_0 = digitalRead(colonne_0);
etat_colonne_1 = digitalRead(colonne_1);
etat_colonne_2 = digitalRead(colonne_2);
etat_colonne_3 = digitalRead(colonne_3);
// Si on a la colonne 0 à LOW, c'est que le bouton * est pressé
if(etat_colonne_0 == LOW) {
Serial.println("Bémol");
alteration=-1;
}
// Si on a la colonne 1 à LOW, c'est que le bouton 0 est pressé
if(etat_colonne_1 == LOW) {
Serial.println("Bécarre");
alteration=0;
}
// Si on a la colonne 2 à LOW, c'est que le bouton # est pressé
if(etat_colonne_2 == LOW) {
Serial.println("Dièse");
alteration=1;
}
// Si on a la colonne 3 à LOW, c'est que le bouton D est pressé
if(etat_colonne_3 == LOW) {
Serial.println("//enregistrement");
}
*/
pt.tune_playscore (score); /* start playing */
while (pt.tune_playing) ; /* wait here until playing stops */
pt.tune_delay(1000);
}