Automatic slide digitsing process using digital camera and a modified projector

I am trying to automate this process as I have over 7000 slides to digitise!

I want 4 buttons each on it’s own digital input to perform 4 functions:-

Start copying
Stop copying and reset all counters
Resume copying from a jammed slide at the same point in the program
Set the total number of slides to copy. I intend to use an analogue input and variable resistor to input the value reading out on screen.

I am using a Nano R3

I have a 2 x 16 line LCD connected by I2C on A4 and A5, digital input pins are as follows:-

D2 - Start
D3 - Stop
D4 - Resume
D5 - Set

D6 - detects a slide jam by monitoring if a slide is in the gate, and if it is not a high is generated.

A1 - analogue input

I have coded the different modules and they all work individually. My problem is reading which button is pressed and selecting the appropriate module.

code below:-

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int analogPin = 1; // potentiometer wiper (middle terminal) connected to analog pin 3
int ctr = 10; // variable to store the value read
int ctdwn =0;
int start = 2;
int stp = 3;
int resum = 4; // assigns names to digital input pins
int set = 5;
int jam = 6;

// Set the LCD address to 0x38 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x38, 16, 2);

void setup()
{
// initialize the LCD
lcd.begin();

// Turn on the blacklight and print a message.

pinMode(start,INPUT);
pinMode(stp,INPUT);
pinMode(resum,INPUT);
pinMode(set,INPUT); //Assigns data direction for digtal pins
pinMode(jam,INPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);

int Statestart = 0;
int Statestop = 0;
int Stateresume =0;
int Stateset = 0;
int Statejam = 0;

lcd.clear();
delay(2000);
}

void loop()
{

Statestart = digitalRead(start);
Statestop = digitalRead(stp);
Stateresume =digitalRead(resum);
Stateset = digitalRead(set);
//Statejam = 0;

if(Statestart == HIGH) {

ctdwn=ctr;
lcd.clear();
for (int i = 0; i <= ctr; i++) {

lcd.backlight();
lcd.print("Total slides “);
lcd.setCursor(13,0);
lcd.print(ctr);
lcd.setCursor(0,1);
lcd.print(“Remaining”);
lcd.setCursor(13,1);
lcd.print(” ");
lcd.setCursor(13,1);
lcd.print(ctdwn);

digitalWrite(7, HIGH); // sets the digital pin 7 on
delay(300); // waits for a second
digitalWrite(7, LOW); // sets the digital pin 7 off
delay(700);
// Check gate
digitalWrite(8, HIGH); // sets the digital pin 8 on
delay(300); // waits for a second
digitalWrite(8, LOW); // sets the digital pin 8 off
delay(700);
// checkstop
ctdwn=ctdwn-1;

}

lcd.clear();
}

else if (Stateset == HIGH)) {

lcd.setCursor (1,0);
lcd.print(“No. of slides”);
lcd.setCursor(7,1);
ctr = analogRead(1); // read the input pin
ctr=ctr / 5;
lcd.print(ctr);
lcd.print(" ");

}

else if (Stateresume == HIGH)){

lcd.clear();
lcd.print(“resume”);
delay(3000);

}

else if (Statestop == HIGH)){

lcd.clear();
lcd.print(“Stop”);
delay(3000);
}

else {

lcd.setCursor(0,0);
lcd.print(“Press button to”);
lcd.setCursor(3,1);
lcd.print(“continue”);
//delay(10000);

}

// Do nothing here…
}

I intended the program to loop through the void loop only switching if a button was pressed. Hoever it always goes straight to the first else if statement andwaits for the number of slides to be set, If I press the start button it correctly goes to the first selection and processes the required number of slides as set in the set module - which functions correctly and allows me to change the number.

Appreciate some guidance on this

Many thansk

Bill

Could be a floating input. Do you have pulldowns in place?

Your code doesn't compile, can you post something that does? In code tags please.

Wrong copy of the code - I had two windows open. Posted below code that does compile and now works! I don’t know what I changed! this has been driving me nuts for about 3 hours!

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int analogPin = 1; // potentiometer wiper (middle terminal) connected to analog pin 3
int ctr = 10; // variable to store the value read
int ctdwn =0;
int start = 2;
int stp = 3;
int resum = 4; // assigns names to digital input pins
int set = 5;
int jam = 6;

int Statestart = 0;
int Statestop = 0;
int Stateresume =0;
int Stateset = 0;
int Statejam = 0;

// Set the LCD address to 0x38 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x38, 16, 2);

void setup()
{
// initialize the LCD
lcd.begin();

// Turn on the blacklight and print a message.

pinMode(start,INPUT);
pinMode(stp,INPUT);
pinMode(resum,INPUT);
pinMode(set,INPUT); //Assigns data direction for digtal pins
pinMode(jam,INPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);

lcd.clear();
delay(2000);
}

void loop()
{

Statestart = digitalRead(start);
Statestop = digitalRead(stp);
Stateresume =digitalRead(resum);
Stateset = digitalRead(set);
//Statejam = 0;

if(Statestart == HIGH) {

ctdwn=ctr;
lcd.clear();
for (int i = 0; i <= ctr; i++) {

lcd.backlight();
lcd.print("Total slides “);
lcd.setCursor(13,0);
lcd.print(ctr);
lcd.setCursor(0,1);
lcd.print(“Remaining”);
lcd.setCursor(13,1);
lcd.print(” ");
lcd.setCursor(13,1);
lcd.print(ctdwn);

digitalWrite(7, HIGH); // sets the digital pin 7 on
delay(300); // waits for a second
digitalWrite(7, LOW); // sets the digital pin 7 off
delay(700);
// Check gate
digitalWrite(8, HIGH); // sets the digital pin 8 on
delay(300); // waits for a second
digitalWrite(8, LOW); // sets the digital pin 8 off
delay(700);
// checkstop
ctdwn=ctdwn-1;

}

lcd.clear();
}

else if (Stateset == HIGH) {

lcd.setCursor (1,0);
lcd.print(“No. of slides”);
lcd.setCursor(7,1);
ctr = analogRead(1); // read the input pin
ctr=ctr / 5;
lcd.print(ctr);
lcd.print(" ");

}

else if (Stateresume == HIGH){

lcd.clear();
lcd.print(“resume”);
delay(3000);

}

else if (Statestop == HIGH){

lcd.clear();
lcd.print(“Stop”);
delay(3000);
}

else {

lcd.setCursor(0,0);
lcd.print(“Press button to”);
lcd.setCursor(3,1);
lcd.print(“continue”);
//delay(10000);

}

// Do nothing here…
}