// Demonstrates reversed text (as if on front of an ambulance)
//
// MD_MAX72XX library can be found at https://github.com/MajicDesigns/MD_MAX72XX
//
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
Adafruit_MPU6050 mpu;
// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 8
#define PAUSE_TIME 1000
#define SCROLL_SPEED 50
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
float x1;
float y1;
float z1;
// HARDWARE SPI
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// SOFTWARE SPI
//MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
const char *msg1[] =
{
"gnivom ton",
};
const char *msg2[] =
{
"forward"
};
const char *msg3[] =
{
" backward",
};
const char *msg4[] =
{
" right",
};
const char *msg5[] =
{
" left ",
};
const char *msg6[] =
{
" ↑",
};
const char *msg7[] =
{
" inward",
};
void setup(void)
{ Serial.begin(115200);
while (!mpu.begin()) {
Serial.println("MPU6050 not connected!");
delay(1000);
}
Serial.println("MPU6050 ready!");
// initialise the LED display
P.begin();
P.setZoneEffect(0, true, PA_FLIP_LR);
}
sensors_event_t event;
void loop(void)
{ mpu.getAccelerometerSensor()->getEvent(&event);
x1=event.acceleration.x;
y1=event.acceleration.y;
z1=event.acceleration.z;
Serial.print("x");
Serial.println(x1);
Serial.print("y");
Serial.println(y1);
Serial.print("z");
Serial.println(z1);
↑
static uint8_t cycle = 0;
if (P.displayAnimate() )
{ if (x1==0 && y1==0 && z1==0)
{
// set up the string
P.displayText(msg1[cycle], PA_CENTER, SCROLL_SPEED, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);
// prepare for next pass
cycle = (cycle + 1) % ARRAY_SIZE(msg1);
}
else if(x1>0)
{ P.displayText(msg2[cycle],PA_CENTER, SCROLL_SPEED,PAUSE_TIME,PA_PRINT,PA_NO_EFFECT);
cycle=(cycle+1)% ARRAY_SIZE(msg2);}
else if(x1<0)
{ P.displayText(msg3[cycle],PA_CENTER, SCROLL_SPEED,PAUSE_TIME,PA_PRINT,PA_NO_EFFECT);
cycle=(cycle+1)% ARRAY_SIZE(msg3);}
else if(y1>0)
{ P.displayText(msg4[cycle],PA_CENTER, SCROLL_SPEED,PAUSE_TIME,PA_PRINT,PA_NO_EFFECT);
cycle=(cycle+1)% ARRAY_SIZE(msg4);}
else if(y1<0)
{ P.displayText(msg5[cycle],PA_CENTER, SCROLL_SPEED,PAUSE_TIME,PA_PRINT,PA_NO_EFFECT);
cycle=(cycle+1)% ARRAY_SIZE(msg5);}
else if(z1>0)
{ P.displayText(msg6[cycle],PA_CENTER, SCROLL_SPEED,PAUSE_TIME,PA_PRINT,PA_NO_EFFECT);
cycle=(cycle+1)% ARRAY_SIZE(msg6);}
else if(z1<0)
{ P.displayText(msg7[cycle],PA_CENTER, SCROLL_SPEED,PAUSE_TIME,PA_PRINT,PA_NO_EFFECT);
cycle=(cycle+1)% ARRAY_SIZE(msg7);}
}}