I’m very new to arduino and know essentially nothing about coding, but I’m trying to create a counter. I want the counter to be count up by ones (starting at zero) and count every time the limit switch is pressed. I would like to have my counter count the number of times the limit switch is pressed in one minute then display the total and reset after about 5 seconds. If the code with the timing is too complicated to fix, I’ve tried to move on to a counter that will simply display the number of times the limit switch has been pressed after it’s been pressed (almost like a deli counter).
I have the following code for the timing attempt but when I press the limit switch nothing happens.
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int x=0;
int count=0;
boolean i=false;
void setup()
{
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
pinMode(10,INPUT);
}
void input()
{
if(INPUT>2)
{
i = true;
}
else
{
i =false;
}
}
void timer ()
{
delay(1000);
x=x+1;
if (i==true)
{
lcd.clear();
int count=count+1;
lcd.print(count);
}
if (x=6000)
{
lcd.clear();
lcd.print(count);
delay (3000);
timer ();
}
}
void loop ()
{
input();
timer();
}
The following code is for my simpler counter but I keep getting error messages on it. I also am not sure how to make it loop.
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int x=0;
int count=0;
boolean i=false;
void setup()
{
lcd.begin(16, 2) // start the library
lcd.setCursor(0,0)
pinMode(2,INPUT)
pinMode(2,LOW);
}
int count=0;
void count ()
{
if (readDigital (10)=HIGH)
count=count+1;
lcd.print(count);
}
The error messages are:
Arduino: 1.6.3 (Windows 7), Board: "Arduino Uno"
Build options changed, rebuilding all
counter.ino:5:5: error: 'int count' redeclared as different kind of symbol
counter.ino:5:6: error: previous declaration of 'void count()'
counter.ino: In function 'void setup()':
counter.ino:11:2: error: expected ';' before 'lcd'
counter.ino: At global scope:
counter.ino:16:5: error: 'int count' redeclared as different kind of symbol
counter.ino:5:6: error: previous declaration of 'void count()'
counter.ino: In function 'void count()':
counter.ino:20:22: error: 'readDigital' was not declared in this scope
counter.ino:21:8: error: assignment of function 'void count()'
counter.ino:21:8: error: cannot convert 'void (*)()' to 'void()' in assignment
counter.ino:22:18: error: call of overloaded 'print(void (&)())' is ambiguous
counter.ino:22:18: note: candidates are:
In file included from C:\Program Files\Arduino\libraries\LiquidCrystal\src/LiquidCrystal.h:5:0,
from counter.ino:2:
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:61:12: note: size_t Print::print(char) <near match>
size_t print(char);
^
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:61:12: note: no known conversion for argument 1 from 'void()' to 'char'
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:62:12: note: size_t Print::print(unsigned char, int) <near match>
size_t print(unsigned char, int = DEC);
^
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:62:12: note: no known conversion for argument 1 from 'void()' to 'unsigned char'
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:63:12: note: size_t Print::print(int, int) <near match>
size_t print(int, int = DEC);
^
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:63:12: note: no known conversion for argument 1 from 'void()' to 'int'
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:64:12: note: size_t Print::print(unsigned int, int) <near match>
size_t print(unsigned int, int = DEC);
^
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:64:12: note: no known conversion for argument 1 from 'void()' to 'unsigned int'
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:65:12: note: size_t Print::print(long int, int) <near match>
size_t print(long, int = DEC);
^
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:65:12: note: no known conversion for argument 1 from 'void()' to 'long int'
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:66:12: note: size_t Print::print(long unsigned int, int) <near match>
size_t print(unsigned long, int = DEC);
^
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:66:12: note: no known conversion for argument 1 from 'void()' to 'long unsigned int'
Error compiling.
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Perhaps, I simply didn’t put everything together correctly (hardware-wise) and the first code is correct?
Any help would be greatly appreciated.