Multiple digital input issue?

Hi all,

Currently having a bit of an issue bringing some code together. I have two separate devices if you will, that I want to run on the same arduino. The first is an oled screen that displays a message which changes to a bitmap qr code for a few seconds after button is pressed:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>


Adafruit_SSD1306 display(128, 64, &Wire);


const unsigned char myBitmap [] PROGMEM = {
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x77, 0x61, 0x98, 0x3e, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x36, 0x61, 0x98, 0x1c, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0x38, 0x01, 0xe1, 0xec, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0x38, 0x01, 0xe1, 0xec, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x30, 0x7f, 0xe7, 0x9c, 0xc0, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x30, 0x7f, 0xe7, 0xbc, 0xc0, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x30, 0x66, 0x78, 0x7c, 0xc0, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x30, 0x66, 0x78, 0x7c, 0xc0, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x37, 0x86, 0x18, 0x04, 0xc0, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x37, 0x86, 0x18, 0x04, 0xc0, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0x3e, 0x19, 0xe7, 0x84, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xfe, 0x3e, 0x19, 0xe7, 0x84, 0x7f, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x36, 0x66, 0x66, 0x64, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x76, 0x66, 0x46, 0xe6, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x67, 0x81, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x23, 0x81, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf0, 0x0f, 0x36, 0x01, 0x81, 0xf3, 0xc0, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xfc, 0x1f, 0xf6, 0x20, 0x07, 0xb0, 0xc1, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xfc, 0x3f, 0xf6, 0x60, 0x07, 0x90, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xfc, 0xf0, 0x70, 0x00, 0xc3, 0xf0, 0x30, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xfc, 0xf0, 0x30, 0x01, 0xe1, 0xf0, 0x30, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf8, 0x0f, 0xf8, 0x3f, 0xff, 0xe7, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf0, 0x0f, 0xf8, 0x7f, 0xff, 0xe7, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xfc, 0x03, 0x00, 0x66, 0x78, 0xf3, 0xb3, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xfc, 0x03, 0x00, 0x66, 0x78, 0x73, 0x33, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf0, 0xf3, 0x8f, 0x86, 0x60, 0x30, 0x30, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf0, 0xf3, 0xcf, 0x86, 0x60, 0x10, 0x30, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xcf, 0x06, 0x19, 0xe7, 0x84, 0xf3, 0x0f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xcf, 0x02, 0x19, 0xe7, 0x84, 0xf3, 0x0f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xc1, 0x9e, 0x07, 0x90, 0xcf, 0x0f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xc1, 0x9e, 0x07, 0x90, 0xcf, 0x0f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0x3c, 0x37, 0xe6, 0x18, 0x07, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0x3c, 0x77, 0xe6, 0x18, 0x07, 0x8f, 0x0f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xfe, 0x7e, 0x79, 0x83, 0xf3, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xfe, 0x7e, 0x79, 0x83, 0xf3, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xf0, 0x0e, 0x78, 0x00, 0x73, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xfb, 0xe0, 0x0e, 0x38, 0x00, 0x73, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0xc6, 0x18, 0x18, 0x63, 0xc0, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0xc2, 0x18, 0x38, 0x61, 0xc0, 0x7f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xfc, 0xfc, 0x31, 0xf8, 0x7e, 0x60, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x71, 0xfc, 0xf8, 0xe0, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, 0xff, 0xf9, 0xe7, 0xc3, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x79, 0xff, 0xe7, 0x86, 0xc7, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x39, 0xfe, 0x67, 0x84, 0xcf, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xfe, 0x3e, 0x00, 0x67, 0x87, 0xcf, 0xdf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0x3e, 0x00, 0x67, 0x87, 0xcf, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x3e, 0x0f, 0xe0, 0x40, 0x0c, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x3e, 0x1f, 0xe0, 0x60, 0x0c, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x37, 0x99, 0x98, 0x67, 0x0c, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x37, 0x99, 0x98, 0x67, 0x0c, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x30, 0x66, 0x60, 0x13, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x30, 0x66, 0x60, 0x13, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0x33, 0xe1, 0xfe, 0x63, 0xc3, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0x33, 0xe1, 0xfe, 0x61, 0xc3, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x31, 0x9f, 0xe7, 0xe0, 0xcf, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x71, 0x9f, 0xe7, 0xe0, 0xcf, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};

const int buttonPin = 6;
int pushCounter = 0;
int buttonState = 0 ;

