Бегущая строка показывает верх тормашками

Gavrilov_S
Offline
Зарегистрирован: 13.11.2014

Добрый день!

Собрал бегущую строку по библиотекам отсюда http://parola.codeplex.com/releases

Купил готовые I2c матрицы 8x8 http://www.aliexpress.com/snapshot/6409463886.html?orderId=65118323589779  все работает кроме как он показывает символы верх ногами.

Помогите где что надо поменять в программе или в библиотеке.

 

Gavrilov_S
Offline
Зарегистрирован: 13.11.2014
#include <MD_MAX72xx.h>

#define USE_POT_CONTROL 0
#define PRINT_CALLBACK 0

#define PRINT(s, v) { Serial.print(F(s)); Serial.print(v); }

// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may 
// need to be adapted
#define MAX_DEVICES 8

#define CLK_PIN  13  // or SCK
#define DATA_PIN 11  // or MOSI
#define CS_PIN  10  // or SS

// SPI hardware interface
MD_MAX72XX mx = MD_MAX72XX(CS_PIN, MAX_DEVICES);
// Arbitrary pins
//MD_MAX72XX mx = MD_MAX72XX(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

// Scrolling parameters
#if USE_POT_CONTROL
#define SPEED_IN A5
#else
#define SCROLL_DELAY 75 // in milliseconds
#endif // USE_POT_CONTROL

#define CHAR_SPACING 1 // pixels between characters

// Global message buffers shared by Serial and Scrolling functions
#define BUF_SIZE 75
char curMessage[BUF_SIZE];
char newMessage[BUF_SIZE];
bool newMessageAvailable = false;

uint16_t scrollDelay; // in milliseconds

void readSerial(void)
{
  static uint8_t putIndex = 0;

  while (Serial.available())
  {
    newMessage[putIndex] = (char)Serial.read();
    if ((newMessage[putIndex] == '\n') || (putIndex >= BUF_SIZE-3)) // end of message character or full buffer
    {
      // put in a message separator and end the string
      newMessage[putIndex++] = ' ';
      newMessage[putIndex] = '\0';
      // restart the index for next filling spree and flag we have a message waiting
      putIndex = 0;
      newMessageAvailable = true;
    }
    else
      // Just save the next char in next location
      newMessage[putIndex++];
  }
}

void scrollDataSink(uint8_t dev, MD_MAX72XX::transformType_t t, uint8_t col)
// Callback function for data that is being scrolled off the display
{
#if PRINT_CALLBACK
  Serial.print("\n cb ");
  Serial.print(dev);
  Serial.print(' ');
  Serial.print(t);
  Serial.print(' ');
  Serial.println(col);
#endif
}

uint8_t scrollDataSource(uint8_t dev, MD_MAX72XX::transformType_t t)
// Callback function for data that is required for scrolling into the dusplay
{
  static char  *p = curMessage;
  static uint8_t state = 0;
  static uint8_t curLen, showLen;
  static uint8_t cBuf[8];
  uint8_t colData;

  // finite state machine to control what we do on the callback
  switch(state)
  {
    case 0: // Load the next character from the font table
      showLen = mx.getChar(*p++, sizeof(cBuf)/sizeof(cBuf[0]), cBuf);
      curLen = 0;
      state++;

      // if we reached end of message, reset the message pointer
      if (*p == '\0')
      {
        p = curMessage;   // reset the pointer to start of message
        if (newMessageAvailable) // there is a new message waiting
        {
          strcpy(curMessage, newMessage); // copy it in
          newMessageAvailable = false;
        }
      }
      // !! deliberately fall through to next state to start displaying

    case 1: // display the next part of the character
      colData = cBuf[curLen++];
      if (curLen == showLen)
      {
        showLen = CHAR_SPACING;
        curLen = 0;
        state = 2;
      }
      break;

    case 2: // display intercharacter spacing (blank column)
      colData = 0;
      curLen++;
      if (curLen == showLen)
        state = 0;
      break;

    default:
      state = 0;
  }

  return(colData);
}

 void scrollText(void)
{
  static uint32_t prevTime = 0;

  // Is it time to scroll the text?
  if (millis()-prevTime >= scrollDelay)
  {
    mx.transform(MD_MAX72XX::TSL); // scroll along - the callback will load all the data
    prevTime = millis();   // starting point for next time
  }
}

