#include "LedControl.h"
#define tiltPin 2
int len = 20;
int d[] = {50,50,50,50,50,50,100,100,100,100,200,200,200,200,300,300,400,400,400,700};
int a;
int b;
int freq = 600;
LedControl lc=LedControl(12,10,11,1);
void setup() {
lc.shutdown(0,false);
lc.setIntensity(0,8);
lc.clearDisplay(0);
pinMode(2,INPUT);
digitalWrite(2, HIGH);
}
void writeUno() {
byte a[8]={B00000000,B00000000,B00000000,B00000100,B00111110,B00000000,B00000000,B00000000};
lc.setRow(0,0,a[0]);
lc.setRow(0,1,a[1]);
lc.setRow(0,2,a[2]);
lc.setRow(0,3,a[3]);
lc.setRow(0,4,a[4]);
lc.setRow(0,5,a[5]);
lc.setRow(0,6,a[6]);
lc.setRow(0,7,a[7]);
}
void writeDue() {
byte a[8]={B00000000,B00000000,B00111010,B00101010,B00101110,B00000000,B00000000,B00000000};
lc.setRow(0,0,a[0]);
lc.setRow(0,1,a[1]);
lc.setRow(0,2,a[2]);
lc.setRow(0,3,a[3]);
lc.setRow(0,4,a[4]);
lc.setRow(0,5,a[5]);
lc.setRow(0,6,a[6]);
lc.setRow(0,7,a[7]);
}
void writeTre() {
byte a[8]={B00000000,B00000000,B00101010,B00101010,B00111110,B00000000,B00000000,B00000000};
lc.setRow(0,0,a[0]);
lc.setRow(0,1,a[1]);
lc.setRow(0,2,a[2]);
lc.setRow(0,3,a[3]);
lc.setRow(0,4,a[4]);
lc.setRow(0,5,a[5]);
lc.setRow(0,6,a[6]);
lc.setRow(0,7,a[7]);
}
void writeQuattro() {
byte a[8]={B00000000,B00000000,B00001110,B00001000,B00111110,B00000000,B00000000,B00000000};
lc.setRow(0,0,a[0]);
lc.setRow(0,1,a[1]);
lc.setRow(0,2,a[2]);
lc.setRow(0,3,a[3]);
lc.setRow(0,4,a[4]);
lc.setRow(0,5,a[5]);
lc.setRow(0,6,a[6]);
lc.setRow(0,7,a[7]);
}
void writeCinque() {
byte a[8]={B00000000,B00000000,B00101110,B00101010,B00111010,B00000000,B00000000,B00000000};
lc.setRow(0,0,a[0]);
lc.setRow(0,1,a[1]);
lc.setRow(0,2,a[2]);
lc.setRow(0,3,a[3]);
lc.setRow(0,4,a[4]);
lc.setRow(0,5,a[5]);
lc.setRow(0,6,a[6]);
lc.setRow(0,7,a[7]);
}
void writeSei() {
byte a[8]={B00000000,B00000000,B00111110,B00101010,B00111010,B00000000,B00000000,B00000000};
lc.setRow(0,0,a[0]);
lc.setRow(0,1,a[1]);
lc.setRow(0,2,a[2]);
lc.setRow(0,3,a[3]);
lc.setRow(0,4,a[4]);
lc.setRow(0,5,a[5]);
lc.setRow(0,6,a[6]);
lc.setRow(0,7,a[7]);
}
void loop() {
lc.clearDisplay(0);
if (digitalRead(tiltPin) == 1) { // tilt
for (int i=0; i<len; i=i+1) {
a = random(1,6);
while (a == b) { a = random(1,6); }
if(a == 1) { writeUno(); }
if(a == 2) { writeDue(); }
if(a == 3) { writeTre(); }
if(a == 4) { writeQuattro(); }
if(a == 5) { writeCinque(); }
if(a == 6) { writeSei(); }
b = a;
tone(7, 1660, 50);
delay(d[i]);
}
if (a==6) { // musichetta trionfale
tone(7, freq, 200);
delay(300);
tone(7, freq, 100);
delay(150);
tone(7, freq, 100);
delay(150);
tone(7, freq, 900);
}
delay(1000);
}
delay(200);
}
Commenti