void setup() {

  Serial.begin(9600);
  pinMode(buttonPin, INPUT);

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);

    display.clearDisplay();
    delay(2000);

  }
}
void loop() {

  buttonState = digitalRead(buttonPin);
  Serial.println(buttonState);


  if (buttonState == HIGH) {

    pushCounter++;
  }

  if (pushCounter == 1)  {

    delay(1000);
    display.clearDisplay();
    display.drawBitmap(0, 0, myBitmap, 128, 64, WHITE);
    display.display();

    delay(10000);
    display.clearDisplay();
    pushCounter = 0;
  }`Preformatted text`
  if (pushCounter == 0) {
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(WHITE);

    display.setCursor(30, 5);
    display.println("Welcome to");

    display.setTextSize(2);
    display.setCursor(15, 20);

    display.println("Mi Waste");
    display.setCursor(10, 50);

    display.setTextSize(1);
    display.println("recycling rewards");
    display.display();
  }
}

The second is a digital scale which uses load cells to measure a weight, the values of which are output to an LCD screen:

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

#define DT 4
#define SCK 5
#define sw 2

long sample = 0;
float val = 0;
long count = 0;

unsigned long readCount(void)
{
  unsigned long Count;
  unsigned char i;
  pinMode(DT, OUTPUT);
  digitalWrite(DT, HIGH);
  digitalWrite(SCK, LOW);
  Count = 0;
  pinMode(DT, INPUT);
  while (digitalRead(DT));
  for (i = 0; i < 24; i++)
  {
    digitalWrite(SCK, HIGH);
    Count = Count << 1;
    digitalWrite(SCK, LOW);
    if (digitalRead(DT))
      Count++;
  }
  digitalWrite(SCK, HIGH);
  Count = Count ^ 0x800000;
  digitalWrite(SCK, LOW);
  return (Count);
}

void setup()
{
  Serial.begin(9600);
  pinMode(SCK, OUTPUT);
  pinMode(sw, INPUT_PULLUP);
  lcd.begin(16, 2);
  lcd.print("    Weight ");
  lcd.setCursor(0, 1);
  lcd.print(" Measurement ");
  delay(1000);
  lcd.clear();
  calibrate();
}

void loop()
{
  count = readCount();
  int w = (((count - sample) / val) - 2 * ((count - sample) / val));
  Serial.print("weight:");
  Serial.print((int)w);
  Serial.println("g");
  lcd.setCursor(0, 0);
  lcd.print("Weight            ");
  lcd.setCursor(0, 1);
  lcd.print(w);
  lcd.print("g             ");

  if (digitalRead(sw) == 0)
  {
    val = 0;
    sample = 0;
    w = 0;
    count = 0;
    calibrate();
  }
}

void calibrate()
{
  lcd.clear();
  lcd.print("Calibrating...");
  lcd.setCursor(0, 1);
  lcd.print("Please Wait...");
  for (int i = 0; i < 100; i++)
  {
    count = readCount();
    sample += count;
    Serial.println(count);
  }
  sample /= 100;
  Serial.print("Avg:");
  Serial.println(sample);
  lcd.clear();
  lcd.print("Put 100g & wait");
  count = 0;
  while (count < 1000)
  {
    count = readCount();
    count = sample - count;
    Serial.println(count);
  }
  lcd.clear();
  lcd.print("Please Wait....");
  delay(2000);
  for (int i = 0; i < 100; i++)
  {
    count = readCount();
    val += sample - count;
    Serial.println(sample - count);
  }
  val = val / 100.0;
  val = val / 100.0;    // put here your calibrating weight
  lcd.clear();
}

Both sets of code work perfectly on their own, however in my attempts to merge them, I have been unable to change the oled screen after the button press:

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

#define DT 4
#define SCK 5
#define sw 2

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 display(128, 64, &Wire);


long sample = 0;
float val = 0;
long count = 0;

