Help with 2 digit 7 segment module

Hi all, I am a newbie with Arduino programming. I have been playing with Ardudroid app and want to do the following: when 1 press a button, say #13 on the ardudroid app, I want my 2 digit 7 segment display to display the letter" An" and when i press button 12 on the ardudroid app I need to clear the "An" and display "01" on the 2 digit display. The idea here is that i'm making a fake answering machine for a prop. When the call comes in (me, pressing button 12 on cue displays "An"(answer)and would ideally would blink x amount of times then press button 12 to read "01" (one new message". I am using a Arduino uno rev 3 and have successfully gotten the bluetooth communication to talk to the app. I understand multiplexing somewhat but have only found countdown tutorials. The 2 digit 7 seg display is LPD-3020D which is a common cathode. Any help would be greatly appreciated.

Hi and welcome.

Have a look at the Playground (click !), scroll down to where it says Seven segment displays. You'll find some explanation and some examples.

Thank you for for reply MAS3. I did get my 7 seg to display the way i needed but I cant seem to implement it into the ardudroid app. when I press button 13 on the app I can see the 7seg display blink the correct characters but it does not stay on. I suspect because it’s not looping? I need to figure out how to apply it to my case #'s (example…case #13 sends the number 13 to my display, case #12 clears the previous characters and sets display to the number 12) I have attached the code i’m trying. Any input on how to go about this would be amazing as i’m running out of time on this and am a bit in over my head here. Thank you.

the code:

#include <SevenSeg.h>

/*
PROJECT: ArduDroid 
PROGRAMMER: Hazim Bitar (techbitar at gmail dot com)
DATE: Oct 31, 2013
FILE: ardudroid.ino
LICENSE: Public domain
*/

#define START_CMD_CHAR '*'
#define END_CMD_CHAR '#'
#define DIV_CMD_CHAR '|'
#define CMD_DIGITALWRITE 10
#define CMD_ANALOGWRITE 11
#define CMD_TEXT 12
#define CMD_READ_ARDUDROID 13
#define MAX_COMMAND 20  // max command number code. used for error checking.
#define MIN_COMMAND 10  // minimum command number code. used for error checking. 
#define IN_STRING_LENGHT 40
#define MAX_ANALOGWRITE 255
#define PIN_HIGH 3
#define PIN_LOW 2

SevenSeg disp(2,3,4,5,6,7,8); // I Added this code to orginal Ardudroid program to diaply my digits
const int numOfDigits=2;
int digitPins[numOfDigits]={12,13};


String inText;

void setup() {
 Serial.begin(9600);
 Serial.println("ArduDroid 0.12 Alpha by TechBitar (2013)");
 Serial.flush();
 
 
 disp.setDigitPins(numOfDigits,digitPins); // This was also added and sets my initial display to all LEDs off
 disp.setCommonCathode();
 digitalWrite(2, LOW);
 digitalWrite(3, LOW);
 digitalWrite(4, LOW);
 digitalWrite(5, LOW);
 digitalWrite(6, LOW);
 digitalWrite(7, LOW);
 digitalWrite(8, LOW);

 
}

void loop()
{
 

 Serial.flush();
 int ard_command = 0;
 int pin_num = 0;
 int pin_value = 0;

 char get_char = ' ';  //read serial

 // wait for incoming data
 if (Serial.available() < 1) return; // if serial empty, return to loop().

 // parse incoming command start flag 
 get_char = Serial.read();
 if (get_char != START_CMD_CHAR) return; // if no command start flag, return to loop().

 // parse incoming command type
 ard_command = Serial.parseInt(); // read the command
 
 // parse incoming pin# and value  
 pin_num = Serial.parseInt(); // read the pin
 pin_value = Serial.parseInt();  // read the value

 // 1) GET TEXT COMMAND FROM ARDUDROID
 if (ard_command == CMD_TEXT){   
   inText =""; //clears variable for new input   
   while (Serial.available())  {
     char c = Serial.read();  //gets one byte from serial buffer
     delay(5);
     if (c == END_CMD_CHAR) { // if we the complete string has been read
       // add your code here
       break;
     }              
     else {
       if (c !=  DIV_CMD_CHAR) {
         inText += c; 
         delay(5);
       }
     }
   }
 }

 // 2) GET digitalWrite DATA FROM ARDUDROID
 if (ard_command == CMD_DIGITALWRITE){  
   if (pin_value == PIN_LOW) pin_value = LOW;
   else if (pin_value == PIN_HIGH) pin_value = HIGH;
   else return; // error in pin value. return. 
   set_digitalwrite( pin_num,  pin_value);  // Uncomment this function if you wish to use 
   return;  // return from start of loop()
 }

 // 3) GET analogWrite DATA FROM ARDUDROID
 if (ard_command == CMD_ANALOGWRITE) {  
   analogWrite(  pin_num, pin_value ); 
   // add your code here
   return;  // Done. return to loop();
 }

 // 4) SEND DATA TO ARDUDROID
 if (ard_command == CMD_READ_ARDUDROID) { 
   // char send_to_android[] = "Place your text here." ;
   // Serial.println(send_to_android);   // Example: Sending text
   Serial.print(" Analog 0 = "); 
   Serial.println(analogRead(A0));  // Example: Read and send Analog pin value to Arduino
   return;  // Done. return to loop();
 }
}

