your correction made the program compile without errors, however now the counting is just not occurring according to the serial monitor. this might be a problem on the physical side since I'm in the process of moving the circuit into its "permanent" home.
To clarify what I want to happen when, I'm using the blink program to run a motor which in turn moves an arm up and down. I'm using the count program to count how many times the arm breaks the photo gates beam. So I need to blink program to run with the count program so that it is counting continuously while the motor runs.
Here is the current code:
//blink without delay
const int ledPin = 9;
int ledState = LOW;
long previousMillis = 0;
long interval = 1000;
// photogate
const int inPinUp = 6;
const int inPinDown = 7;
int channel = 1;
int buttonUpState = 0;
int buttonDownState = 0;
int prevBtnUp = LOW;
int prevBtnDwn = LOW;
unsigned long lastBtnUp = 0;
unsigned long lastBtnDwn = 0;
int transInt = 50;
void setup ()
{
pinMode (ledPin, OUTPUT);
Serial.begin(9600);
pinMode(inPinUp, INPUT);
pinMode(inPinDown, INPUT);
}
void loop ()
{
buttonUpState = digitalRead(inPinUp); //begin photogate
buttonDownState = digitalRead(inPinDown);
if (buttonUpState == HIGH && prevBtnUp == LOW)
{
if (millis() - lastBtnUp > transInt)
{
channel++;
lastBtnUp = millis();
Serial.println(channel);
}
}
prevBtnUp = buttonUpState;
//blink without delay
unsigned long currentMillis = millis ();
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
digitalWrite(ledPin, ledState);
}
}
(and yes I know indenting doesn't do anything for the compiler but it made it easier for me to read)