#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;
const byte vpin = A0;
const byte hpin = A1;
int head_y = 0;
int head_x = 0;
String direction="",prev_direction="";
int max_x = 31, max_y = 7;
// creating matrix object
MD_MAX72XX matrix = MD_MAX72XX(MD_MAX72XX::PAROLA_HW, chip_select_pin, max_devices);
// define the joystick controls
void setup(){
Serial.begin(9600);
delay(25);
matrix.begin();
matrix.clear();
matrix.setPoint(head_y, head_x, true)
}
void loop(){
//Serial.print(analogRead(hpin));
//Serial.print('\t');
//Serial.println(analogRead(vpin));
check_direction();
move_sprite();
matrix.setPoint(head_y, head_x, true)
}
void check_direction(){
if(analogRead(hpin)>512)
direction = "left";
else if (analogRead(hpin)<512)
direction = "right";
else if (analogRead(vpin)>512)
direction = "up";
else if (analogRead(vpin)<512)
direction = "down";
}
void move_sprite(){
if(direction == "left") head_x++;
else if (direction == "right") head_x--;
else if (direction == "up") head_y--;
else if (direction == "down") head_y++;
}