Hi there, new member here,
First Post,
First Arduino project.
But I do have a lot of experience in many areas including electronics.
Background, I bought my first UNO R3 (clone) about three weeks ago, I have three now including an original Arduino-cc,
UNO and a lot of extras to play with.
So C or C++ is all Greek to me at the moment, though I have had past experience using modified BASIC but that was all
over 10 years ago, and I have trouble even working out WTH was that I wrote back there on that part of previous code ?.
Iv'e downloaded 8Gig or more of information and data sheets, pdf's, tutorials and saved hundreds of pages from forums
and similar web sites, And NO, most (95%) of it wasn't You-Tube videos, though I do have quite a few from places
like educ8s.tv, https://educ8s.tv/ and How To Mechatronics https://howtomechatronics.com/arduino-projects/ and others, although that
little Greek man does rush things a bit, but better than a bloated, bad video of uselessness.
So far, stumbling around blind I've managed to get a 2.8in Touch Screen working and playing my modified BMP files
off an SD Card, got an HC-05 Bluetooth module going, modified with AT commands, had a play with an 8x8 Dot Matrix
MAX2719 module. My first project attempt will be a DMD 32x16 panel sign with fixed and a Blue Tooth input.
The project I've chosen is based on Ashru Abhijit Pattnaiks web page, Wireless Notice Board (Arduino UNO + DMD) © GPL3+
https://create.arduino.cc/projecthub/abhijitbrain/wireless-notice-board-arduino-uno-dmd-9ff29e?ref=tag&ref_id=wireless%20communication&offset=1
And here's where I need help, as I still have not written a single line of original code yet and don't even understand
how most of the syntax is even formed or put together,Yet. I'll get there, slowly.
I'll paste the code below and explain along the way.
/*
-----------
- Download the DMD library here: https://github.com/freetronics/DMD
- Place the DMD library folder into the "arduino/libraries/" folder of your Arduino installation.
- Get the TimerOne library from here: http://code.google.com/p/arduino-timerone/downloads/list
or download the local copy from the DMD library page (which may be older but was used for this creation)
and place the TimerOne library folder into the "arduino/libraries/" folder of your Arduino installation.
- Restart the IDE.
*/
#include <SPI.h> //SPI.h must be included as DMD is written by SPI (the IDE complains otherwise)
#include <DMD.h>
#include <TimerOne.h>
#include "SystemFont5x7.h"
#include "Arial_black_16.h"
//Fire up the DMD library as dmd
#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);
//number max of characters in your message
#define max_char 100
char message[max_char]; // stores you message
//char mess[max_char];
char r_char; // reads each character
byte index = 0; // defines the position into your array
int i;
char greeting[] = "Abhijit Pattnaik";
/*--------------------------------------------------------------------------------------
Interrupt handler for Timer1 (TimerOne) driven DMD refresh scanning, this gets
called at the period set in Timer1.initialize();
--------------------------------------------------------------------------------------*/
void ScanDMD()
{
dmd.scanDisplayBySPI();
}
void setup(void)
{
//initialize TimerOne's interrupt/CPU usage used to scan and refresh the display
Timer1.initialize( 5000 ); //period in microseconds to call ScanDMD. Anything longer than 5000 (5s) and you can see flicker.
Timer1.attachInterrupt( ScanDMD ); //attach the Timer1 interrupt to ScanDMD which goes to dmd.scanDisplayBySPI()
//clear/init the DMD pixels held in RAM
dmd.clearScreen( true ); //true is normal (all pixels off), false is negative (all pixels on)
Serial.begin(9600);
strcpy(message,greeting);
}
void loop(void)
{
//check if serial is avaible an before reading a new message delete's the old message
if(Serial.available())
{
for(i=0; i<99; i++){
message[i] = '\0';
}
//resests the index
index=0;
}
//while is reading the message
while(Serial.available() > 0){
//the message can have up to 100 characters
dmd.clearScreen( true );
if(index < (max_char-1))
{
r_char = Serial.read(); // Reads a character
message[index] = r_char; // Stores the character in message array
index++; // Increment position
// message[index] = '\0'; // Delete the last position
}
}
//prepares the display to print our message
dmd.selectFont(Arial_Black_16);
//displays the message
dmd.drawMarquee(message ,max_char,(32*DISPLAYS_ACROSS)-1 ,0);
long start=millis();
long timer=start;
boolean ret=false;
while(!ret)
{
if ((timer+30) < millis()) {
ret=dmd.stepMarquee(-1,0);
timer=millis();
}
}
}
Q: Is there a way to include Line Numbers inside the Code Tags above ?
Anyway if you look at that code in the IDE, on line 30, it says, char greeting[] = "Abhijit Pattnaik";
When the program runs you get that message repeated across the DMD panel.
But I wanted to include a second message or third or fourth or fifth e.g ~
char greeting1[] = "Hello World";
char greeting2[] = "Merry Christmas";
char greeting3[] = "Happy Halloween"; , etc.
Now, that first message will just repeat until it gets a different input from the Blue Tooth module, via a Phone App etc.
And then the DMD panel it will just repeat whatever was input via Bluetooth.
I wanted to jump out of the BT Loop and go back to the original message (or messages) and continue from there.
Looking at the code as is, it is not structured to do things that way, so I tried ~
A Label and a Goto, opps ! half the purists just fell of their chairs and the other half are reaching for their Heart Pills.
It didn't work, the compiler refused to accept a Label: saying " 'Label' does not name a type " or some other error.
1: I thought a Label: was valid syntax
and
2: goto Label; also, though despised by most.
Look I'm bare bones new at this and had it gotten me an end result that worked, I would have been happy.
I don't tell people what Religion or Football team to support so if "goto" had worked for me that's all that matters.
Anyway why didn't it work ?, I'm using IDE 1.8.9 and had seen examples of other instances using goto that seemed
to work so why was I getting errors ?. I tried inserting it inside the Loop, outside the Loop and 50 variations of.
Then I thought something may have changed in the IDE, so I went back to 1.6.12 but nothing changed.
I did rename my original Arduino Folders, so they were saved from the un-install, pre backdating to the older IDE.
So I'm asking (nicely) is there anyone willing to point out the correct direction I should be heading in to either
restructure the above code or modify it to suit what I need it to do and in very simple terms.
Use Comments, use lots of Comments so I can follow along and anyone else who may be learning also.
Please don't just plonk a solution on the screen and just say this will work, as I'll have learned nothing ~ :o)
To recap ~
I'd like to get the DMD to come On with a message or consecutive messages and repeat them.
(at the moment only a single message is available)
But if an input was provided from the Blue Tooth source it would then just repeat that message.
(up until now that all happens anyway)
What I need to do is to be able to jump back to the start message/s after any Blue Tooth message is received.
(this is where I need advice)
And I'm really curious to know why "goto" didn't work. Even though everybody hates the use of it.
And Library files, very annoying, half of them don't work or won't add to the collection due to some error,
but we won't go there for now.
After all of that I think I need a sandwich and a coffee.
And I promise not to make such a long post in the future.
Cheers, B0B