const unsigned char myBitmap [] PROGMEM = {
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x77, 0x61, 0x98, 0x3e, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x36, 0x61, 0x98, 0x1c, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0x38, 0x01, 0xe1, 0xec, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0x38, 0x01, 0xe1, 0xec, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x30, 0x7f, 0xe7, 0x9c, 0xc0, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x30, 0x7f, 0xe7, 0xbc, 0xc0, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x30, 0x66, 0x78, 0x7c, 0xc0, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x30, 0x66, 0x78, 0x7c, 0xc0, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x37, 0x86, 0x18, 0x04, 0xc0, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x37, 0x86, 0x18, 0x04, 0xc0, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0x3e, 0x19, 0xe7, 0x84, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xfe, 0x3e, 0x19, 0xe7, 0x84, 0x7f, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x36, 0x66, 0x66, 0x64, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x76, 0x66, 0x46, 0xe6, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x67, 0x81, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x23, 0x81, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf0, 0x0f, 0x36, 0x01, 0x81, 0xf3, 0xc0, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xfc, 0x1f, 0xf6, 0x20, 0x07, 0xb0, 0xc1, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xfc, 0x3f, 0xf6, 0x60, 0x07, 0x90, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xfc, 0xf0, 0x70, 0x00, 0xc3, 0xf0, 0x30, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xfc, 0xf0, 0x30, 0x01, 0xe1, 0xf0, 0x30, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf8, 0x0f, 0xf8, 0x3f, 0xff, 0xe7, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf0, 0x0f, 0xf8, 0x7f, 0xff, 0xe7, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xfc, 0x03, 0x00, 0x66, 0x78, 0xf3, 0xb3, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xfc, 0x03, 0x00, 0x66, 0x78, 0x73, 0x33, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf0, 0xf3, 0x8f, 0x86, 0x60, 0x30, 0x30, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf0, 0xf3, 0xcf, 0x86, 0x60, 0x10, 0x30, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xcf, 0x06, 0x19, 0xe7, 0x84, 0xf3, 0x0f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xcf, 0x02, 0x19, 0xe7, 0x84, 0xf3, 0x0f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xc1, 0x9e, 0x07, 0x90, 0xcf, 0x0f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xc1, 0x9e, 0x07, 0x90, 0xcf, 0x0f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0x3c, 0x37, 0xe6, 0x18, 0x07, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0x3c, 0x77, 0xe6, 0x18, 0x07, 0x8f, 0x0f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xfe, 0x7e, 0x79, 0x83, 0xf3, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xfe, 0x7e, 0x79, 0x83, 0xf3, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xf0, 0x0e, 0x78, 0x00, 0x73, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xfb, 0xe0, 0x0e, 0x38, 0x00, 0x73, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0xc6, 0x18, 0x18, 0x63, 0xc0, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0xc2, 0x18, 0x38, 0x61, 0xc0, 0x7f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xfc, 0xfc, 0x31, 0xf8, 0x7e, 0x60, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x71, 0xfc, 0xf8, 0xe0, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, 0xff, 0xf9, 0xe7, 0xc3, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x79, 0xff, 0xe7, 0x86, 0xc7, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x39, 0xfe, 0x67, 0x84, 0xcf, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xfe, 0x3e, 0x00, 0x67, 0x87, 0xcf, 0xdf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0x3e, 0x00, 0x67, 0x87, 0xcf, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x3e, 0x0f, 0xe0, 0x40, 0x0c, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x3e, 0x1f, 0xe0, 0x60, 0x0c, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x37, 0x99, 0x98, 0x67, 0x0c, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x37, 0x99, 0x98, 0x67, 0x0c, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x30, 0x66, 0x60, 0x13, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0x03, 0x30, 0x66, 0x60, 0x13, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0x33, 0xe1, 0xfe, 0x63, 0xc3, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0x33, 0xe1, 0xfe, 0x61, 0xc3, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x31, 0x9f, 0xe7, 0xe0, 0xcf, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x71, 0x9f, 0xe7, 0xe0, 0xcf, 0x3f, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};

const int buttonPin = 6;
int pushCounter = 0;
int buttonState = 0 ;

unsigned long readCount(void)
{
  unsigned long Count;
  unsigned char i;
  pinMode(DT, OUTPUT);
  digitalWrite(DT, HIGH);
  digitalWrite(SCK, LOW);
  Count = 0;
  pinMode(DT, INPUT);
  while (digitalRead(DT));
  for (i = 0; i < 24; i++)
  {
    digitalWrite(SCK, HIGH);
    Count = Count << 1;
    digitalWrite(SCK, LOW);
    if (digitalRead(DT))
      Count++;
  }
  digitalWrite(SCK, HIGH);
  Count = Count ^ 0x800000;
  digitalWrite(SCK, LOW);
  return (Count);
}

