Why do you need a copy of sensorTriggered? I might have missed something... asking so I understand your thoughts.
Yeah I guess there's no need to have a copy but wont it work the same as I presented??
Lets say that I dont use the copy of strongMagneticField, then this part of could should be:
if (!strongMagneticField) {
unsigned long currentMillis = millis();
if (currentMillis - lastAnimationUpdate >= tiltAnimationDelay) {
lastAnimationUpdate = currentMillis;
like this:
if (!sensorTriggered) {
unsigned long currentMillis = millis();
if (currentMillis - lastAnimationUpdate >= tiltAnimationDelay) {
lastAnimationUpdate = currentMillis;
Am I right??
"sensorTriggered" is cleared the very next loop after "STOP" is displayed.
If you want STOP to be displayed for a length of time during sensorTriggered and when sensorTriggered has gone away, you should set a flag inside a "millis()" timer (similar to the timer you show in Post #67)... and when the timer is finished, the flag is cleared... this lets you display STOP only when the flag is set.
like this??
unsigned long stopMessageTimer = 0; // Timer for displaying STOP message
bool displayStop = false; // Flag to indicate whether to display STOP message
void loop
if (sensorTriggered) {
if (!displayStop) {
stopMessageTimer = millis(); // Start the timer
displayStop = true; // Set the flag
displayStopMessage(); // Display STOP message
}
sensorTriggered = false;
} else {
myDisplay.displayReset();
}
// Check if the timer has expired and clear the flag
if (displayStop && millis() - stopMessageTimer >= stopMessageDuration) {
displayStop = false; // Clear the flag
}
correct me if I'm wrong I'm always open to learn new more things
You should test your code as you work on it. Does it work?
before I test it should I incorporate other temporary changes in the code even though its not finalize yet??
I like to test parts until the parts work, then add parts.
Okay Ill try and update whether it works or not thank you again
You will make it work.
After running this code, I receive several errors
in this code the stopMessageDuration is not defined so what I did was I change this:
Into this
if (displayStop && millis() - stopMessageTimer >= scrollDelay) {
And of course I need to define the value of stopMessageDuration or else it would give me an error. So I end up with this
const unsigned long stopMessageDuration = 5000; // Adjust the duration as needed
void loop() {
int16_t ax, ay, az;
mpu.getAcceleration(&ax, &ay, &az);
displayAcceleration(ax, ay, az);
// Check for strong magnetic field
bool strongMagneticField = sensorTriggered; // Base on this sensorTriggered function will still apply even if it is named strongMagneticField
if (strongMagneticField) { // If sensorTriggered is display at the serial monitor, it will display the stop message
if (!displayStop) {
stopMessageTimer = millis(); // Start the timer
displayStop = true; // Set the flag
displayStopMessage(); // Display STOP message
}
sensorTriggered = false; // Reset the flag after displaying the message
} else {
myDisplay.displayReset();
}
// Check if the timer has expired and clear the flag
if (displayStop && millis() - stopMessageTimer >= stopMessageDuration) {
displayStop = false; // Clear the flag
}
// Execute tilt animation if strong magnetic field is NOT detected
if (!strongMagneticField) {
unsigned long currentMillis = millis();
if (currentMillis - lastAnimationUpdate >= tiltAnimationDelay) {
lastAnimationUpdate = currentMillis;
if (ax > 4000) {
tiltRightAnimation_OneStep();
} else if (ax < -4000) {
tiltLeftAnimation_OneStep();
}
}
}
}
Feel free to check my work its the best thing you could help me to make this project of ours complete
Hey just an quick update, I tried running it at the arduino and the only thing happened is it lights up for a brief second and it clear the display again
post the complete actual sketch. If you ony post parts of the code it can't be really checked if it will work.
You seem to have not always access to your hardware.
You should set up a wokwi-simulation of your project.
In the time where you have no access to the hardware use the simulation.
Instead of a hall-sensor use a simple slider-switch
As of now, I have 2 separate codes
This is for the whole code, this is the complete code when it is done
#include <Wire.h>
#include <MPU6050.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <LedControl.h>
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 4
#define CS_PIN 53
#define DATA_PIN 51
#define CLK_PIN 52
#define HALL_SENSOR_PIN 2
MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
MPU6050 mpu;
LedControl lc = LedControl(51, 52, 53, 4); // Pins: DIN, CLK, CS, # of Displays connected
volatile bool sensorTriggered = false; // Use volatile for interrupt safety
const unsigned long stopMessageDuration = 5000; // Adjust the duration as needed
unsigned long stopMessageTimer = 0; // Timer for displaying STOP message
bool displayStop = false; // Flag to indicate whether to display STOP message
unsigned long lastAnimationUpdate = 0;
unsigned long scrollTimer = 0; // Timer for scrolling message delay
const unsigned long tiltAnimationDelay = 200; // Delay between tilt animation frames
const unsigned long scrollDelay = 20; // Delay for scrolling message
// Put values in arrays
byte invader1a[] =
{
B00010010, // First frame of invader #1
B00100100,
B01001001,
B10010010,
B10010010,
B01001001,
B00100100,
B00010010};
byte invader1b[] =
{
B00000000, // Second frame of invader #1
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000};
byte invader2a[] =
{
B00010010, // First frame of invader #1
B00100100,
B01001001,
B10010010,
B10010010,
B01001001,
B00100100,
B00010010};
byte invader2b[] =
{
B00000000, // Second frame of invader #2 (flipped horizontally)
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000};
byte invader3a[] =
{
B00010010, // First frame of invader #1
B00100100,
B01001001,
B10010010,
B10010010,
B01001001,
B00100100,
B00010010};
byte invader3b[] =
{
B00000000, // First frame of invader #2 (flipped horizontally)
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000};
byte invader4a[] =
{
B00010010, // First frame of invader #1
B00100100,
B01001001,
B10010010,
B10010010,
B01001001,
B00100100,
B00010010};
byte invader4b[] =
{
B00000000, // Second frame of invader #2
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000};
// Put values in arrays
byte invader1c[] =
{
B01001000, // First frame of invader #1
B00100100,
B10010010,
B01001001,
B01001001,
B10010010,
B00100100,
B01001000};
byte invader1d[] =
{
B00000000, // Second frame of invader #1
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000};
byte invader2c[] =
{
B01001000, // First frame of invader #1
B00100100,
B10010010,
B01001001,
B01001001,
B10010010,
B00100100,
B01001000};
byte invader2d[] =
{
B00000000, // Second frame of invader #2 (flipped horizontally)
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000};
byte invader3c[] =
{
B01001000, // First frame of invader #1
B00100100,
B10010010,
B01001001,
B01001001,
B10010010,
B00100100,
B01001000};
byte invader3d[] =
{
B00000000, // First frame of invader #2 (flipped horizontally)
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000
};
byte invader4c[] =
{
B01001000, // First frame of invader #1
B00100100,
B10010010,
B01001001,
B01001001,
B10010010,
B00100100,
B01001000};
byte invader4d[] =
{
B00000000, // Second frame of invader #2
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000};
void setup() {
Serial.begin(115200);
Wire.begin();
mpu.initialize();
SPI.begin(); // Initialize SPI
lc.shutdown(0, false); // Wake up displays
lc.shutdown(1, false);
lc.shutdown(2, false);
lc.shutdown(3, false);
lc.setIntensity(0, 15); // Set intensity levels
lc.setIntensity(1, 15);
lc.setIntensity(2, 15);
lc.setIntensity(3, 15);
lc.clearDisplay(0); // Clear Displays
lc.clearDisplay(1);
lc.clearDisplay(2);
lc.clearDisplay(3);
myDisplay.begin();
myDisplay.setIntensity(8);
myDisplay.displayClear();
pinMode(HALL_SENSOR_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(HALL_SENSOR_PIN), sensorInterrupt, CHANGE); // Attach interrupt on CHANGE
scrollTimer = millis(); // Initialize the scroll timer
}
void sensorInterrupt() {
sensorTriggered = !digitalRead(HALL_SENSOR_PIN); // Read the sensor state in the interrupt
}
void displayAcceleration(int16_t ax, int16_t ay, int16_t az) {
// Print the X, Y, and Z values to the serial monitor
Serial.print("X: ");
Serial.print(ax);
Serial.print(" | Y: ");
Serial.print(ay);
Serial.print(" | Z: ");
Serial.print(az);
Serial.print(" | H: ");
Serial.println(sensorTriggered);
}
void tiltRightAnimation_OneStep() {
static int frameIndex = 0; // Static variable to keep track of frame index
// Define the array of animation frames
byte* frames[] = {invader1a, invader2a, invader3a, invader4a, invader1b, invader2b, invader3b, invader4b};
// Display the current frame
for (int i = 0; i < 8; i++) {
lc.setRow(frameIndex / 2, i, frames[frameIndex][i]);
}
// Increment frame index
frameIndex++;
if (frameIndex >= 8) {
frameIndex = 0; // Reset frame index if it exceeds the number of frames
}
}
void tiltLeftAnimation_OneStep() {
static int frameIndex = 0; // Static variable to keep track of frame index
// Define the array of animation frames
byte* frames[] = {invader4c, invader3c, invader2c, invader1c, invader4d, invader3d, invader2d, invader1d};
// Display the current frame
for (int i = 0; i < 8; i++) {
lc.setRow(frameIndex / 2, i, frames[frameIndex][i]);
}
// Increment frame index
frameIndex++;
if (frameIndex >= 8) {
frameIndex = 0; // Reset frame index if it exceeds the number of frames
}
}
void displayStopMessage() {
unsigned long currentMillis = millis();
if (currentMillis - scrollTimer >= scrollDelay) {
scrollTimer = currentMillis; // Update the scroll timer
if (myDisplay.displayAnimate()) {
myDisplay.displayReset();
myDisplay.setTextAlignment(PA_CENTER);
myDisplay.setSpeed(30);
myDisplay.displayScroll("STOP STOP STOP STOP ", PA_CENTER, PA_SCROLL_LEFT, 20);
}
}
}
void loop() {
int16_t ax, ay, az;
mpu.getAcceleration(&ax, &ay, &az);
displayAcceleration(ax, ay, az);
// Check for strong magnetic field
bool strongMagneticField = sensorTriggered; // Base on this sensorTriggered function will still apply even if it is named strongMagneticField
if (strongMagneticField) { // If sensorTriggered is display at the serial monitor, it will display the stop message
if (!displayStop) {
stopMessageTimer = millis(); // Start the timer
displayStop = true; // Set the flag
displayStopMessage(); // Display STOP message
}
sensorTriggered = false; // Reset the flag after displaying the message
} else {
myDisplay.displayReset();
}
// Check if the timer has expired and clear the flag
if (displayStop && millis() - stopMessageTimer >= stopMessageDuration) {
displayStop = false; // Clear the flag
}
// Execute tilt animation if strong magnetic field is NOT detected
if (!strongMagneticField) {
unsigned long currentMillis = millis();
if (currentMillis - lastAnimationUpdate >= tiltAnimationDelay) {
lastAnimationUpdate = currentMillis;
if (ax > 4000) {
tiltRightAnimation_OneStep();
} else if (ax < -4000) {
tiltLeftAnimation_OneStep();
}
}
}
}
This another one is the sketch I use to do my own attempts this currently has the "without for-loop function I still don't corporate them to avoid further confusions and I might
type or paste code here#include <Wire.h>
#include <MPU6050.h>
#include <LedControl.h>
unsigned long lastAnimationUpdate = 0;
const unsigned long tiltAnimationDelay = 200; // Delay between tilt animation frames
// Bytes for the Left arrow animation
byte invader1c[] =
{
B01001000, // First frame of invader #1
B00100100,
B10010010,
B01001001,
B01001001,
B10010010,
B00100100,
B01001000};
byte invader1d[] =
{
B00000000, // Second frame of invader #1
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000};
byte invader2c[] =
{
B01001000, // First frame of invader #1
B00100100,
B10010010,
B01001001,
B01001001,
B10010010,
B00100100,
B01001000};
byte invader2d[] =
{
B00000000, // Second frame of invader #2 (flipped horizontally)
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000};
byte invader3c[] =
{
B01001000, // First frame of invader #1
B00100100,
B10010010,
B01001001,
B01001001,
B10010010,
B00100100,
B01001000};
byte invader3d[] =
{
B00000000, // First frame of invader #2 (flipped horizontally)
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000
};
byte invader4c[] =
{
B01001000, // First frame of invader #1
B00100100,
B10010010,
B01001001,
B01001001,
B10010010,
B00100100,
B01001000};
byte invader4d[] =
{
B00000000, // Second frame of invader #2
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000};
void setup() {
Serial.begin(115200);
Wire.begin();
mpu.initialize();
SPI.begin(); // Initialize SPI
lc.shutdown(0, false); // Wake up displays
lc.shutdown(1, false);
lc.shutdown(2, false);
lc.shutdown(3, false);
lc.setIntensity(0, 15); // Set intensity levels
lc.setIntensity(1, 15);
lc.setIntensity(2, 15);
lc.setIntensity(3, 15);
lc.clearDisplay(0); // Clear Displays
lc.clearDisplay(1);
lc.clearDisplay(2);
lc.clearDisplay(3);
myDisplay.begin();
myDisplay.setIntensity(8);
myDisplay.displayClear();
}
// Bytes function
void do_ONE_Step_lefttiltAnimation() {
sinvader4c();
tiltAnimationTimer = millis() + tiltAnimationDelay; // Set timer for next frame
sinvader3c();
tiltAnimationTimer = millis() + tiltAnimationDelay; // Set timer for next frame
sinvader2c();
tiltAnimationTimer = millis() + tiltAnimationDelay; // Set timer for next frame
sinvader1c();
tiltAnimationTimer = millis() + tiltAnimationDelay; // Set timer for next frame
sinvader4d();
tiltAnimationTimer = millis() + tiltAnimationDelay; // Set timer for next frame
sinvader3d();
tiltAnimationTimer = millis() + tiltAnimationDelay; // Set timer for next frame
sinvader2d();
tiltAnimationTimer = millis() + tiltAnimationDelay; // Set timer for next frame
sinvader1d();
tiltAnimationTimer = 0; // Reset timer after animation is complete
}
// Loop the function so it will always display the left animation when it reaches the certain value
void loop() {
int16_t ax, ay, az;
mpu.getAcceleration(&ax, &ay, &az); // measure the value of the accelerometer to make it display the left turn animation
displayAcceleration(ax, ay, az);
// Detect tilt direction and run appropriate animation
if (ax > 5000) {
do_ONE_Step_lefttiltAnimation();
}
}
// Define every byte to prevent error
void sinvader4c()
{
int i = 0; // Start with i = 0
lc.setRow(0, i, invader4c[i]); // Execute with i = 0
i++; // Increment i to 1
lc.setRow(0, i, invader4c[i]); // Execute with i = 1
i++; // Increment i to 2
lc.setRow(0, i, invader4c[i]); // Execute with i = 2
i++; // Increment i to 3
lc.setRow(0, i, invader4c[i]); // Execute with i = 3
i++; // Increment i to 4
lc.setRow(0, i, invader4c[i]); // Execute with i = 4
i++; // Increment i to 5
lc.setRow(0, i, invader4c[i]); // Execute with i = 5
i++; // Increment i to 6
lc.setRow(0, i, invader4c[i]); // Execute with i = 6
i++; // Increment i to 7
lc.setRow(0, i, invader4c[i]); // Execute with i = 7
}
void sinvader3c()
{
int i = 0; // Start with i = 0
lc.setRow(0, i, invader3c[i]); // Execute with i = 0
i++; // Increment i to 1
lc.setRow(0, i, invader3c[i]); // Execute with i = 1
i++; // Increment i to 2
lc.setRow(0, i, invader3c[i]); // Execute with i = 2
i++; // Increment i to 3
lc.setRow(0, i, invader3c[i]); // Execute with i = 3
i++; // Increment i to 4
lc.setRow(0, i, invader3c[i]); // Execute with i = 4
i++; // Increment i to 5
lc.setRow(0, i, invader3c[i]); // Execute with i = 5
i++; // Increment i to 6
lc.setRow(0, i, invader3c[i]); // Execute with i = 6
i++; // Increment i to 7
lc.setRow(0, i, invader3c[i]); // Execute with i = 7
}
void sinvader2c()
{
int i = 0; // Start with i = 0
lc.setRow(0, i, invader2c[i]); // Execute with i = 0
i++; // Increment i to 1
lc.setRow(0, i, invader2c[i]); // Execute with i = 1
i++; // Increment i to 2
lc.setRow(0, i, invader2c[i]); // Execute with i = 2
i++; // Increment i to 3
lc.setRow(0, i, invader2c[i]); // Execute with i = 3
i++; // Increment i to 4
lc.setRow(0, i, invader2c[i]); // Execute with i = 4
i++; // Increment i to 5
lc.setRow(0, i, invader2c[i]); // Execute with i = 5
i++; // Increment i to 6
lc.setRow(0, i, invader2c[i]); // Execute with i = 6
i++; // Increment i to 7
lc.setRow(0, i, invader2c[i]); // Execute with i = 7
}
void sinvader1c()
{
int i = 0; // Start with i = 0
lc.setRow(0, i, invader1c[i]); // Execute with i = 0
i++; // Increment i to 1
lc.setRow(0, i, invader1c[i]); // Execute with i = 1
i++; // Increment i to 2
lc.setRow(0, i, invader1c[i]); // Execute with i = 2
i++; // Increment i to 3
lc.setRow(0, i, invader1c[i]); // Execute with i = 3
i++; // Increment i to 4
lc.setRow(0, i, invader1c[i]); // Execute with i = 4
i++; // Increment i to 5
lc.setRow(0, i, invader1c[i]); // Execute with i = 5
i++; // Increment i to 6
lc.setRow(0, i, invader1c[i]); // Execute with i = 6
i++; // Increment i to 7
lc.setRow(0, i, invader1c[i]); // Execute with i = 7
}
void sinvader1d()
{
int i = 0; // Start with i = 0
lc.setRow(0, i, invader1d[i]); // Execute with i = 0
i++; // Increment i to 1
lc.setRow(0, i, invader1d[i]); // Execute with i = 1
i++; // Increment i to 2
lc.setRow(0, i, invader1d[i]); // Execute with i = 2
i++; // Increment i to 3
lc.setRow(0, i, invader1d[i]); // Execute with i = 3
i++; // Increment i to 4
lc.setRow(0, i, invader1d[i]); // Execute with i = 4
i++; // Increment i to 5
lc.setRow(0, i, invader1d[i]); // Execute with i = 5
i++; // Increment i to 6
lc.setRow(0, i, invader1d[i]); // Execute with i = 6
i++; // Increment i to 7
lc.setRow(0, i, invader1d[i]); // Execute with i = 7
}
void sinvader2d()
{
int i = 0; // Start with i = 0
lc.setRow(0, i, invader2d[i]); // Execute with i = 0
i++; // Increment i to 1
lc.setRow(0, i, invader2d[i]); // Execute with i = 1
i++; // Increment i to 2
lc.setRow(0, i, invader2d[i]); // Execute with i = 2
i++; // Increment i to 3
lc.setRow(0, i, invader2d[i]); // Execute with i = 3
i++; // Increment i to 4
lc.setRow(0, i, invader2d[i]); // Execute with i = 4
i++; // Increment i to 5
lc.setRow(0, i, invader2d[i]); // Execute with i = 5
i++; // Increment i to 6
lc.setRow(0, i, invader2d[i]); // Execute with i = 6
i++; // Increment i to 7
lc.setRow(0, i, invader2d[i]); // Execute with i = 7
}
void sinvader3d()
{
int i = 0; // Start with i = 0
lc.setRow(0, i, invader3d[i]); // Execute with i = 0
i++; // Increment i to 1
lc.setRow(0, i, invader3d[i]); // Execute with i = 1
i++; // Increment i to 2
lc.setRow(0, i, invader3d[i]); // Execute with i = 2
i++; // Increment i to 3
lc.setRow(0, i, invader3d[i]); // Execute with i = 3
i++; // Increment i to 4
lc.setRow(0, i, invader3d[i]); // Execute with i = 4
i++; // Increment i to 5
lc.setRow(0, i, invader3d[i]); // Execute with i = 5
i++; // Increment i to 6
lc.setRow(0, i, invader3d[i]); // Execute with i = 6
i++; // Increment i to 7
lc.setRow(0, i, invader3d[i]); // Execute with i = 7
}
void sinvader4d()
{
int i = 0; // Start with i = 0
lc.setRow(0, i, invader4d[i]); // Execute with i = 0
i++; // Increment i to 1
lc.setRow(0, i, invader4d[i]); // Execute with i = 1
i++; // Increment i to 2
lc.setRow(0, i, invader4d[i]); // Execute with i = 2
i++; // Increment i to 3
lc.setRow(0, i, invader4d[i]); // Execute with i = 3
i++; // Increment i to 4
lc.setRow(0, i, invader4d[i]); // Execute with i = 4
i++; // Increment i to 5
lc.setRow(0, i, invader4d[i]); // Execute with i = 5
i++; // Increment i to 6
lc.setRow(0, i, invader4d[i]); // Execute with i = 6
i++; // Increment i to 7
lc.setRow(0, i, invader4d[i]); // Execute with i = 7
}
Also it is true that I don't always have the access of my hardwre, I tried using wokwi-simulation but theres several libraries that is not accessible in the wokwi
You can add libraries
This the running WOKWI-Simulation of your
But I don't understand what you mean by writing
this is the complete code when it is done.
This says
- the code is completed
at the same time your sentence says the contradictionary - this will be the code when it is done (in the future)
Now what is it`?
Is it ready to use code with everything done and working?
or
is it work in progress that is missing some parts?
This is your
code-version.
Libraries are added but there are different things missing
my bad by this I meant
That this code is not currently done (working) but when everything is done this is the code that will be change/modify, so yeah it is work in progress that is missing some part. I also wanna say thankyou for providing me the wokwi-simulation I tried it and its trying to make me pay, thankyou very much again
Edit: just encountered another problem, theres no hall effect at the wokwi, theres only a esp32 that has a built in hall effect but I don't know how to use it since I never tried using any other board
Stefan's links to Wokwi simulations in #79 using the code you posted in #78 work like this for me:
The first one runs, with a very fqst loop printing out lines like this:
X: 0 | Y: 0 | Z: 0 | H: 0
X: 0 | Y: 0 | Z: 0 | H: 0
X: 0 | Y: 0 | Z: 0 | H: 0
X: 0 | Y: 0 | Z: 0 | H: 0
The second prints compilation errors:
If I click the install library button and try again, I get another error:
If I click on that I get a third screen of errors:
sketch.ino:1:24: error: stray '#' in program
type or paste code here#include <Wire.h>
^
sketch.ino:1:1: error: 'type' does not name a type; did you mean 'tone'?
type or paste code here#include <Wire.h>
^~~~
tone
In file included from /libraries/MPU6050/src/I2Cdev.h:94:0,
from /libraries/MPU6050/src/MPU6050.h:41,
from sketch.ino:2:
/arduino/hardware/avr/1.8.6/libraries/Wire/src/Wire.h:86:8: error: 'TwoWire' does not name a type; did you mean 'TwoWire_h'?
extern TwoWire Wire;
^~~~~~~
TwoWire_h
sketch.ino: In function 'void setup()':
sketch.ino:100:3: error: 'Wire' was not declared in this scope
Wire.begin();
^~~~
sketch.ino:101:3: error: 'mpu' was not declared in this scope
mpu.initialize();
... taking off the extranous text gets:
sketch.ino: In function 'void setup()':
sketch.ino:101:3: error: 'mpu' was not declared in this scope
mpu.initialize();
^~~
sketch.ino:102:3: error: 'SPI' was not declared in this scope
SPI.begin(); // Initialize SPI
^~~
sketch.ino:102:3: note: suggested alternative: 'SPIE'
SPI.begin(); // Initialize SPI
^~~
SPIE
sketch.ino:104:3: error: 'lc' was not declared in this scope
lc.shutdown(0, false); // Wake up displays
^~
sketch.ino:117:3: error: 'myDisplay' was not declared in this scope
myDisplay.begin();
^~~~~~~~~
sketch.ino: In function 'void do_ONE_Step_lefttiltAnimation()':
sketch.ino:125:3: error: 'tiltAnimationTimer' was not declared in this scope
tiltAnimationTimer = millis() + tiltAnimationDelay; // Set timer for next frame
^~~~~~~~~~~~~~~~~~
sketch.ino:125:3: note: suggested alternative: 'tiltAnimationDelay'
tiltAnimationTimer = millis() + tiltAnimationDelay; // Set timer for next frame
^~~~~~~~~~~~~~~~~~
tiltAnimationDelay
sketch.ino: In function 'void loop()':
sketch.ino:152:3: error: 'mpu' was not declared in this scope
mpu.getAcceleration(&ax, &ay, &az); // measure the value of the accelerometer to make it display the left turn animation
^~~
sketch.ino:153:3: error: 'displayAcceleration' was not declared in this scope
displayAcceleration(ax, ay, az);
^~~~~~~~~~~~~~~~~~~
sketch.ino: In function 'void sinvader4c()':
sketch.ino:165:3: error: 'lc' was not declared in this scope
lc.setRow(0, i, invader4c[i]); // Execute with i = 0
^~
sketch.ino: In function 'void sinvader3c()':
sketch.ino:185:3: error: 'lc' was not declared in this scope
lc.setRow(0, i, invader3c[i]); // Execute with i = 0
^~
sketch.ino: In function 'void sinvader2c()':
sketch.ino:205:3: error: 'lc' was not declared in this scope
lc.setRow(0, i, invader2c[i]); // Execute with i = 0
^~
sketch.ino: In function 'void sinvader1c()':
sketch.ino:225:3: error: 'lc' was not declared in this scope
lc.setRow(0, i, invader1c[i]); // Execute with i = 0
^~
sketch.ino: In function 'void sinvader1d()':
sketch.ino:245:3: error: 'lc' was not declared in this scope
lc.setRow(0, i, invader1d[i]); // Execute with i = 0
^~
sketch.ino: In function 'void sinvader2d()':
sketch.ino:265:3: error: 'lc' was not declared in this scope
lc.setRow(0, i, invader2d[i]); // Execute with i = 0
^~
sketch.ino: In function 'void sinvader3d()':
sketch.ino:285:3: error: 'lc' was not declared in this scope
lc.setRow(0, i, invader3d[i]); // Execute with i = 0
^~
sketch.ino: In function 'void sinvader4d()':
sketch.ino:305:3: error: 'lc' was not declared in this scope
lc.setRow(0, i, invader4d[i]); // Execute with i = 0
^~
Error during build: exit status 1
...showing that the code is asking for things it doesn't know how to configure. All together it looks like a very broken cut-and-paste copy of the first code.
I think Wokwi is compiling and running your code as written. I think it might be inviting your to pay for club membership, but it functions without paying.
Rather than using broken code like this for planning, @Robin2's scheme (below) lays out a way to develop with a working program, iterating with incremental changes in a top-down-manner with placeholder functions.
See:
I understand your kindness, I have here the link of my wokwi you could try it but its not yet complete the code is not yet fully done and need some changes, which I dont have any idea on how to fix but you could try it for your self
feel free to try I respect any recommendations about the coding Im having fun learning this kind of things, just remember that my knowledge is still not that broad and is still developing so dont be too harsh I'll always try my best to satisfy your recommendation for my own goods. ![]()
Looking at that link, It looks like your animation of STOP only steps once per Hall sensor/PWM change. If you adjust the PWM freq down to 1/sec, the STOP scrolls very slowly. I'd suggest following Stefan's suggestion of a using a slide switch in place of the PWM generator and step through your logic.
I'd also suggest rate-limiting your printing (as below) and adding more Serial.print()s in places where things might not be working as expected. For instance, maybe add Serial.print("S") in the displayStopMessage() code, or a Serial.print("M") where you notice the magnetic field.
void displayAcceleration(int16_t ax, int16_t ay, int16_t az) {
// Print the X, Y, and Z values to the serial monitor
static uint32_t lastPrintMs = 0;
if (millis() - lastPrintMs >= 500) {
lastPrintMs = millis();
Serial.print("X: ");
Serial.print(ax);
Serial.print(" | Y: ");
Serial.print(ay);
Serial.print(" | Z: ");
Serial.println(az);
}
}
I understand, I'll get back to you tomorrow and update what happens. It's just too late here and I need to take some rest, thank you so much again
Pointed out in Post #61... but amid a lot of reading, so it is easily missed. Your "flag and timer" needs work to create 1. set the flag, 2. display STOP 3. check the timer 4. if timer is "long enough" 5. remove STOP display 6. clear the flag.