// 2a) select the requested pin# for DigitalWrite action
void set_digitalwrite(int pin_num, int pin_value)
{
 switch (pin_num) {
   
 case 13: // Here is where I want to send the #12 to my display but it just lights up for a short flicker when button 13 on ardudriod is pressed.
    disp.write(13);
    break;
 case 12: // This button should wipe the previous characters and sed the #12 to the display
   disp.write(12);   
     break;
     
     
 case 11:
   pinMode(11, OUTPUT);
   digitalWrite(11, pin_value);         
   // add your code here 
   break;
 case 10:
   pinMode(10, OUTPUT);
   digitalWrite(10, pin_value);         
   // add your code here 
   break;
 case 9:
   pinMode(9, OUTPUT);
   digitalWrite(9, pin_value);         
   // add your code here 
   break;
 case 8:
   pinMode(8, OUTPUT);
   digitalWrite(8, pin_value);         
   // add your code here 
   break;
 case 7:
   pinMode(7, OUTPUT);
   digitalWrite(7, pin_value);         
   // add your code here 
   break;
 case 6:
   pinMode(6, OUTPUT);
   digitalWrite(6, pin_value);         
   // add your code here 
   break;
 case 5:
   pinMode(5, OUTPUT);
   digitalWrite(5, pin_value); 
   // add your code here       
   break;
 case 4:
   pinMode(4, OUTPUT);
   digitalWrite(4, pin_value);         
   // add your code here 
   break;
 case 3:
   pinMode(3, OUTPUT);
   digitalWrite(3, pin_value);         
   // add your code here 
   break;
 case 2:
   pinMode(2, OUTPUT);
   digitalWrite(2, pin_value); 
   // add your code here       
   break;      
   // default: 
   // if nothing else matches, do the default
   // default is optional
 
 }  
}

Hi,

Try this. I can’t test it for you, so its guess-work on my part.

Also note this is how you should post code/sketches on this forum. Please edit your original post so it looks like the box below. Edit your post, select all the code and press the </> icon.

Paul

#include <SevenSeg.h>

/*
 PROJECT: ArduDroid
 PROGRAMMER: Hazim Bitar (techbitar at gmail dot com)
 DATE: Oct 31, 2013
 FILE: ardudroid.ino
 LICENSE: Public domain
*/

#define START_CMD_CHAR '*'
#define END_CMD_CHAR '#'
#define DIV_CMD_CHAR '|'
#define CMD_DIGITALWRITE 10
#define CMD_ANALOGWRITE 11
#define CMD_TEXT 12
#define CMD_READ_ARDUDROID 13
#define MAX_COMMAND 20  // max command number code. used for error checking.
#define MIN_COMMAND 10  // minimum command number code. used for error checking.
#define IN_STRING_LENGHT 40
#define MAX_ANALOGWRITE 255
#define PIN_HIGH 3
#define PIN_LOW 2

SevenSeg disp(2,3,4,5,6,7,8); // I Added this code to orginal Ardudroid program to diaply my digits
const int numOfDigits=2;
int digitPins[numOfDigits]={12,13};
int numberToDisplay;


String inText;

void setup() {
  Serial.begin(9600);
  Serial.println("ArduDroid 0.12 Alpha by TechBitar (2013)");
  Serial.flush();
 
 
  disp.setDigitPins(numOfDigits,digitPins); // This was also added and sets my initial display to all LEDs off
  disp.setCommonCathode();
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);

 
}

