# Simple logic

Joined: August 6th, 2009, 8:46 am
Dear folks

Although I have reasonable experience I have been unable to solve this "simple" problem, must be my age?

I thought perhaps you would help me solving a "simple" logic problem in Basic.
It is.....

1. A switch is open
2. The switch closes
3. Log the event
4. Go back to start
5. Is the switch open?
6. If so watch it until it closes again
7. Log the event...etc etc

Problem I can't solve is to disregard switch closed after first time until it has opened and closed again.

I want to monitor the number of times the switch has closed, opened and closed again.

At the moment as I cycle round it logs the switch closure every time, even though it has only been closed once.

Hope you can help with a bit of code

Rgds

Mike Denton

Galleon
Galleon
*I never got past line 4...

Pete
Pete
Dear folks

Although I have reasonable experience I have been unable to solve this "simple" problem, must be my age?

I thought perhaps you would help me solving a "simple" logic problem in Basic.
It is.....

1. A switch is open
2. The switch closes
3. Log the event
4. Go back to start
5. Is the switch open?
6. If so watch it until it closes again
7. Log the event...etc etc

Problem I can't solve is to disregard switch closed after first time until it has opened and closed again.

I want to monitor the number of times the switch has closed, opened and closed again.

At the moment as I cycle round it logs the switch closure every time, even though it has only been closed once.

Hope you can help with a bit of code

Rgds

Mike Denton
* You need FreeBasic for that.

Joined: April 24th, 2004, 8:26 pm
Dear folks

Although I have reasonable experience I have been unable to solve this "simple" problem, must be my age?

I thought perhaps you would help me solving a "simple" logic problem in Basic.
It is.....

1. A switch is open
2. The switch closes
3. Log the event
4. Go back to start
5. Is the switch open?
6. If so watch it until it closes again
7. Log the event...etc etc

Problem I can't solve is to disregard switch closed after first time until it has opened and closed again.

I want to monitor the number of times the switch has closed, opened and closed again.

At the moment as I cycle round it logs the switch closure every time, even though it has only been closed once.

Hope you can help with a bit of code

Rgds

Mike Denton
See if something like this will work:

CONST FALSE = 0
DIM swch AS INTEGER, chng AS INTEGER, lg AS INTEGER
swch = FALSE
chng = swch
CLS
DO
swch = NOT swch
IF chng <> swch THEN lg = lg + 1
LOOP UNTIL swch = chng
PRINT lg
END

However, if you place DO above the swch = FALSE line, you will get an overflow error.
Last edited by Solitaire1 on August 6th, 2009, 5:05 pm, edited 1 time in total.

Joined: February 2nd, 2006, 10:38 pm
Dear folks

Although I have reasonable experience I have been unable to solve this "simple" problem, must be my age?

I thought perhaps you would help me solving a "simple" logic problem in Basic.
It is.....

1. A switch is open
2. The switch closes
3. Log the event
4. Go back to start
5. Is the switch open?
6. If so watch it until it closes again
7. Log the event...etc etc

Problem I can't solve is to disregard switch closed after first time until it has opened and closed again.

I want to monitor the number of times the switch has closed, opened and closed again.

At the moment as I cycle round it logs the switch closure every time, even though it has only been closed once.

Hope you can help with a bit of code

Rgds

Mike Denton
You will get a pulse only when the switch closes. Once the voltage evens out across the capacitor, there is no change. When the switch is open, the resistor will pull the capacitor voltage to ground and it is ready for the next pulse.

I hope the voltage is pretty low. You could try using an opto-coupler if it is low enough to light an led.

Anon
Anon
* You need FreeBasic for that.
* Wait, what?