#include "LedControl.h"
#include "Servo.h"
//matrice LED
LedControl lc=LedControl(12,10,11,1);
byte ospedale[8] = {0b11000011,0b11000011,0b11000011,0b11111111,0b11111111,0b11000011,0b11000011,0b11000011};
byte cuore[8] = {0b00000000,0b01100110,0b11111111,0b11111111,0b01111110,0b00111100,0b00011000,0b00000000};
byte peso[8]={0b00000000,0b00000000,0b11100111,0b11111111,0b11111111,0b11100111,0b00000000,0b00000000};
byte busta[8]={0b00011000,0b00100100,0b01000010,0b01000010,0b11111111,0b11111111,0b11111111,0b01111110};
byte bicchiere[8]={0b11111111,0b01111110,0b00111100,0b00011000,0b00011000,0b00011000,0b00011000,0b01111110};
byte conferma[8]={0b00000000,0b10010111,0b01010101,0b00110101,0b00110101,0b01010101,0b10010111,0b00000000};
//potenziometro
int potenziometro=A0;
//servomotore
Servo servo;
int angle = -90;
int pos;
//pulsante
int pulsante1 =7;
int pulsante2 =2;
int pulsante3 = 4;
int stato_pulsante1;
int stato_pulsante2;
int stato_pulsante3;
//contatore
int count=0;
int count2=0;
void setup() {
lc.shutdown(0, false); //posizioni della matrice a 0
lc.setIntensity(0, 0); //si regola l'intensità dei led della matrice
lc.clearDisplay(0); //la matrice parte con tutti i led spenti
pinMode(potenziometro, INPUT);
pinMode(ospedale, OUTPUT);
//servomotore
servo.attach(6);
servo.write(angle); //posiziono il servo
//delay(1000);
//pulsanti
pinMode(pulsante1, INPUT_PULLUP);
pinMode(pulsante2, INPUT_PULLUP);
pinMode(pulsante3, INPUT_PULLUP);
}
void loop() {
int value=analogRead(potenziometro);
analogWrite(ospedale,value);
stato_pulsante1 = digitalRead(pulsante1);
stato_pulsante2 = digitalRead(pulsante2);
stato_pulsante3 = digitalRead(pulsante3);
if(stato_pulsante1 == 0)
{ servo.write(180);
}
if(stato_pulsante2 ==0)
{
count=1;
}
if (count==1)
{
if (value>0&value<=205)
{ for (int row = 0; row < 8; row++)
lc.setRow(0, row, ospedale[row]);
}
if (value>205&value<=410)
{ for (int row = 0; row < 8; row++)
lc.setRow(0, row, cuore[row]);
}
if (value>410&value<=615)
{ for (int row = 0; row < 8; row++)
lc.setRow(0, row, peso[row]);
}
if (value>615&value<=820)
{ for (int row = 0; row < 8; row++)
lc.setRow(0, row, busta[row]);
}
if (value>820&value<=1024)
{for (int row = 0; row < 8; row++)
lc.setRow(0, row, bicchiere[row]);
}
}
if(stato_pulsante3 ==0)
{
lc.clearDisplay(0);
count2=1;
}
if (count2==1)
{
if (value>=0 && value<=1000)
{
for (int row = 0; row < 8; row++)
lc.setRow(0, row, conferma[row]);
}
count=2;
}
}
//else
//{
// lc.clearDisplay(0);
//}