void setup() {


  Serial.begin(9600);

  pinMode(buttonPin, INPUT);

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);

    display.clearDisplay();
    delay(2000);

  }

  pinMode(SCK, OUTPUT);
  pinMode(sw, INPUT_PULLUP);
  lcd.begin(16, 2);
  lcd.print("    Weight ");
  lcd.setCursor(0, 1);
  lcd.print(" Measurement ");
  delay(1000);
  lcd.clear();
  calibrate();
}

void loop()
{
  count = readCount();
  int w = (((count - sample) / val) - 2 * ((count - sample) / val));
  Serial.print("weight:");
  Serial.print((int)w);
  Serial.println("g");
  lcd.setCursor(0, 0);
  lcd.print("Weight            ");
  lcd.setCursor(0, 1);
  lcd.print(w);
  lcd.print("g             ");

  if (digitalRead(sw) == 0)
  {
    val = 0;
    sample = 0;
    w = 0;
    count = 0;
    calibrate();
  }
}

void calibrate()
{
  lcd.clear();
  lcd.print("Calibrating...");
  lcd.setCursor(0, 1);
  lcd.print("Please Wait...");
  for (int i = 0; i < 100; i++)
  {
    count = readCount();
    sample += count;
    Serial.println(count);
  }
  sample /= 100;
  Serial.print("Avg:");
  Serial.println(sample);
  lcd.clear();
  lcd.print("Put 100g & wait");
  count = 0;
  while (count < 1000)
  {
    count = readCount();
    count = sample - count;
    Serial.println(count);
  }
  lcd.clear();
  lcd.print("Please Wait....");
  delay(2000);
  for (int i = 0; i < 100; i++)
  {
    count = readCount();
    val += sample - count;
    Serial.println(sample - count);
  }
  val = val / 100.0;
  val = val / 100.0;    // put here your calibrating weight
  lcd.clear();

  buttonState = digitalRead(buttonPin);
  Serial.println(buttonState);


  if (buttonState == HIGH) {

    pushCounter++;
  }

  if (pushCounter == 1)  {

    delay(1000);
    display.clearDisplay();
    display.drawBitmap(0, 0, myBitmap, 128, 64, WHITE);
    display.display();

    delay(10000);
    display.clearDisplay();
    pushCounter = 0;

  }

  if (pushCounter == 0) {
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(WHITE);

    display.setCursor(30, 5);
    display.println("Welcome to");

    display.setTextSize(2);
    display.setCursor(15, 20);

    display.println("Mi Waste");
    display.setCursor(10, 50);

    display.setTextSize(1);
    display.println("recycling rewards");
    display.display();
  }

}

My thinking was that due to the arduino reading the values of the load cells via a digital input, it can't also read the button state at the same time, i.e you can't read two separate digital inputs at once. Would this be correct? If not im hoping this may just be a formatting error.

Would really appreciate any help or advice you can give,
ThanksPreformatted text

P.S sorry about the formatting, im not too familiar with this page and wasn't sure how to isolate the code from the rest of the text in my post

can you explain the problem?

Hi,

the problem im having is that when I bring the two pieces of code shown above, at least in the format that I currently have them set as, the arduino doesn't seem to be reading the state of the button, therefore pressing the button isn't doing anything. my thinking was that because the arduino is continuously reading the input values from the load cells, it can't also read the state of the button i.e, won't ever know when the button is high

Hello
did you you design a buttonHandler that delivers the information about "button pressed".
If not, I gues that type handler is missing in your sketch.

In the IDE, click Tools>Auto format, then Edit>Copy to forum. Then you can paste code into your post and it will appear in a box with a scroll bar. Please edit your original post and do that, because it takes an age to scroll down past your post!

you have both a buttonPin and sw. are there 2 buttons?

it's conventional to connect a button switch between ground and the pin and configure the pin as INPUT_PULLUP so that it is normally HIGH and pulled LOW when pressed.

furthermore, it's conventional to maintain a button state and only recognize when pressed (not held) when there's a change in state and the button is LOW.

can you explain what your using your buttons for and how you are monitoring them?

Hi,

That should be everything formatted properly, thanks for the tip!

What happens in readCount? That while loop has the potential to wait a while looking for LOW and if it does, it will be hard to press the other button at the right moment to catch it.

What happened to this line?

  }`Preformatted text`

Your code to check the button attached to pin 6 and display the qr code is only executed as part of your calibrate() function. That function only gets called when the button attached to pin 2 is pressed. I think you meant to put the pin 6/display qr code into loop() not into calibrate().

Hi Paul,

Yes that was the issue, thanks for your help!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.