I presume as we had dropped the word OPTO that every OPEN and every CLOSED would then also work backwards to what we currently have. In this case every switch would work incorrectly.
You do understand the code that examines the Opto Sensor needs to be modified ?
//======================================================================== OptoSensor.pin
currentState = digitalRead(OptoSensor.pin);
//===================================
//has this switch changed state ?
if (OptoSensor.lastState != currentState)
{
OptoSensor.counter++;
//is this change in state stable ?
if (OptoSensor.counter >= filter)
{
//get ready for the next sequence
OptoSensor.counter = 0;
//update to this new state
OptoSensor.lastState = currentState;
//========================
//did this Opto sensor close ?
if (currentState == OPTOclosed)
{
Serial.println("Opto Sensor Has Closed");
}
//========================
//did this switch open ?
else if (currentState == OPTOopened)
{
Serial.println("Opto Sensor has Opened");
}
}
}
//===================================
//a valid switch change has not been confirmed
else
{
OptoSensor.counter = 0;
}
//END of OptoSensor.pin
} //END of checkSwitches()
I was aware that we needed to change the code but i couldn't work out where.
I had looked at the macro initially because we had used OPTO in the definition so didn't think it would effect the wider system as you described if we removed OPTO.
What i cant locate is where we are telling the system that the optical beam is normally made and then to register zero when broken.
I have updated my optoSensor.pin section of code to match the above and im struggling to work out where the initial current state is determined. even if i swap the (currentState == OPTOclosed)
around with //did this switch open ? else if (currentState == OPTOopened)
I am still not getting the desired effect.
Any Clues?
FIrstly, that find bar is awesome, thank you. Along with Ctrl T yesterday, are there any other shortcuts i need to know as i didn't know any when we started.
So we need to change the OPENED to CLOSED.
I then needed to find the correct location to tell the motor to stop when this changes.
So on line 384
//has the OptoSensor gone OPENED ?
if (OptoSensor.lastState == OPENED) {
//reset the "Reset State Machine"
resetMachine = ResetFinished;
I changed this part of the code and bingo!
It now works.
Im not getting the reset part of code in the serial monitor though.
So i am currently looking at the checkmachine around line 444 to see if there is something in that.
stepIndex = 7;
}
//has the OptoSensor gone CLOSED ?
if (OptoSensor.lastState == CLOSED)
{
//reset the "Reset State Machine"
resetMachine = ResetFinished;
//we are done, disable this TIMER
stepperTIMER.disableTIMER();
stepIndex = 7;
}
//has the OptoSensor gone CLOSED ?
if (OptoSensor.lastState == CLOSED)
{
//reset the "Reset State Machine"
resetMachine = ResetFinished;
//we are done, disable this TIMER
stepperTIMER.disableTIMER();
What needs to be done ?
That is where i removed the gone CLOSED ?
and
if (OptoSensor.lastState == CLOSED)
and replaced it with
//has the OptoSensor gone OPENED ?
if (OptoSensor.lastState == OPENED)
stepIndex = 7;
}
//has the OptoSensor gone CLOSED ?
if (OptoSensor.lastState == CLOSED)
{
//reset the "Reset State Machine"
resetMachine = ResetFinished;
//we are done, disable this TIMER
stepperTIMER.disableTIMER();
The 2nd code found should be changed to:
stepIndex = 7;
}
//has the OptoSensor gone CLOSED ?
if (OptoSensor.lastState == OPTOclosed)
{
//reset the "Reset State Machine"
resetMachine = ResetFinished;
//we are done, disable this TIMER
stepperTIMER.disableTIMER();
What we are doing is, for the Opto Sensor only, changing all the CLOSED Macros to OPTOclosed and OPENED Macros to OPTOopened
At this point the changes made should get your setup working.
yes it does work as desired perfectly.
the only thing that is not occurring is the system reset message is not being printed in the serial monitor any longer.
Does that effect the way the system operates?
on line 323 under setup
//configure the output pins
for (byte x = 0; x < sizeof(outputPins); x++) {
digitalWrite(outputPins[x], LOW);
pinMode(outputPins[x], OUTPUT);
}
Serial.println("System Reset");
Is it not appearing because we have set this section as only writing 'system reset' when the pin goes LOW?
Im not sure why else this is nolonger occurring. although im also unsure of the above as it refers to an output pin and a sensor is an input. so even in writing this i think its wrong. But i cant find 'system reset' other than this entry.
There is a subtle item which we must consider.
In the setup( ) routine the following code turns on pullup resistors for all switch inputs.
//======================
//use INPUT_PULLUP so the pin does not float, floating pins can cause faulty readings
//configure the input pins
for (byte x = 0; x < sizeof(inputPins); x++)
{
pinMode(inputPins[x], INPUT_PULLUP);
}
The schematic below, I think, is your Opto Sensor
Since the LM339 has a pull up resistor on the board we do not need to turn on the pin 18 pull up resistor (where your Opto sensor is connected).
Suggest you change this line of code from this:
Ok 18 removed from the code.
I dont believe there are any ive missed. But can you please clarify the areas i mentioned in post #176. Just so i know im understanding everything.
Also, you mention the opto sensor has an internal pullup resistor. Are you referring to the 10k attached to the '-' pin of LM393 and ground?
I know from my understanding of these resistors that effectively the LM393 would compare its + and - pins to give a 0 or 1 output.