Scrolling text is an obvious thing to want to do with the LED matrix.
The scrollText function lets you specify the delay as an argument or pass in a variable as the text.
However, this only works in mblock mode when flag is pressed. Once you upload to arduino then the matrix just displays “text”! That means it’s displaying the internal function variable name rather than the argument passed to that variable.
Below are the block code in case that’s all you want and the arduino code which was required to fix the problem. Now I have implemented this to show the light sensor reading on the Led Matrix which required converting the integer value from the sensor to a string / char array to pass into the ledMtx.drawStr method.
Hope this helps someone.
scrollText.sb2 (76.6 KB)
/*
// passing character arrays instead of strings to the drawStr function
// so that a scrollText function can pass the character array as an argument
//
// Using the makeblock app for Mac was causing it to always just scroll “text”
//
// Converting integer LDR value to char[] so it can be displayed on LED Matrix
//
// Connect LED Matrix to port 6
// Light sensor is onboard Light_sensor1
// Serial comm enabled for debugging
*/
#include <MeAuriga.h>
#include <MeLEDMatrix.h>
#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>
//Instantiate class MeLightSensor
MeLightSensor lightsensor_12(12);
//Instantiate class MeLEDMatrix connected on port 6
MeLEDMatrix ledMtx_6(6);
double count;
char s[5];
int lightValue;
void scrollText(char *text, double scroll_delay, int mode)
{
switch (mode) {
case 0: // no scroll. Good to check the LED Matrix is working
ledMtx_6.drawStr(0,0+7,text);
break;
case 1:
for(count = 0;count <(strlen(text)) * (9);++count) {
_delay(scroll_delay);
ledMtx_6.drawStr((-1*count)+10,0+7,text);
}
break;
}
}
void setup(){
ledMtx_6.setColorIndex(1);
ledMtx_6.setBrightness(6);
//open serial communication
Serial.begin(9600);
}
void loop(){
lightValue = lightsensor_12.read();
itoa(lightValue, s, 10); //convert int to char array for drawStr method
scrollText(s, 0.1,1);
// Print results to serial monitor to check light sensor is working
// Serial.print("value = ");
// Serial.println(lightValue);
_loop();
}
void _delay(float seconds){
long endTime = millis() + seconds * 1000;
while(millis() < endTime)_loop();
}
void _loop(){
}