Not a teensy but i need help on this.
I have one of those dev board aliexpress 38pin jobs. The controller is labled ESP-32. How is it possible that I get this terminal output (when the PE input is pulsed on and off:
edit: To save you some time, let me say, just look at where the print statements are made and then the if statement block that they are in, and the printout. The complete program is there so once you are hooked in you can go through it all and share in my frustration or put me on the correct path.
With this program (complete) compiled using arduino ide:
To be clear, what i think i'm seeing is Serial.print(deltaTime) showing deltatime to be 0 from inside an if statement block where the condition requires deltatime to be greater than 1000.
In addition to that an if condition that will print in the case that deltaTime is less than 1000 is not being printed despite print showing that it is 0.
What's more, when performing the test I can clearly tell that the terminal is printing immediately when my photo eye input is made/not made. That is there is no 1000ms delay.
I'm thinking i have a wrong board selected or some compiler weirdness that i have created. Has anyone got any ideas. I've been at it for a few days.
Thanks.
Gavin
I have one of those dev board aliexpress 38pin jobs. The controller is labled ESP-32. How is it possible that I get this terminal output (when the PE input is pulsed on and off:
Code:
deltaTime = 0
This should not be happening!
deltaTime = 0
This should not be happening!
edit: To save you some time, let me say, just look at where the print statements are made and then the if statement block that they are in, and the printout. The complete program is there so once you are hooked in you can go through it all and share in my frustration or put me on the correct path.
With this program (complete) compiled using arduino ide:
Code:
#define PE_INPUT 13
unsigned long peDebounceStartTime = 0; //millis when debounce timer was started
bool lastPeState = false;
bool currentPeState = false;
bool debounceStarted = false;
unsigned long deltaTime = 0;
unsigned long currentTime = 0;
void setup() {
pinMode(PE_INPUT,INPUT_PULLUP);
Serial.begin(115200);
}
bool readPeWithDebounce()
/*
* Returns the debounced state of the Photo eye input.
*/
{
bool peState = digitalRead(PE_INPUT);
currentTime = millis();
if (peState != lastPeState) //We should debounce this
{
if (debounceStarted == false) // must be first loop since peState changed
{
debounceStarted = true;
peDebounceStartTime = currentTime;
}
else //Debounce has already started
{
deltaTime = currentTime - peDebounceStartTime;
if(deltaTime > 1000)
{
if(deltaTime < 1000)
{
Serial.print("deltaTime is less than 1000 and has a value of:");
Serial.println(deltaTime);
}
Serial.print("deltaTime = ");
Serial.println(deltaTime);
Serial.println("This should not be happening!");
return peState;
}
}
}
else
{
debounceStarted = false;
return lastPeState;
}
}
void loop() {
lastPeState = currentPeState;
currentPeState = readPeWithDebounce();
}
To be clear, what i think i'm seeing is Serial.print(deltaTime) showing deltatime to be 0 from inside an if statement block where the condition requires deltatime to be greater than 1000.
In addition to that an if condition that will print in the case that deltaTime is less than 1000 is not being printed despite print showing that it is 0.
What's more, when performing the test I can clearly tell that the terminal is printing immediately when my photo eye input is made/not made. That is there is no 1000ms delay.
I'm thinking i have a wrong board selected or some compiler weirdness that i have created. Has anyone got any ideas. I've been at it for a few days.
Thanks.
Gavin
Last edited: