So I need to make a laser counter to count eggs on a conveyor belt. What I'm trying to achieve is two counters that add up their individual counts and display the sum on an LCD screen. Here is my code below.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
int sensA;
int sensB;
int thresh1;
int ctr = 0;
int timeOfEgg = 1000;
int ledpin = 13;
int inpin = 7;
int val = 0;
unsigned long previousMillis1 = 0;
unsigned long previousMillis2 = 0;
unsigned long currentMillis = millis();
int digVal = digitalRead(inpin);
void setup(){
pinMode(ledpin,OUTPUT);
pinMode(inpin,INPUT);
lcd.begin(16,2);
}
void loop(){
val = digitalRead(inpin);
if(val == LOW){
digitalWrite(ledpin,HIGH);
nmbr1();
nmbr2();
}else{
lcd.setCursor(0,0);
lcd.print(">");
lcd.print(ctr);
lcd.print("< Eggs!");
}
void nmbr1() {
sensA = analogRead(A0);
if(sensA < thresh1){
if(currentMillis - previousMillis1 >= timeOfEgg){
ctr = ctr+1;
previousMillis1 = currentMillis;
lcd.setCursor(0,0);
lcd.print(">");
lcd.print(ctr);
lcd.print("< Eggs!");
}else{
lcd.setCursor(0,0);
lcd.print(">");
lcd.print(ctr);
lcd.print("< Eggs!");
}
}else{
lcd.setCursor(0,0);
lcd.print(">");
lcd.print(ctr);
lcd.print("< Eggs!");
}
void nmbr2(); {
sensB = analogRead(A1);
if(sensB < thresh1){
if(currentMillis - previousMillis2 >= timeOfEgg){
ctr = ctr+1;
previousMillis2 = currentMillis;
lcd.setCursor(0,0);
lcd.print(">");
lcd.print(ctr);
lcd.print("< Eggs!");
}else{
lcd.setCursor(0,0);
lcd.print(">");
lcd.print(ctr);
lcd.print("< Eggs!");
}
}else{
lcd.setCursor(0,0);
lcd.print(">");
lcd.print(ctr);
lcd.print("< Eggs!");
}
However whenever I try to verify the code it comes up with this error:
/home/benjamin/Arduino/eggCounterNoDelay/eggCounterNoDelay.ino: In function 'void loop()':
eggCounterNoDelay:25: error: 'nmbr1' was not declared in this scope
nmbr1();
^
eggCounterNoDelay:26: error: 'nmbr2' was not declared in this scope
nmbr2();
^
eggCounterNoDelay:35: error: a function-definition is not allowed here before '{' token
void nmbr1() {
^
eggCounterNoDelay:78: error: expected '}' at end of input
}
^
exit status 1
'nmbr1' was not declared in this scope
I've got no clue what to do and I'm quite new to Arduino so any help would be greatly appreciated
Thanks