Scrolling Marque using 8x8 matrix

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
vader7071
 
Posts: 124
Joined: Mon Sep 11, 2017 12:45 pm

Scrolling Marque using 8x8 matrix

Post by vader7071 »

I have been using the mini 8x8 led matrix (PID: 870) on an Arduino Nano for a while now. I use these things all over the place. I do a lot of marque scrolling messages.

Now I am trying to move from the Arduino Nano and go to a Feather nRF52832 (PID: 3406) so I can do some BLE control. With the move, I am trying to shift from the Arduino IDE to CircuitPython. I have found the tutorial on "activating" the libraries for the 870, even how to make sure I properly address multiple 870's.

But I am having trouble figuring out how to adjust the matrix to become a scrolling marque.

My final hardware setup is:
1) nRF52832 (PID: 3406)
3) 8x8 led Matrix (PID: 870)
1) 24 bar graph (PID: 1721)

The hardware is setup so the (3) 8x8 matrices are side by side creating a single 24x8 matrix. This is what I scroll the message on.

Here is the section from my Arduino IDE sketch. This is what I am trying to come from.

Code: Select all

void loop() {
    scroll(msg[msgChoice]); 
}

//============  Matrix Text Scroll  ============
void scroll(char* text) {
  int scrollPositions = (strlen(text) * 8) - 32;

  for (int x=(8 * NUM_MATRICES); x>=-scrollPositions; x--) {
   for(uint8_t m=0; m<NUM_MATRICES; m++) {
    matrix[m].clear();
    matrix[m].setCursor((x - (m * 8)), 0);
    matrix[m].print(text);
    matrix[m].writeDisplay();
   }
  delay(msgInterval);
  }
}
Below I included the entire sketch so you can see entirely where I am coming from trying to get to a CircuitPython program. I am open to any and all suggestions to make either the Arduino IDE or the CircuitPython better.

Code: Select all

/*
 * 2019-06-11
 * 
 * Adafruit Feather nRF52
 * nRF52832
 * 
 * Adafruit Products:
 *   3406 (Adafruit Feather nRF52 Bluefruit LE - nRF52832)
 *   870 (0.8" 8x8 Matrix)
 *   1721 (Tri-Color 24 Segment Bar Graph)
 *    
 * Does 3 things
 *   1)  Scrolls the message on (3) Adafruit 870 8x8 mini matrix
 *   2)  Runs Bar Graph above Text Matrix
 *   3)  Receives data via Bluetooth
 */

//============  Includes / Defines  ============
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include <Adafruit_GFX.h>
#include <SPI.h>

#define NUM_MATRICES 3
Adafruit_8x8matrix matrix[NUM_MATRICES];

Adafruit_24bargraph bar = Adafruit_24bargraph();

//============  Constants  ============

//--------  Sets scrolling messages  --------
char* msg[] = {"CHEST BOOTING","Where's Francis?","Don't be mean!","Maximum Effort!"};    // Scrolling text

// ---- Used for Mode Selection ----
const int msgArraySize = 4;                                                                 // Sets the number of spots in the arrays
const int barArraySize = 4;                                                                 // Sets the number of spots in the arrays

// ---- Sets Back LED Timer Multiplier ----
const int offset = 15;                                                                      // delay time for each LED

// ---- Used for Scroll Speed ----
const int msgInterval = 45;                                                                 // number of millisecs between blinks

//============  VARIABLES (will change)  ============
int barDirection = 1;                                                                       // used to determine direction on different modes
int chestBar = 0;                                                                           // used for counting cycles
bool firstRun = true;                                                                       // used for modes that require an inital setup
bool barZero = false;                                                                       // used for chest bar = 0

// ---- Used for Mode Selection ----
int msgChoice = 0;                                                                          // holds the selection for which mode to use
int barChoice = 0;                                                                          // holds the selection for which mode to use

// ---- Loop Timing Counters ----
int scroll_loop = 0;
int ledStack_loop = 0;

//============  Function Pointers  ============
// ---- Chest Bar Function Selection Array (aka Pointer) ----
void chestLedZero(), chestLedKitt(), chestLedCtrOut(), chestLedFill();
void (* chestArray[])() = {chestLedZero, chestLedKitt, chestLedCtrOut, chestLedFill};

//============  Setup function  ============
void setup()
{
  Serial.begin(115200);
  while ( !Serial ) delay(10);   // for nrf52840 with native usb

  bar.begin(0x73);                                                                          // Set the address for the 24 Bar Graph

  for(uint8_t m=0; m<NUM_MATRICES; m++) {                                                   // Set the address and mode for the 8x8 matrices
    matrix[m].begin(0x70 + m);
    matrix[m].clear();
    matrix[m].setTextSize(1);
    matrix[m].setTextWrap(false);                                                           // we dont want text to wrap so it scrolls nicely
    matrix[m].setRotation(2);                                                               // 0 = Conn @ Top; 1 = Conn @ Left; 2 = Conn @ Bottom; 3 = Conn @ Right
  }
}


