Skip to content

Instantly share code, notes, and snippets.

@rafitc
Last active September 28, 2022 17:28
Show Gist options
  • Select an option

  • Save rafitc/c70100db74bbdcac88df80abfe85fcac to your computer and use it in GitHub Desktop.

Select an option

Save rafitc/c70100db74bbdcac88df80abfe85fcac to your computer and use it in GitHub Desktop.
#include <SoftwareSerial.h>
#include <SPI.h>
#include <DMD.h>
#include <TimerOne.h>
#include "SystemFont5x7.h"
#include "Arial_black_16.h"
#define ROW 1
#define COLUMN 1
#define FONT Arial_Black_16
DMD led_module(ROW, COLUMN);
String st;
const char *msg;
unsigned int LengMsg;
char finalMsg[100] = "";
SoftwareSerial mySerial(3, 2);
void scan_module() {
led_module.scanDisplayBySPI();
}
void setup() {
Timer1.initialize(2000);
Timer1.attachInterrupt(scan_module);
led_module.clearScreen( true );
Serial.begin(9600);
mySerial.begin(9600);
Serial.println("Starting...");
delay(1000);
mySerial.println("AT");
updateSerial();
mySerial.println("AT+CMGF=1");
updateSerial();
mySerial.println("AT+CNMI=1,2,0,0,0");
updateSerial();
}
void loop() {
// pollSms();
displayMessage();
delay(500);
//Start print in led matrix
led_module.selectFont(FONT);
led_module.drawMarquee(finalMsg, LengMsg, (32 * ROW), 0);
long start = millis();
long timming = start;
boolean flag = false;
while (!flag) {
if ((timming + 20) < millis()) {
flag = led_module.stepMarquee(-1, 0);
timming = millis();
}
}
}
//------GSM Helper
void displayMessage()
{
delay(500);
String msg = "";
int start = 0, endPoint = 0;
finalMsg[100] = "";
while (Serial.available())
{
mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
// parseData(mySerial.readString());//Calls the parseData function to parse SMS
}
while (mySerial.available())
{
msg = mySerial.readString();//Forward what Software Serial received to Serial Port
}
if (msg.length() > 1) {
start = msg.indexOf('*') + 1;
endPoint = msg.indexOf('#') - 1;
int count = 0;
if (start > 1 && endPoint > 1) {
strcpy( finalMsg, "");
for (int i = start; i <= endPoint; i++) {
finalMsg[count] = msg[i];
count++;
}
Serial.println("SMS Received: ");
Serial.println(finalMsg);
LengMsg = count;
}
else{
return false;
}
}
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while (mySerial.available())
{
Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment