4-7 Seg Display ScoreBoard

Hello, I'm new to Arduino and these forums so go easy..

I have an idea for a project and believe the Arduino may be the perfect tool for the job. Having never used this before I've spent the past week downloading various software, watching countless youtube tutorials and studying lines and lines of code. Not a lot is making sense right now but i'm persevering. I find myself here now because I have hit a brick wall with the code.

Here is an outline of what I want the project to do;

A changeable 4-7 segment display which starts at 0000 (up to 9999) with a further 2-7 segment static display showing 00. The 4-7 display increments depending on the input of a 2-axis accelerometer. Small movement +1, medium movement +10, large movement +100.

Right now, while i'm getting to grips with the code, I have simplified the design to replace the accelerometer with a push button switch which increments the display by 1 on each press. I am hoping to connect to the display serially through TX-1 of the UNO.

This is where my problems are. The code I have (through many of the sources i've mentioned above) doesn't work on 123D.

Specifically
mySerial.print(0x7A,BYTE); //special character (error - BYTE not defined in scope)

I'm also having issues setting up the serial connection with the include <Software.Serial.h> command with the error 'include' does not have a type?

Any help with these errors, advice on better way to do the project or guidance at all would be gratefully received.

I can post the code I have and a 123D circuits picture of my current design if required.

Many thanks,

JT

JonTron82:
Hello, I'm new to Arduino and these forums so go easy..

I have an idea for a project and believe the Arduino may be the perfect tool for the job. Having never used this before I've spent the past week downloading various software, watching countless youtube tutorials and studying lines and lines of code. Not a lot is making sense right now but i'm persevering. I find myself here now because I have hit a brick wall with the code.

Here is an outline of what I want the project to do;

A changeable 4-7 segment display which starts at 0000 (up to 9999) with a further 2-7 segment static display showing 00. The 4-7 display increments depending on the input of a 2-axis accelerometer. Small movement +1, medium movement +10, large movement +100.

Right now, while i'm getting to grips with the code, I have simplified the design to replace the accelerometer with a push button switch which increments the display by 1 on each press. I am hoping to connect to the display serially through TX-1 of the UNO.

This is where my problems are. The code I have (through many of the sources i've mentioned above) doesn't work on 123D.

Specifically
mySerial.print(0x7A,BYTE); //special character (error - BYTE not defined in scope)

I'm also having issues setting up the serial connection with the include <Software.Serial.h> command with the error 'include' does not have a type?

Any help with these errors, advice on better way to do the project or guidance at all would be gratefully received.

I can post the code I have and a 123D circuits picture of my current design if required.

Many thanks,
JT

I can see a number of potential issues here.
It would be best if you post your code. Between code tags, of course. (</> in the "reply" dialog.)

Thanks for the reply.
I've tweaked some bits replacing

mySerial.print(0000,BYTE)

with

Serial.write(0000)

as I believe the old code is obsolete?

Here is the code I'm using.

#include <SoftwareSerial.h>

#define txPin 1  //change to your serial port on Arduino board
#define trxPin 0  //not used but is required

SoftwareSerial mySerial =  SoftwareSerial(0,1);
int buttonPressCount;


const int  buttonPin = 2;    //the pin that the pushbutton is attached to




int buttonPushCounter = 0;   //counter for the number of button presses
int buttonState = 0;         //current state of the button
int lastButtonState = 0;     //previous state of the button


void setup()  {
  pinMode(buttonPin, INPUT);  //initialize the button pin as a input
  Serial.begin(9600);  //initialize serial communication

 pinMode(txPin, OUTPUT);
 //the following resets the board, changes the brightness to 100%, and sets the board to '0000':
 Serial.begin(9600);
 Serial.write(0x7A); //special character
 Serial.write(0x00); //set brightness to full
 Serial.write(0x76); //reset board
 Serial.print(0); //send '0' character
 Serial.print(0); //send '0' character
 Serial.print(0); //send '0' character
 Serial.print(0); //send '0' character
}

void loop(){
 
  buttonState = digitalRead(buttonPin);  //read the pushbutton input pin

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button
      // went from off to on:
      buttonPushCounter++;
      
      Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter, DEC);
      updateDisplay(buttonPushCounter);  //function to update the display 'requires button press count'
      
      
    } 

  }
 
  lastButtonState = buttonState;  // save the current state as the last state, for next time through the loop

  

}




void updateDisplay(int buttonPushCounter){
String intString = String(buttonPushCounter);  //changes integer to a string
char displayChars[4];  //create array to hold the four numbers
int stringLength = intString.length();  //get length of the string
//the following will determine if the button press count variable has 1, 2, 3, or 4 numbers in it
//and will fill the empty spaces with '0'. so if the button press count variable is '29' it will end up being '0029':
if(stringLength == 4){
  displayChars[0] = intString.charAt(0);
  displayChars[1] = intString.charAt(1);
  displayChars[2] = intString.charAt(2);
  displayChars[3] = intString.charAt(3);
}else if(stringLength == 3){
  displayChars[0] = 0;
  displayChars[1] = intString.charAt(0);
  displayChars[2] = intString.charAt(1);
  displayChars[3] = intString.charAt(2);
}else if(stringLength == 2){
  displayChars[0] = 0;
  displayChars[1] = 0;
  displayChars[2] = intString.charAt(0);
  displayChars[3] = intString.charAt(1);
}else if(stringLength == 1){
  displayChars[0] = 0;
  displayChars[1] = 0;
  displayChars[2] = 0;
  displayChars[3] = intString.charAt(0);
}
 Serial.write(0x76); //Reset board
 Serial.write(0x76); //Reset board
 Serial.print(displayChars[0]); //Send '0' character
 Serial.print(displayChars[1]); //Send '0' character
 Serial.print(displayChars[2]); //Send '0' character
 Serial.print(displayChars[3]); //Send '0' character

delay(100); //this will make it so you don't get double counts. you could also use this to avoid someone pressing the button repeatedly 'for fun!'
  
}

I have got it to run but no display. So it might be hardware now. But I'm not convinced I have anything going out on the TX pin.

Thanks again,

JT

Use pins besides 0,1. Those are the hardware serial pins, the ones that get used for downloading code and serial monitor interfacing (i.e. debugging) with your PC.

If you want to use the software serial you should change:

 Serial.write(0x7A); //special character
 Serial.write(0x00); //set brightness to full
 Serial.write(0x76); //reset board
 Serial.print(0); //send '0' character

To:

  mySerial.write(0x7A); //special character
  mySerial.write(0x00); //set brightness to full
  mySerial.write(0x76); //reset board
  mySerial.print(0); //send '0' character

You have two different serial drivers. One is to the PC "Serial" and one is to the display "mySerial".

You need to make sure to use the correct name.

When you make the switch to the software serial, the compiler will complain about this line.

 mySerial.write(0x00); //set brightness to full

One way you get around this is to use a constant like this (at the top of the program).

const byte ZERO = 0;

When you want to send a zero with the software serial use this code.

 mySerial.write(ZERO); //set brightness to full

Edit: AND make sure to follow CrossRoad's advice about using different I/O pins for the software serial.

Thanks everyone for the advice and help with this project. I'll be sure to try it out.

I think my problem may have been trying to run before I could crawl. Something I think many of us on here may be guilty of. I'm going back to basics with tutorials and examples I should have done at the start a couple of weeks ago. Hopefully when my coding gets better I can get this project on track. I'll be sure to update here when it does.

Many thanks again.

JT