#include "LedControl.h"
#include "SR04.h"
#define buzzPin 7
#define TRIG_PIN 8
#define ECHO_PIN 9
SR04 sr04 = SR04(ECHO_PIN,TRIG_PIN);
LedControl lc=LedControl(12,10,11,1);
long a;
long f;
void setup() {
lc.shutdown(0,false);
lc.setIntensity(0,8);
lc.clearDisplay(0);
}
void writeCuoreSmall() {
byte a[8]={B00000000,B00001100,B00010100,B00101000,B00101000,B00010100,B00001100,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 writeCuoreBig() {
byte a[8]={B00011110,B00100010,B01000010,B10000100,B10000100,B01000010,B00100010,B00011110};
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() {
a = sr04.Distance();
// scegli la frequenza del LA in base alla distanza
if (a<7) { f= 4; }
if (a>6 && a<13) { f= 3; }
if (a>12 && a<22) { f= 2; }
if (a>21 && a<61) { f= 1; }
if(a<60 && a>2) {
if(a<30) {
writeCuoreBig();
tone(buzzPin, f*220, a*10);
delay(a*10);
writeCuoreSmall();
delay(a*10);
} else {
writeCuoreBig();
delay(500);
}
} else {
writeCuoreBig();
delay(100);
}
}
Commenti