uint16_t getScrollDelay(void)
{
#if USE_POT_CONTROL
  uint16_t t;

  t = analogRead(SPEED_IN);
  t = map(t, 0, 1023, 25, 250);

  return(t);
#else
  return(SCROLL_DELAY);
#endif
}

void setup()
{
  mx.begin();
  mx.setShiftDataInCallback(scrollDataSource);
  mx.setShiftDataOutCallback(scrollDataSink);

#if USE_POT_CONTROL
  pinMode(SPEED_IN, INPUT);
#else
  scrollDelay = SCROLL_DELAY;
#endif

  strcpy(curMessage, "Hello! ");
  newMessage[0] = '\0';

  Serial.begin(57600);
  Serial.print("\n[MD_MAX72XX Message Display]\nType a message for the scrolling display\nEnd message line with a newline");
}

void loop() 
{
  scrollDelay = getScrollDelay();
  readSerial();
  scrollText();
}

 

Gavrilov_S
Offline
Зарегистрирован: 13.11.2014
#ifndef MDMAX72xxLIB_H
#define MDMAX72xxLIB_H

/**
 * \file
 * \brief Includes library definitions
 */

#define MAX_DEBUG 0  ///< Enable or disable (default) debugging output from the MD_MAX72xx library

#if MAX_DEBUG
#define PRINT(s, v)  { Serial.print(F(s)); Serial.print(v); }  ///< Print a string followed by a value (decimal)
#define PRINTX(s, v) { Serial.print(F(s)); Serial.print(v, HEX); } ///< Print a string followed by a value (hex)
#define PRINTB(s, v) { Serial.print(F(s)); Serial.print(v, BIN); } ///< Print a string followed by a value (binary)
#define PRINTS(s)  { Serial.print(F(s)); }       ///< Print a string
#else
#define PRINT(s, v)  ///< Print a string followed by a value (decimal)
#define PRINTX(s, v) ///< Print a string followed by a value (hex)
#define PRINTB(s, v) ///< Print a string followed by a value (binary)
#define PRINTS(s)  ///< Print a string
#endif

// Opcodes for the MAX7221 and MAX7219
 // All OP_DIGITn are offsets from OP_DIGIT0
#define OP_NOOP     0 ///< MAX72xx opcode for NO OP
#define OP_DIGIT0   1 ///< MAX72xx opcode for DIGIT0
#define OP_DIGIT1   2 ///< MAX72xx opcode for DIGIT1
#define OP_DIGIT2   3 ///< MAX72xx opcode for DIGIT2
#define OP_DIGIT3   4 ///< MAX72xx opcode for DIGIT3
#define OP_DIGIT4   5 ///< MAX72xx opcode for DIGIT4
#define OP_DIGIT5   6 ///< MAX72xx opcode for DIGIT5
#define OP_DIGIT6   7 ///< MAX72xx opcode for DIGIT6
#define OP_DIGIT7   8 ///< MAX72xx opcode for DIGIT7
#define OP_DECODEMODE   9 ///< MAX72xx opcode for DECODE MODE
#define OP_INTENSITY   10 ///< MAX72xx opcode for SET INTENSITY
#define OP_SCANLIMIT   11 ///< MAX72xx opcode for SCAN LIMIT
#define OP_SHUTDOWN    12 ///< MAX72xx opcode for SHUT DOWN
#define OP_DISPLAYTEST 15 ///< MAX72xx opcode for DISPLAY TEST

#define ALL_CHANGED   0xff   ///< Mask for all rows changed in a buffer structure
#define ALL_CLEAR     0x00   ///< Mask for all rows clear in a buffer structure

#define FONT_INDEX_SIZE 256   ///< Number of characters in a font table (ASCII maximum)

// Shortcuts
#define SPI_DATA_SIZE (sizeof(uint8_t)*_maxDevices*2) ///< Size of the SPI data buffers
#define SPI_OFFSET(i,x) (((i)*2)+(x))     ///< SPI data offset for buffer i, digit x
#define FIRST_BUFFER 0      ///< First buffer number
#define LAST_BUFFER  (_maxDevices-1)   ///< Last buffer number

// variables shared in the library
extern uint8_t _sysfont_var[];  ///< System variable pitch font table

