#include <MD_MAX72xx.h>
#define TasteLinks 12
#define TasteRechts 14
#define LED_PIN 23
#define dataPin 2
#define clkPin 0
#define csPin 4
#define mod GENERIC_HW
MD_MAX72XX mx = MD_MAX72XX (MD_MAX72XX::mod, dataPin, clkPin, csPin, 1);
char Richtung;
int x=4, y=4;
void setup() {
// put your setup code here, to run once:
pinMode(dataPin, OUTPUT);
pinMode(clkPin, OUTPUT);
pinMode(csPin, OUTPUT);
mx.begin();
pinMode(LED_PIN, OUTPUT);
pinMode(TasteLinks, INPUT_PULLUP);
pinMode(TasteRechts, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(TasteLinks), RichtungLinks, FALLING);
attachInterrupt(digitalPinToInterrupt(TasteRechts), RichtungRechts, FALLING);
// Funktion zur Konfiguration des externen Interrupts
// 3 Übergabeparameter
// 1) welcher Pin wird verwendet, 2) ISR Funktion die ausgeführt werden soll
// 3) welches elektrische Signal - Flanke
}
void pixel_links_recht_oben_unten (void) ;
void RichtungLinks () {
Richtung='W';
}
void RichtungRechts () {
Richtung='E';
}
void loop() {
// put your main code here, to run repeatedly:
if (Richtung == 'W') {
digitalWrite(LED_PIN, HIGH);
mx.setPoint (x, y, 0);
}
else {
digitalWrite(LED_PIN, LOW);
mx.setPoint (x, y, 1);
}
delay(10); // this speeds up the simulation
}
void pixel_links_recht_oben_unten (void) {
mx.setPoint (x, y, 0);
if (Richtung == 'N'){
x++;
if (x>8) {
x=8;
}
}
if (Richtung == 'E'){
x--;
if (x<0) {
x=0;
}
}
if (Richtung == 'S'){
y++;
if (y>8) {
y=8;
}
}
if (Richtung == 'W'){
y--;
if (y<0) {
y=0;
}
}
mx.setPoint (x, y, 1);
delay(100);
}