I am trying to program my 7 segment LED display to display a number, based on the number of times a button is pressed.
For Example: Press the Button three times, a 3 appears on the LED display.
I wanted a pretty simple code and I am thinking using an interrupt will work. BTW I am new to the forums and to the Arduino UNO.
const int aPIN = 9;
const int bPIN = 8;
const int cPIN = 7;
const int dPIN = 10;
const int ePIN = 11;
const int fPIN = 13;
const int gPIN = 12;
const int buttonPIN = 2; // I left this in here from when i was trying this same idea with ridiculous if statements and booleans
int pressCount; // I tried this as a volatile but it didn't seem to work
void setup()
{
pinMode(aPIN, OUTPUT);
pinMode(bPIN, OUTPUT);
pinMode(cPIN, OUTPUT);
pinMode(dPIN, OUTPUT);
pinMode(ePIN, OUTPUT);
pinMode(fPIN, OUTPUT);
pinMode(gPIN, OUTPUT);
attachInterrupt(0, count, RISING); // I tried the first value set to both 2 and 0 neither worked
}
void loop()
{
int pressCount = 0; // I think this is my issue:
// 1. void count can't edit this var because it is in my loop.
// 2. everytime this loop runs it resets the pressCount to 0
// So If i move this statement to the bottom it should work right?
// Wrong Becuase apparently void count will not edit vars in void loop
unsigned long readTime = 0; // Stores run time at beginning of loop for read time, resets it everytime the loop runs
readTime = millis();
if ((readTime == 7000) && (pressCount == 1)) // 7 second to press the button 1 time, this code is only for testing 1 press = the number 1 to appear
{
digitalWrite(bPIN, HIGH);
digitalWrite(cPIN, HIGH);
}
}
void count()
{
pressCount = (pressCount + 1);
}
If you read my comments on " int pressCount = 0; "
and go to http://arduino.cc/en/Reference/AttachInterrupt and look at the code on this page it makes me think that voids can edit variables across each other...
Any Ideas?
Thanks!