Operation Game Counter
hey guys,
i'm relatively new arduino, have been trying build device counts amount of times open circuit becomes closed, similar game operation. have been using arduino uno along sainsmart lcd shield make device have run problem. have programmed arduino based on other hit counters on web time high voltage registered on a1 pin, lcd should count 1 digit. however, when place voltage on a1 pin, device counts larger number depending on how long set delay(right counts 23). hoping might able give me suggestions of why might happening. based code off of plans found online of code might seem unnecessary or confusing , first part of loop when "select" button on shield pressed, lcd counts 1 , works perfectly. here code:
#include <liquidcrystal.h>
liquidcrystal lcd(8, 13, 9, 4, 5, 6, 7);
int hits = 0;
int switchstate = 0;
int switchstate1;
int prevswitchstate = 0;
int prevswitchstate1 = low;
const int switchpin = a1;
void setup()
{
lcd.begin(16,2);
pinmode(switchpin, input);
lcd.print(" open surgery ");
lcd.setcursor(0,1);
lcd.print(" simulator ");
delay(4000);
lcd.clear();
}
void loop()
{
switchstate = analogread (0);
switchstate1 = digitalread(switchpin);
if (switchstate != prevswitchstate){
if (switchstate < 800 && switchstate > 600)
hits = hits + 1;
lcd.clear();
lcd.setcursor(0,0);
lcd.print("hits:");
lcd.setcursor(6,0);
lcd.print(hits);
delay(100);
}
if (switchstate1 != prevswitchstate1)
{
if (switchstate1 == high)
hits = hits + 1;
lcd.clear();
lcd.setcursor(0,0);
lcd.print("hits:");
lcd.setcursor(6,0);
lcd.print(hits);
delay(100);}
}
i'm relatively new arduino, have been trying build device counts amount of times open circuit becomes closed, similar game operation. have been using arduino uno along sainsmart lcd shield make device have run problem. have programmed arduino based on other hit counters on web time high voltage registered on a1 pin, lcd should count 1 digit. however, when place voltage on a1 pin, device counts larger number depending on how long set delay(right counts 23). hoping might able give me suggestions of why might happening. based code off of plans found online of code might seem unnecessary or confusing , first part of loop when "select" button on shield pressed, lcd counts 1 , works perfectly. here code:
#include <liquidcrystal.h>
liquidcrystal lcd(8, 13, 9, 4, 5, 6, 7);
int hits = 0;
int switchstate = 0;
int switchstate1;
int prevswitchstate = 0;
int prevswitchstate1 = low;
const int switchpin = a1;
void setup()
{
lcd.begin(16,2);
pinmode(switchpin, input);
lcd.print(" open surgery ");
lcd.setcursor(0,1);
lcd.print(" simulator ");
delay(4000);
lcd.clear();
}
void loop()
{
switchstate = analogread (0);
switchstate1 = digitalread(switchpin);
if (switchstate != prevswitchstate){
if (switchstate < 800 && switchstate > 600)
hits = hits + 1;
lcd.clear();
lcd.setcursor(0,0);
lcd.print("hits:");
lcd.setcursor(6,0);
lcd.print(hits);
delay(100);
}
if (switchstate1 != prevswitchstate1)
{
if (switchstate1 == high)
hits = hits + 1;
lcd.clear();
lcd.setcursor(0,0);
lcd.print("hits:");
lcd.setcursor(6,0);
lcd.print(hits);
delay(100);}
}
take @ : http://arduino.cc/en/tutorial/buttonstatechange .
Arduino Forum > Using Arduino > Project Guidance > Operation Game Counter
arduino
Comments
Post a Comment