Triggering text on a Beam remotely

Hi,

I’ve been working on getting a Beam ( http://www.hoverlabs.co/products/beam ) to work with a particle photon/electron. Getting there. Adapted their demo to display just text. But I’m not sure how and where to use a Particle Function to call the code remotely.

Here’s what I’ve got so far. Any advice appreciated.

Thanks! DC

// This #include statement was automatically added by the Particle IDE.

/*
===========================================================================    
  This started out as an example for Beam. I'm trying to adapt it so that I can remotely trigger text messages. 
  
  To that end, I commented out the second part of the demo -- the one with animations. 
  
  But I'm not sure how to "call" the right functions with a Particle Function. 
  
  Beam is a beautiful LED matrix — features 120 LEDs that displays scrolling text, animations, or custom lighting effects. 
  Beam can be purchased here: http://www.hoverlabs.co
  
  Written by Emran Mahbub and Jonathan Li for Hover Labs.  
  BSD license, all text above must be included in any redistribution
  
#  HISTORY
    v1.0  -  Initial Release
#  INSTALLATION
    The 4 library files (beam.cpp, beam.h and charactermap.h and frames.h) are required to run Beam.
    Run the BeamDemo.ino file.
    
#  SUPPORT
    For questions and comments, email us at support@hoverlabs.co
===========================================================================    
*/ 

#include "application.h"
#include "beam.h"

/* pin definitions for Beam */
#define RSTPIN 2        //use any digital pin
#define IRQPIN 9        //currently not used
#define BEAMCOUNT 1     //number of beams daisy chained together

/* Iniitialize an instance of Beam */
Beam b = Beam(RSTPIN, IRQPIN, BEAMCOUNT);

/* Timer used by the demo loop */
unsigned long updateTimer = 0;
int demo = 0;

void setup() {
    /*I'm thinking that a Particle.function goes here, but not sure. Something like:
  Particle.function("scroll",beamScroll);
     */
   
    Serial.begin(9600);
    Wire.begin();
    
    Serial.println("Starting Beam example");
    
    b.begin();
  /*  b.print("Hello");
    b.setSpeed(30);
    b.play();*/

}



void loop() {

    /*
    The following code originally cycled through two different demos every 20 seconds. 
    
    I commented out the second part. Now it just displays the text. 
    
    I'm still playing with the functions below, to optimize the display. 
    
    But first I'd like to set up a simple Particle Function so that I can trigger a simple text message remotely. 
    
    Note that it is not necessary to print to Beam on every loop. 
    */
    /*
    int beamScroll(String command) {
        b.begin();
        b.print("This is my text.");
        b.setSpeed(3);
        b.setLoops(3);
        b.play(); }
    */
    
    if (millis() - updateTimer > 20000){
        
   //     if (demo == 0){
            /*
            The print() command prints and scrolls text across Beam. 
            */
            
            b.begin();
            b.print("This is my text.");
            b.setSpeed(3);
            b.setLoops(3);
            b.play();
            //delay(10000);
            
            demo = 1;
            updateTimer = millis();
   /* 
        } else if (demo == 1){
            //The draw() command draws the frames defined in the frames.h header file, 
            //and animates them as if flipping through a book. 
            b.draw();
            b.setSpeed(2);
            b.setLoops(10);
            b.play();     
            
            demo = 0;
            updateTimer = millis();
        }
    */
    } 

    // do something else here

}

Hmm, have you had a look how Particle.function() works.
That’s pretty much a minimal use case as shown in the docs.

Just put your four code lines in a function-callback and you should be done.

1 Like

Yes, definitely a minimal use case for the Particle.

I’ll go back and review the docs, with an eye out for “function-callbacks”

thanks,

DC

1 Like

Hi DC, what a beautiful display!

You may try something like this (this compiles, but I don’t know if it works since I don’t have a beam):

#include "application.h"
#include "beam.h"

/* pin definitions for Beam */
#define RSTPIN 2    //use any digital pin
#define IRQPIN 9    //currently not used
#define BEAMCOUNT 1 //number of beams daisy chained together

/* Iniitialize an instance of Beam */
Beam b = Beam(RSTPIN, IRQPIN, BEAMCOUNT);

/* Timer used by the demo loop */
unsigned long updateTimer = 0;
int demo = 0;

void setup()
{

    Serial.begin(9600);
    Wire.begin();

    Particle.function("scroll", beamScroll);

    b.begin();
}

void loop()
{

}

int beamScroll(String command)
{
    b.begin();
    b.print("This is my text.");
    b.setSpeed(3);
    b.setLoops(3);
    b.play();
    return 0;
}

Hope it helps,
Gustavo.

1 Like

Thanks Gustavo, worked great. You even inspired a coder at Cambridge Hackspace to add a few wrinkles.

I’ll share our latest version when I get a chance.

Thanks again!

DC

1 Like