Simple logic

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

August 6th, 2009, 8:51 am #1

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
Quote
Like
Share

Galleon
Galleon

August 6th, 2009, 1:20 pm #2

*I never got past line 4...
Quote
Share

Pete
Pete

August 6th, 2009, 5:03 pm #3

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.
Quote
Share

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

August 6th, 2009, 5:03 pm #4

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.
Quote
Like
Share

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

August 6th, 2009, 6:08 pm #5

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.
Quote
Like
Share

Anon
Anon

August 7th, 2009, 1:38 am #6

* You need FreeBasic for that.
* Wait, what?
Quote
Share