Help on Scoring

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
andrewr1545
 
Posts: 2
Joined: Wed Nov 14, 2018 4:36 pm

Help on Scoring

Post by andrewr1545 »

Trying to get this code from an earlier project, but instead of an LCD screen I want the LED Segment Backpack to work.

Code: Select all

//
//Compatible with the Arduino IDE 1.0
//Library version:1.1

#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


// this constant won't change:
const int  Up_buttonPin1   = 6;    // the pin that the pushbutton is attached to
const int  Up_buttonPin2 = 7;

// Variables will change:
int buttonPushCounter1 = 0;   // counter for the number of button presses
int up_buttonState1 = 0;         // current state of the up button
int up_lastButtonState1 = 0;     // previous state of the up button

int buttonPushCounter2 = 0;   // counter for the number of button presses
int up_buttonState2 = 0;         // current state of the up button
int up_lastButtonState2 = 0;     // previous state of the up button
                                                                             
int down_buttonState1 = 0;         // current state of the up button    
int down_lastButtonState1 = 0;     // previous state of the up button
bool bPress1 = false;

int down_buttonState2 = 0;         // current state of the up button
int down_lastButtonState2 = 0;     // previous state of the up button
bool bPress2 = false;

void setup()
{
  Serial.begin(9600);
  pinMode( Up_buttonPin1 , INPUT_PULLUP);
  pinMode( Up_buttonPin2, INPUT_PULLUP);
   lcd.begin(16, 2);
 
 
  // Print a message to the LCD.
  lcd.setCursor(0,0);
  lcd.print("Home     Visitor");
  
  
  lcd.setCursor(12,2);
  lcd.print(buttonPushCounter1);
  
  
  lcd.setCursor(2,2);
  lcd.print(buttonPushCounter2);
 
}


void loop()
{
   checkUp1();
   checkUp2();
   
   if( bPress1){
       bPress1 = false;
      lcd.setCursor(0,0);
      lcd.print("Home     Visitor");
      lcd.setCursor(12,2);
      lcd.print(buttonPushCounter1);
   }

   if( bPress2){
       bPress2 = false;
      lcd.setCursor(0,0);
      lcd.print("Home     Visitor");
      lcd.setCursor(2,2);
      lcd.print(buttonPushCounter2);
   }
  
}

void checkUp1()
{
  up_buttonState1 = digitalRead(Up_buttonPin1);

  // compare the buttonState to its previous state
  if (up_buttonState1 != up_lastButtonState1) {
    // if the state has changed, increment the counter
    if (up_buttonState1 == LOW) {
        bPress1 = true;
      // if the current state is HIGH then the button went from off to on:
      buttonPushCounter1++;
      Serial.println("on");
      Serial.print("number of button pushes: ");
      Serial.println(buttonPushCounter1);
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  up_lastButtonState1 = up_buttonState1;
}

void checkUp2()                                                                         
{
  up_buttonState2 = digitalRead(Up_buttonPin2);

  // compare the buttonState to its previous state
  if (up_buttonState2 != up_lastButtonState2) {
    // if the state has changed, increment the counter
    if (up_buttonState2 == LOW) {
        bPress2 = true;
      // if the current state is HIGH then the button went from off to on:
      buttonPushCounter2++;
      Serial.println("on");
      Serial.print("number of button pushes: ");
      Serial.println(buttonPushCounter2);
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  up_lastButtonState2 = up_buttonState2;
}

User avatar
kcl1s
 
Posts: 1512
Joined: Tue Aug 30, 2016 12:06 pm

Re: Help on Scoring

Post by kcl1s »

You do not say if you are using one 7-seg display or 2. This example code can give you a good idea of the changes you need to make. https://github.com/adafruit/Adafruit_LE ... venseg.ino.

Fellow hobbyist
Keith

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”