Send numbers to 7-seg display over bluetooth

Hi!

I would like to send some digits (10 to 16) over bluetooth and display them on 2x8 7-seg display modules.

I managed to test and get the bluetooth module to work, i can now send and receive using a sample code with the serial monitor.

Using the folowing code i can set static numbers to VAR01 - VAR16 and display them correct on the modules:

//Visa tecken på 2 stycken displaymoduler som är sammankopplade med variabler

#include "LedControl.h" //Inkludera bibliotek
 
/*
PINOUT:
PIN 11 - DataIn
PIN 13 - CLK
PIN 10 - LOAD (CS)
*/

  int VAR16 = 0; //Variabler för segment 9-16
  int VAR15 = 8;
  int VAR14 = 0;
  int VAR13 = 0;
  int VAR12 = 0;
  int VAR11 = 0;
  int VAR10 = 9;
  int VAR09 = 8;

  int VAR08 = 7; //Variabler för segment 1-8
  int VAR07 = 6;
  int VAR06 = 5;
  int VAR05 = 4;
  int VAR04 = 3;
  int VAR03 = 2;
  int VAR02 = 1;
  int VAR01 = 0;

  
  
  

LedControl lc = LedControl(11,13,10,2); //Definiering av PINOUT samt antal moduler
void setup()
{
 
  // Initiering av displaymoduler (2st)
  
    lc.shutdown(0,false);  //Aktivera modul 1
    delay(10);
    lc.shutdown(1,false);  //Aktivera modul 2
    delay(10);
    
    lc.setIntensity(0,5); //Justera ljusnivå på modul 1 (0 är min, 15 är max)
    delay(10);
    lc.setIntensity(1,5); //Justera ljusnivå på modul 2 (0 är min, 15 är max)
    delay(10);
    
    lc.clearDisplay(0); //Rensa register på modul 1
    delay(10);
    lc.clearDisplay(1); //Rensa register på modul 2
    delay(10)

    
}

void loop() {{
  
   
    delay(100);
  
    lc.setChar(1,0,(int)VAR16,false); //Skriv ut tecken som är lagrade i variabel till respektive segment på modul 2
    delay(20);
    lc.setChar(1,1,(int)VAR15,false);
    delay(20);
    lc.setChar(1,2,(int)VAR14,false);
    delay(20);
    lc.setChar(1,3,(int)VAR13,false);
    delay(20);
    lc.setChar(1,4,(int)VAR12,false);
    delay(20);
    lc.setChar(1,5,(int)VAR11,false);
    delay(20);
    lc.setChar(1,6,(int)VAR10,false);
    delay(20);
    lc.setChar(1,7,(int)VAR09,false);


  
    lc.setChar(0,0,(int)VAR08,false); //Skriv ut tecken som är lagrade i variabel till respektive segment på modul 1
    delay(20);
    lc.setChar(0,1,(int)VAR07,false);
    delay(20);
    lc.setChar(0,2,(int)VAR06,false);
    delay(20);
    lc.setChar(0,3,(int)VAR05,false);
    delay(20);
    lc.setChar(0,4,(int)VAR04,false);
    delay(20);
    lc.setChar(0,5,(int)VAR03,false);
    delay(20);
    lc.setChar(0,6,(int)VAR02,false);
    delay(20);
    lc.setChar(0,7,(int)VAR01,false);

   
  }}

The string from the bluetooth module is sent without any delimiters, only a carrige return at the end.

I understand that i need to store the serial string and pharse it, then i could define VAR01 - VAR16.

Could anyone point me in the right direction how i should put this togheter?

Should i use a array to store the string?

Tried to use some parts from this code and replacing the static numbers with inputString and inChar, but only got invalid conversion from ‘const char*’ to 'char error:

String inputString = "";         // a string to hold incoming data
boolean stringComplete = false;  // whether the string is complete

void setup()
{
Serial.begin(9600);

// reserve 200 bytes for the inputString:
inputString.reserve(200);




char example[]={"20150224172718000"};




int year    = valueFromString( example, 0, 4);
int month   = valueFromString( example,4,2);
int day     = valueFromString ( example, 6, 2);
int hour    = valueFromString ( example, 8, 2);
int minute  = valueFromString ( example, 10, 2);
int second  = valueFromString ( example, 12, 2);

Serial.print( "Year ");
Serial.println (year);
Serial.print( "Month ");
Serial.println (month);
Serial.print( "Day ");
Serial.println (day);
Serial.print( "Hour ");
Serial.println (hour);
Serial.print( "minute ");
Serial.println (minute);
Serial.print( "Second ");
Serial.println (second);



}

void loop() {

    // print the string when a newline arrives:
  if (stringComplete) {
    Serial.println(inputString);
    // clear the string:
    inputString = "";
    stringComplete = false;
  }
  Serial.print(inputString);
  delay(1000);
}

int valueFromString(char* string,int start, int width)
{
int value=0;
for( int n=0; n < width; n++ )
  value = value * 10 + string[start +n] - '0';

return value; 
} 


void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
    }
}

Thanks for any advice, i am a beginner with arduino and sorry for my bad english.

/Greger

How many digits are being displayed at each location on the display? What size variable do you need to hold a value with that number of digits?

When you start numbering variables, that's a big clue that you need an array.

void loop() {{

Why why are are there there two two curly curly braces braces?

    lc.setChar(1,0,(int)VAR16,false);

Why the hell do you have to cast an int to an int?

Should i use a array to store the string?

Yes. You should use a char array, not that stupid String class.

// reserve 200 bytes for the inputString:
inputString.reserve(200);

And THAT is a big f**king clue that you do NOT need to piss away resources on a String.

Now, ask yourself just how big the array needs to be. Just how many characters can you display?

Now, take a peek at an ASCII chart. Can you figure out how to convert a '4' to a 4? Hint: it involves subtracting '0'.