void loop()
{
  disp.write(numberToDisplay);

  Serial.flush();
  int ard_command = 0;
  int pin_num = 0;
  int pin_value = 0;

  char get_char = ' ';  //read serial

  // wait for incoming data
  if (Serial.available() < 1) return; // if serial empty, return to loop().

  // parse incoming command start flag
  get_char = Serial.read();
  if (get_char != START_CMD_CHAR) return; // if no command start flag, return to loop().

  // parse incoming command type
  ard_command = Serial.parseInt(); // read the command
 
  // parse incoming pin# and value 
  pin_num = Serial.parseInt(); // read the pin
  pin_value = Serial.parseInt();  // read the value

  // 1) GET TEXT COMMAND FROM ARDUDROID
  if (ard_command == CMD_TEXT){   
    inText =""; //clears variable for new input   
    while (Serial.available())  {
      char c = Serial.read();  //gets one byte from serial buffer
      delay(5);
      if (c == END_CMD_CHAR) { // if we the complete string has been read
        // add your code here
        break;
      }             
      else {
        if (c !=  DIV_CMD_CHAR) {
          inText += c;
          delay(5);
        }
      }
    }
  }

  // 2) GET digitalWrite DATA FROM ARDUDROID
  if (ard_command == CMD_DIGITALWRITE){ 
    if (pin_value == PIN_LOW) pin_value = LOW;
    else if (pin_value == PIN_HIGH) pin_value = HIGH;
    else return; // error in pin value. return.
    set_digitalwrite( pin_num,  pin_value);  // Uncomment this function if you wish to use
    return;  // return from start of loop()
  }

  // 3) GET analogWrite DATA FROM ARDUDROID
  if (ard_command == CMD_ANALOGWRITE) { 
    analogWrite(  pin_num, pin_value );
    // add your code here
    return;  // Done. return to loop();
  }

  // 4) SEND DATA TO ARDUDROID
  if (ard_command == CMD_READ_ARDUDROID) {
    // char send_to_android[] = "Place your text here." ;
    // Serial.println(send_to_android);   // Example: Sending text
    Serial.print(" Analog 0 = ");
    Serial.println(analogRead(A0));  // Example: Read and send Analog pin value to Arduino
    return;  // Done. return to loop();
  }
}

// 2a) select the requested pin# for DigitalWrite action
void set_digitalwrite(int pin_num, int pin_value)
{
  switch (pin_num) {
   
  case 13: // Here is where I want to send the #12 to my display but it just lights up for a short flicker when button 13 on ardudriod is pressed.
     numberToDisplay = 12;
     break;
  case 12: // This button should wipe the previous characters and sed the #12 to the display
      numberToDisplay = 0;   
      break;
     
     
  case 11:
    pinMode(11, OUTPUT);
    digitalWrite(11, pin_value);         
    // add your code here
    break;
  case 10:
    pinMode(10, OUTPUT);
    digitalWrite(10, pin_value);         
    // add your code here
    break;
  case 9:
    pinMode(9, OUTPUT);
    digitalWrite(9, pin_value);         
    // add your code here
    break;
  case 8:
    pinMode(8, OUTPUT);
    digitalWrite(8, pin_value);         
    // add your code here
    break;
  case 7:
    pinMode(7, OUTPUT);
    digitalWrite(7, pin_value);         
    // add your code here
    break;
  case 6:
    pinMode(6, OUTPUT);
    digitalWrite(6, pin_value);         
    // add your code here
    break;
  case 5:
    pinMode(5, OUTPUT);
    digitalWrite(5, pin_value);
    // add your code here       
    break;
  case 4:
    pinMode(4, OUTPUT);
    digitalWrite(4, pin_value);         
    // add your code here
    break;
  case 3:
    pinMode(3, OUTPUT);
    digitalWrite(3, pin_value);         
    // add your code here
    break;
  case 2:
    pinMode(2, OUTPUT);
    digitalWrite(2, pin_value);
    // add your code here       
    break;     
    // default:
    // if nothing else matches, do the default
    // default is optional
 
  } 
}

PaulRb, You Sir are a rockstar!!!! Thank you a million times!!! That worked great. I noticed that in "Case 12" the value of 0 wasn't necessary. I changed it to =12. When i press button 13 my display reads 13, when i press button 12, it reads 12. Thank you again for the help and heads up how to post code to this forum.