// Coordinate system adjustment for different hardware configurations
// 
// Each hardware type translates into a transformation of coordinates and potential 
// reversal of row and column indices. This creates 2 coordinates systems - a cartesian 
// coordinate system based on the pixels seen and an underlying hardware coordinate 
// system based on digits and segments.
// Pixel coordinate space has it's origin in the top right hand corner of a display. 
// - Columns numbers increase to the left (as do module numbers)  
// - Row numbers increase down (0..7)
//
// All user functions are called using pixel coordinates space and all hardware buffers 
// are stored in 'hardware ready' coordinates that depend on the hardware configuration. 
// It is the job of the low level library functions to map one to the other. 
//
// All the dependent code is in the buffer and pixel modules. All other modules 
// are written in terms of the primitives given in these affected modules.
//
// Library code sections will be activated depending on the defines below, to perform 
// the appropriate coordinate remapping and transformations.
// HW_DIG_ROWS - Max72xx digits are mapped to rows in on the matrix. 
//               If digits are not rows then they are columns!
// HW_REV_COLS - Max72xx column coordinates orientation is 0 col is on right
// HW_REV_COLS - Max72xx row coordinates orientation is 0 row is at top  
//
// Note: Combinations not listed here have probably not been tested and may not work correctly.
//
#if USE_PAROLA_HW  // tested MC 8 March 2014
#define HW_DIG_ROWS 1
#define HW_REV_ROWS 0
#define HW_REV_COLS 1
#endif

#if USE_GENERIC_HW  // tested MC 9 March 2014
#define HW_DIG_ROWS 0
#define HW_REV_ROWS 0
#define HW_REV_COLS 1
#endif

#if USE_ICSTATION_HW // tested MC 9 March 2014
#define HW_DIG_ROWS 1
#define HW_REV_ROWS 1
#define HW_REV_COLS 1
#endif

// Macros to map ROW and COLUMN coordinates
#if HW_REV_ROWS
#define HW_ROW(r) (7-r) ///< Pixel to hardware coordinate row mapping
#else
#define HW_ROW(r) (r)  ///< Pixel to hardware coordinate row mapping
#endif

#if HW_REV_COLS
#define HW_COL(c) (7-c) ///< Pixel to hardware coordinate column mapping
#else
#define HW_COL(c) (c)  ///< Pixel to hardware coordinate column mapping
#endif

#endif

 

Gavrilov_S
Offline
Зарегистрирован: 13.11.2014

Нашел сам. Пол дня копал код.

Может кому нибудь пригодиться. В библиотеке нужно поменять

#if USE_PAROLA_HW  // tested MC 8 March 2014
#define HW_DIG_ROWS 1 //1
#define HW_REV_ROWS 1 //0
#define HW_REV_COLS 1 //1
#endif

И все. О чудо, буквы перевернулись :)

Emeljanowich
Emeljanowich аватар
Offline
Зарегистрирован: 30.04.2015

Подскажи пожалуйста, как поменять? Как открыть библиотеку? Спасибо. 

malev
Offline
Зарегистрирован: 07.07.2015

Библиотека MD_MAX72xx_lib.h (работает как отдельно так и в комплекте с parola). Поменять можно блокнотом, я использую notepad++. Библиотеку брал с http://arduinocode.codeplex.com/releases

Waldemar Hein
Offline
Зарегистрирован: 06.05.2019

MD_MAX72xx_lib.h помогите нет у меня в папке этого файла все буквы верх тормашками стоят.спасибо

Antsanv
Antsanv аватар
Offline
Зарегистрирован: 18.12.2018

А через
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW

не проще?

b707
Offline
Зарегистрирован: 26.05.2017

Waldemar Hein пишет:

все буквы верх тормашками

переверните матрицы

Waldemar Hein
Offline
Зарегистрирован: 06.05.2019

надо как то на 360 градусов перевернуть ну помогите,пожалуйста, острить и я могу все буквы и изображение на матрице зеркально отображаются

b707
Offline
Зарегистрирован: 26.05.2017

да никто и не острит. Если у вас 4 отдельных матрицы, то их правда проще физически перевернуть. А вот если у вас 4 матрицы вместе на одной плате, то поменять расположение непросто - вон в теме про часы на таких матрицах люди распиливали плату на отдельные квадраты и поворачивали.

Хотя. конечно, можно и в программе поменять  - но тогда выкладывайте код, схему и желатетельно фото-видео "перевернутых букв"

Waldemar Hein
Offline
Зарегистрирован: 06.05.2019
Sana956
Offline
Зарегистрирован: 14.12.2021

В секции void setup() вставь:

mx.setModuleType(MD_MAX72XX::FC16_HW);