#include <Streaming.h>
#include "AbstractJoystick.h"
//#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
// Uncomment according to your hardware type.
// #define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 1
#define CLK_PIN 18 // or SCK
#define DATA_PIN 23 // or MOSI
#define CS_PIN 5 // or SS
#define HARDWARE_TYPE MD_MAX72XX::GENERIC_HW
#define DELAYTIME 300
// SPI hardware interface
//MD_MAX72XX mx = MD_MAX72XX(CS_PIN, MAX_DEVICES);
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary pins
//MD_MAX72XX mx = MD_MAX72XX(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
class Joystick: public AbstractJoystick {
public:
Joystick(int pinx, int piny, int pinz): AbstractJoystick(pinx, piny, pinz) {
}
void onClick() {
Serial.println("click");
}
void onMoveHorizontal(int xValue) {
Serial << "X = " << xValue << endl;
}
void onMoveVertical(int yValue) {
Serial << "Y = " << yValue << endl;
}
};
Joystick joystick(4, 2, 15);
void zeroPointSet()
// Demonstrates the use of setPoint and
// show where the zero point is in the display
{
mx.clear();
for (uint8_t i=0; i<7; i++)
{
mx.setPoint(i, i, true);
mx.setPoint(0, i, true);
mx.setPoint(i, 0, true);
delay(DELAYTIME);
}
delay(DELAYTIME);
}
const int pinX = 4; // P0 (GPIO00 - ADC11)
const int pinY = 2; // P2 (GPIO02 - ADC12)
const int pinSW = 15; // P15 (GPIO15)
int valueX = 0; // Analog
int valueY = 0; // Analog
int valueZ = 0; // Digital
void setup() {
Serial.begin(9600);
joystick.setup();
}
void loop() {
// Simplest raw code for reading joystick input - Joysick class aims to replace it
// Default mode x=2048, y=2048, z=0
// When moved only to: top => y=4095, right => y=0
// When moved only to: left => y=0, right => y=4095
// When clicked z=1
// valueX = analogRead(pinX);
// valueY = analogRead(pinY);
// valueZ = digitalRead(pinSW);
// Serial << "x: " << valueX << ", y: " << valueY << ", z(button): " << valueZ << endl;
// Turns on the LED Matrix on all panels.
Serial.println("ZeroPointSet");
zeroPointSet();
delay(500);
// Turns off the LED Matrix on all panels.
joystick.loop();
delay(100);
}