#include <LedControl.h>
#include <Servo.h>
#include <data.h>
LedControl lc = LedControl(12, 11, 10, 4);
const byte botao1 = 2;
const byte botao2 = 3;
const int pinoServo = 7; //PINO DIGITAL UTILIZADO PELO SERVO
Servo s;
volatile boolean HeadCenter = false;
volatile byte counter1 = 0;
volatile byte counter2 = 0;
boolean blockA = true;
boolean blockB = true;
void setup() {
s.attach(pinoServo);
s.write(0);
pinMode(botao1, INPUT); //configura entrada digital para o sensor
pinMode(botao2, INPUT); //configura entrada digital para o sensor
lc.shutdown(0, false);
lc.setIntensity(0, 6);
lc.clearDisplay(0);
attachInterrupt(0, extInt, RISING);
attachInterrupt(1, extInt2, RISING);
}
void loop() {
EyeLeft(evilLeft);
EyeRight(evilRight);
delay(6000);
EyeLeft(eyeClose);
EyeRight(eyeClose);
delay(80);
Head0();
}
void Head0()
{
if (HeadCenter) {
s.write(0);
HeadCenter = false;
}
}
void EyeLeft(byte eye_left[])
{
for (int i = 0; i < 8; i++)
{
lc.setRow(0, i, eye_left[i]);
}
}
void EyeRight(byte eye_right[])
{
for (int i = 0; i < 8; i++)
{
lc.setRow(1, i, eye_right[i]);
}
}
void extInt() {
counter1++;
if (counter1 < 3)
{
EyeLeft(eyeToRight);
EyeRight(eyeToRight);
s.write(180);
HeadCenter = true;
}
else
{
EyeLeft(evilLeft);
EyeRight(evilRight);
s.write(180);
HeadCenter = true;
counter1 = 0;
}
}
void extInt2() {
counter2++;
if (counter2 < 3)
{
EyeLeft(eyeToLeft);
EyeRight(eyeToLeft);
s.write(90);
HeadCenter = true;
}
else
{
EyeLeft(evilLeft);
EyeRight(evilRight);
s.write(90);
HeadCenter = true;
counter2 = 0;
}
}