//============  Loop function  ============
void loop() {
    scroll(msg[msgChoice]); 
}

//============  Matrix Text Scroll  ============
void scroll(char* text) {
  int scrollPositions = (strlen(text) * 8) - 32;

  for (int x=(8 * NUM_MATRICES); x>=-scrollPositions; x--) {
   for(uint8_t m=0; m<NUM_MATRICES; m++) {
    matrix[m].clear();
    matrix[m].setCursor((x - (m * 8)), 0);
    matrix[m].print(text);
    matrix[m].writeDisplay();
   }

// ---- Calls the Bar Graph code ----
   chestArray[barChoice]();
  
  delay(msgInterval);
  }
}

//============  Chest Bar Zero  ============
/*
 * Flashes Bar.
 * barChoice = 0
 */

void chestLedZero() {
  barZero = !barZero;
  if (barZero == true){
    for (uint8_t l=0; l<=24; l++){
      bar.setBar(l, LED_GREEN);
      bar.writeDisplay();
    }
  }
  if (barZero == false){
    for (uint8_t l=0; l<=24; l++){
      bar.setBar(l, LED_OFF);
      bar.writeDisplay();
    }
  }
}


//============  Chest Bar 3 LED K.I.T.T. mode  ============
/*
 * One LED moving like the front of K.I.T.T. from Knight Rider
 * Also known as Cylon Mode
 */
 
void chestLedKitt() {
  if (barDirection == 1){
  chestBar++;
  bar.setBar(chestBar, LED_RED);
  bar.writeDisplay();
  bar.setBar(chestBar - 1, LED_OFF);
  bar.writeDisplay();
 }
 if (barDirection == 0){
  chestBar--;
  bar.setBar(chestBar, LED_RED);
  bar.writeDisplay();
  bar.setBar(chestBar + 1, LED_OFF);
  bar.writeDisplay();
 }
 if (chestBar >= 23){
  barDirection = 0;
 }
 if (chestBar <= 0){
  barDirection = 1;
 }
 firstRun=false;
}

//============  Chest Bar LED Fill & Dump  ============
/*
 * Fills from left to right till bar full
 * then keeps going until empty
 * Like a train passing a station
 */
 
void chestLedFill() {
 if (barDirection == 1){
  bar.setBar(chestBar, LED_RED);
  bar.writeDisplay();
  chestBar++;
 }
 if (barDirection == 0){
  chestBar++;
  bar.setBar(chestBar-25, LED_OFF);
  bar.writeDisplay();
 }
 if (chestBar >= 24){
  barDirection = 0;
 }
 if (chestBar >= 48){
  barDirection = 1;
  chestBar = 0;
 }
 firstRun=false;
}

//============  Chest Bar LED Center to Outside  ============
/*
 * Starts in the middle and fills outwards till full
 * Once full, keeps going until the bar is empty
 * Like 2 trains headed away from each other and just exiting the sides
 */

void chestLedCtrOut() {
  if (firstRun == true){
    chestBar = 12;
    barDirection = 1;
  }
 if (barDirection == 1){
  bar.setBar(chestBar, LED_RED);
  bar.setBar(23 - chestBar, LED_RED);
  bar.writeDisplay();
  chestBar++;
 }
 if (barDirection == 0){
  bar.setBar(chestBar, LED_OFF);
  bar.setBar(23 - chestBar, LED_OFF);
  bar.writeDisplay();
  chestBar++;
 }
 if (chestBar >= 24 && barDirection == 1){
  barDirection = 0;
  chestBar = 12;
 }
 if (chestBar >= 24 && barDirection == 0){
  barDirection = 1;
  chestBar = 12;
 }
 firstRun=false;
}
In the full sketch, it may appear that I am looking at variables that get no input. That isn't the case. The full sketch has a bluetooth portion to it where I can receive data via BLE from a cellphone. To try and trim the sketch size, I just removed all of the BLE portions of the sketch, plus the BLE portion will be completely redone in CircuitPython, and isn't part of this question.

User avatar
dastels
 
Posts: 15817
Joined: Tue Oct 20, 2015 3:22 pm

Re: Scrolling Marque using 8x8 matrix

Post by dastels »

CircuitPython isn't supported on the nRF52832; you will need a Feather nRF52840 Express https://www.adafruit.com/product/4062.

Dave

User avatar
vader7071
 
Posts: 124
Joined: Mon Sep 11, 2017 12:45 pm

Re: Scrolling Marque using 8x8 matrix

Post by vader7071 »

Ok, thank you. I am having some issues with the BLE staying connected. I'll start a new thread for that question.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”