Hi Everyone.
I have been playing with Arduino for a year now and have been able to make a few little projects. I learned about edge detection and was able to make a rain gauge using a tip bucket and a nano with a lcd display. I want to add one more thing to it but am having trouble. For the sake of test I have a nano with 2 buttons attached. Button 1 is the set point for the amount of rain to trigger another action like fire a relay. Button 2 acts as the tip bucket rain gauge. I really don't know or may not fully understand how the code is looping. When I run the code I can click button one and make it count but once I click button 2 i am no longer able to click button 1 and make it change. Also when I click button 2 it does not count up for me. I was wondering if this is the best way to go about it or should I have 3 buttons. On detection that button one is high it would let me set the set point for the rain fall amount then use button 3 to simulate the tip bucket. Here is my code thanks so much for the help.
const int buttonApin = 2;
const int buttonBpin = 3;
const int relaypin = 5;
// Variables
int tipbucketcount = 0;//for setting fall shutoff
int buttonAcounter = 0;// counter for the number of button presses
int buttonBcounter = 0;// counter for setting the amount of rain fall that is required to trip the well
int buttonAstate = 0;//current state of button A
int buttonBstate = 0;// current state of button B
int lastbuttonAstate = 0; //previous state of the A button
int lastbuttonBstate = 0;// previous state of the B button
float rainamount = 0;//current amount of rain collected
float shutdown = 0; //Reading from the pot for the amount to kill motor at
void setup() {
pinMode(buttonApin, INPUT); // initialize the button pin as a input:
pinMode(buttonApin, INPUT);
//for (int i = 0; i < 255; i++)
// EEPROM.write(i, i);
Serial.begin(9600);
buttonBstate = digitalRead(buttonBpin);
}
void loop() {
buttonAstate = digitalRead(buttonApin);
if (buttonAstate != lastbuttonAstate) {
if (buttonAstate == HIGH) {
buttonAcounter++;
}
}
lastbuttonAstate = buttonAstate;
if (buttonBstate != lastbuttonBstate) {
if (buttonBstate == HIGH) {
buttonBcounter++;
}
lastbuttonBstate = buttonBstate;
}
Serial.print(buttonAcount);
Serial.print(" ------------- ");
Serial.println(buttonBcount);
}