First Project Jitters - Input Counter with Uno using 4 Digit Serial Display

Good day all, this is my first post so I hope I hit all the check marks after reading the “Read this first section”. I tried not to call out for help in my subject line, but I guess it does come down to that, sorry.

I’ve always wanted to get my abs into shape (they never have been) and with 50 fast approaching, its probably now or never, so I deceived to buy an Arduino Uno to help me out.

All I would need for my project is an arduino kit, small display for counting the number of rolls, an ab roller and a simple switch to send a pulse to my arduino, like two sheets of tin to act as a pressure switch. So when I roll over the switch the two plates of tin touch sending a closed signal to the arduino, then counting the display up by 1, each time. In this code, it uses a press button with three leads into it, I think I’ll only need two with my switch, so I guess a slight change is needed there.

After trying to write the code myself, (my very first code) it was not going well so I hunted down a code that would work for me, I found one here. http://missionduke.com/wordpress/arduino-projects/

My serial display was a little different, from Tindie, but I’m pretty sure it should work the same, “pretty sure”. When I first uploaded the code, I had an “BYTE” error, suggesting me to sub out the older BYTE code for newer code. So then I researched that, and I am pretty sure, that I corrected the 5 errors in the older code, again, “pretty sure”.

Presto! It uploaded! But sadly, no display, double check with my wiring, seems correct, but not even a flicker on the display.

I’ll attach the code below, please have a look and throw me any suggestions and I’ll try all out.
Thxs everyone.

#include <SoftwareSerial.h>  //for software serial communication



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

SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
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':
 mySerial.begin(9600);
 mySerial.print((byte)0x7a); //special character
 mySerial.print((byte)0x00); //set brightness to full
 mySerial.print((byte)0x76); //reset board
 mySerial.print(0); //send '0' character
 mySerial.print(0); //send '0' character
 mySerial.print(0); //send '0' character
 mySerial.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);
}
 mySerial.print((byte)0x76); //Reset board
 mySerial.print((byte)0x76); //Reset board
 mySerial.print(displayChars[0]); //Send '0' character
 mySerial.print(displayChars[1]); //Send '0' character
 mySerial.print(displayChars[2]); //Send '0' character
 mySerial.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!'
  
}

Mmmmmm. Where is the code to drive the display? I see none. :slight_smile:

None? Well that would explain everything :o ...... anyone that can point me in a direction to find some, or toss me code so I can add into my project, I'll thank in advance.
Thxs

You should post a link to the display. The more technical the info the better. The picture doesn't make it obvious what it is.

Thxs for the suggestion ChrisTenone

I’ve attached a link to the serial display I’m using and also added a photo of the display

I would really like to have a proper code for my project and learn more about coding. I have viewed tutorials and tried my own code, but been failing to get it correct.

If there are any takers out there, I can offer a small paypal transfer for the code that would work with my project. With a proper code I would be able to read through and learn from it.

So, any takers out there, I am offer a paypal transfer.
Thxs