#include <MD_MAX72xx.h>
//matrix controls
const byte data_pin = 11;
const byte chip_select_pin = 10;
const byte clock_pin = 13;
const byte max_devices = 4;
// creating matrix object
MD_MAX72XX matrix = MD_MAX72XX(MD_MAX72XX::PAROLA_HW, chip_select_pin, max_devices);
// define the joystick controls
const byte hpin = A1;
const byte vpin = A0;
int head_x = 0;
int head_y = 0;
int max_x = 31;
int max_y = 7;
String prev_dir = "";
String dir = "";
void setup()
{
Serial.begin(9600);
// delay(20);
matrix.begin();
matrix.clear();
matrix.setPoint(head_y , head_x , true);
// (right left ,up down, true--> pint visible, false --> no visible)
}
void loop()
{
checkDirection();
moveSprite();
matrix.setPoint(head_y , head_x , true);
// (right left ,up down, true--> pint visible, false --> no visible)
//////DONT ADD FIRST, RUN WITHOUT< SHOES IS VERY FAST< THERFORE WE ADD////////////
delay(200);
/////////////////////////////////////////////////////////////////////////////////
}
void checkDirection()
{
if (analogRead(hpin) > 512)
dir = "Left";
else if (analogRead(hpin) < 512)
dir = "Right";
if (analogRead(vpin) > 512)
dir = "Up";
else if (analogRead(vpin) < 512)
dir = "Down";
}
void moveSprite()
{
if (dir == "Left" )
{
head_x += 1;
}
else if (dir == "Right" )
{
head_x -= 1;
}
else if (dir == "Up" )
{
head_y -= 1;// has been switched wantedly, only then sprite is moving according tot the joystick
}
else if (dir == "Down" )
{
head_y += 1;// has been switched wantedly, only then sprite is moving according tot the joystick
}
}