Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Simplistic reaction timer

Status
Not open for further replies.
Looking at the docs and website, there is a user programmed ISR on change module/routine, if i got everything correct then this is simply downloaded and added. So how come you didnt use that Mr Deb? I have SF downloaded, the one got cha for me is the SD card is only in the full version? Not too big a problem, but our first project was going to log some data to SD card... I will have a rethink on the first project.

I used to like the C18 sd card routine but mc seems to have dropped alot of the libs. I might end up buying the full version if this proves successful. £50 is cheap Jon, but not at this time of year. Everything i got is tied up in oils and stock ready for the county shows. We are hoping to win a good few county shows this year. We are entering alot of the big competitions to get the name out there some more.

This bad weather lately has wrecked my tomato plants in the tunnel, 2000 hydroponic plants had it. Nightmare to catch up again, need a heating unit on the main water feed as it froze in the tunnel this year!

moved my **** out of here to this thread....

https://www.electro-tech-online.com/threads/swordfish-thread.153553/

would hate to derail a already complex thread such as this.
 
Last edited:
I am still trying to understand Jon's suggestion

this looks like it might work but INC THE LEDONTIME? where is the loop?? Am sure I am missing something and the button press?


MrDEB, this is just a snipet to illustrate the key point you are missing. Read the variable names carefully, every letter. They are extremely descriptive of the function each. It's not

Code:
Inc(LEDOnTime)

It's

Code:
Inc(LedOnTimeCount)

If you can't follow the logic in those few lines, further discussion is pointless.

Serious question: Have you had your vision checked recently? If you are struggling to read the words, that would partially explain why you are having so much difficulty.

I am done. If you can't follow this, maybe someone else will explain it, or perhaps guide you in another method. I will not contine wasting hundreds of hours trying to help when you won't make the effort to understand 5 lines or to even look at your posts to see if they need editing.
 
Interesting how you dont have to have Dim declared at the program start, but it automatically gets included!
 
Interesting how you dont have to have Dim declared at the program start, but it automatically gets included!


It's to illustrate what he needs. Nothing more than that. Your 9 year old sister could explain what those lines should do I'm pretty sure.
 
It's to illustrate what he needs. Nothing more than that. Your 9 year old sister could explain what those lines should do I'm pretty sure.
Unfortunately not, i asked her and she thinks
Inc(LEDOnTime)
Has something to do with a how long a led is on for, maybe i should wait until she is older ;).
 
I didn't want to screw it up.
No one said you did. You run into the same problems every time, what i was saying was..........Its time to change how to approach the learning. Forget this project or that project, start with the June bug and take small steps, simple loops to flash a led, then more complex loops to flash the led, then use a timer to flash the led, then try using a switch to turn on the led then off, then try interrupts and so on.

Currently this is what happens

You post an idea and a splodge of code, jon etal tell you the splodge is meaningless and post working code, you take the working code and sprinkle your splodge of code over it.

What you should do is use the code they post, dont alter it dont try and improve it with a splodge. just use it, then once its working try altering ONE thing in it and see what that does, and so on. If it wasnt for Jon and a couple of others your hobby would be dead, start paying good attention to what they are saying.
 
I take suggested code and work from there. It's not like I just start from scratch. I run suggested code THEN investigate what and why it works then I make adjustments as needed.
Jons recent code suggestion looks interesting and I have the posted code already in the works to see what it needs to run.
 
While I agree with what LGM says about learning from the beginning, that's not going to happen.

Let's expand on this a little. I won't go beyond this, so I encourage MrDEB to go over this the THINK his way through the steps. What I posted before is a concept to get rid of all the delays that prevent reading switches. Starting from this concept:

SmartSelectImage_2018-04-17-07-40-50.png


First, we'll need to declare variables for EACH LED color.

Code:
Dim RedLEDOn as Boolean        
//True means you want the LED on

Dim RedLEDOnTime as Word
//The time you want the LED to be on.
//This can be different each time you turn it on

Dim RedLEDOnTimeCount as Word
//this is a counter of how long the LED has been on

Repeat this for green, yellow, blue....whatever colors you have.

At the end of your program loop, we put the following, a separate block for each color.

Code:
If RedLEDOn = true then
     inc(RedLEDOnTimeCount)
     if (RedLEDOnTimeCount > RedLEDOnTime then
               RedLEDOn = False
               RedLED = (whatever state turns it off)
               RedLEDOnTimeCount = 0
     end if
end if

If GreenLEDOn = true then
     inc(GreenLEDOnTimeCount)
     if (GreenLEDOnTimeCount > GreenLEDOnTime then
               GreenLEDOn = False
               GreebLED = (whatever state turns it off)
               GreenLEDOnTimeCount = 0
     end if
end if

//repeat the block for all colors

And finally you can either add THE ONLY DELAY IN THE LOOP or the timer routine to generate 1mS events. Let's go the delay route.

Code:
DelayMS(1)

Wend

The above code handles only keeping the LEDs on the length of time you want them on. Read it. Think about what happens when you want an LED or several LEDs on. Take your time. I will wait until you understand it.

Stop. Do what I said. Line by line, go through the above until you understand what's happening.

Understand it? Ok, now we move on to turning on LEDs on. Nothing changes in your logic of the switches. That part is on you.

If I recall, you turn on the green LED for 3 seconds to start the process. We need a few lines to do that.

Code:
If (switch pressed) then //this part is on you

    GreenLEDOnTime = 3000
    GreenLEDOn = True
    GreenLED = (whatever turn it on)

End If

When this gets to the block at the end, the block at the end will keep track of how long the LED is on, and turn it off at the right time.

Let's say somebody presses the switch too early. The logic is on you, but this is how you control the LEDs.

Code:
If (button pressed too early) then
    RedLEDOnTime = 5000
    RedLEDOn = True
    RedLED = (whatever turns it on)
    GreenLEDOn = false
    GreenLED = (whatever turns it off)
    //required since the LED didn't time out

I hope this helps. I urge you to go through this step by step, as many times as it takes to understand it.

I'm not going to help you with your logic or anything other than turning the LEDs on for the desired time. This is as clear as I can make it.
 
I take suggested code and work from there. It's not like I just start from scratch. I run suggested code THEN investigate what and why it works then I make adjustments as needed.
Jons recent code suggestion looks interesting and I have the posted code already in the works to see what it needs to run.
That is your issue, look at it this way. You have a broken car and take it to get it fixed, the mechanic fixes it. Then most people drive it until it breaks again. You dont take a car and get it fixed, THEN take it home and FIX it some more!!!

Can you see what i mean? use working code as it is, it isnt a starting point, its IT, its the whole thing working. It dosnt need any more working on its done. What i said was once you see it working then MAYBE try and alter a tiny bit and see what that bit does. I see what Jon has posted and he is being real kind. But after this project FFS go back to the very basics of basic. Three things true in life, Death, Tax and shortcuts are always the longest way around something.
 
I tried using Jons suggested code but felt it was too busy with all the BOOLEAN this and that so using most of the posted suggestion I came up with a smooth running code that sequencly turns on the yellow leds and polls the switch every 1ms.
Sorry I messed up the suggested code but IMO came up with a better mouse trap.
basic code text
WHILE true
REPEAT
Yellow1 = 1 //first yellow led
IF button1 = 0 THEN //poll the switch BUTTON1 IF PRESSED BEFORE GREEN LED THEN SUBROUTINE FOUL
FOUL()
END IF
DELAYMS(1)
INC (LEDOn1_TimeCount)
UNTIL
LEDOn1_TimeCount >= LEDOn_Time //NEED TO INSERT RANDOM # HERE FOR LEDON_TIME
Yellow1=0
LEDOn1_TimeCount = 0
Count = Count +1 //count = 2

REPEAT
Yellow2 = 1 //second yellow led
IF button1 = 0 THEN //poll the switch BUTTON1 IF PRESSED BEFORE GREEN LED THEN SUBROUTINE FOUL
FOUL()
END IF
DELAYMS(1)
INC (LEDOn1_TimeCount)
UNTIL
LEDOn1_TimeCount >= LEDOn_Time
Yellow2=0
LEDOn1_TimeCount=0
Count = Count +1 //count = 3

REPEAT
Yellow3 = 1 //third yellow
IF button1 = 0 THEN ////poll the switch BUTTON1 IF PRESSED BEFORE GREEN LED THEN SUBROUTINE FOUL
FOUL()
END IF
DELAYMS(1)
INC (LEDOn1_TimeCount)
UNTIL
LEDOn1_TimeCount >= LEDOn_Time
Yellow3=0
LEDOn1_TimeCount=0
Count = Count +1 //count = 4
//start ISR
 
....felt it was too busy with all the BOOLEAN this and that.....

...IMO came up with a better mouse trap....


We have vastly different standands for "better mouse trap" and what constitutes "working."

I'm glad you managed to get something "working" and in only 4 pages on the forum. That's got to be a record! Now if you could just get code tags working, so somebody could decipher your code!

One last time, forget what you think people have told you. To make code tags work to get this:

Code:
'This is code

      'Indenting code make it easier to follow
      'As does white space, to separate sections

You type exactly this:

SmartSelectImage_2018-04-23-04-31-51.png

Alas, my efforts attempting to help you are a giant waste of effort, so have fun guys!
 
Last edited:
I tried using Jons suggested code but felt it was too busy with all the BOOLEAN this and that so using most of the posted suggestion I came up with a smooth running code that sequencly turns on the yellow leds and polls the switch every 1ms.
Sorry I messed up the suggested code but IMO came up with a better mouse trap.
Yep you did indeed come up with a better mouse trap, its just a shame you were trying to make a reaction timer instead of a mouse trap ;).
 
Jons suggested code I tried and it worked but I felt the boolean command was getting carried away. IMO Jon has started using boolean more than he used to, which is ok but his code ignited a spark which I used some of his code suggestions and came up with a usable working and easy to understand code. I used a for next loop two weeks or so before Jons posted suggestion in post #70 but it too wasn't right but it was headed in the right direction but Jon steered me straight as usual
 
Jons suggested code I tried and it worked but I felt the boolean command was getting carried away. IMO Jon has started using boolean more than he used to, which is ok but his code ignited a spark which I used some of his code suggestions and came up with a usable working and easy to understand code. I used a for next loop two weeks or so before Jons posted suggestion in post #70 but it too wasn't right but it was headed in the right direction but Jon steered me straight as usual


I really dont know what to say to that..... you felt he used too much Boolean?? Before you make judgments like this, please firat make sure you understand what a interupt is and what boolean is, the only command you seem to use is Dim. Your code is totally full of Dim. Seriously go back and read it, there is so much Dim in the code its almost 90% Dim and 10% Random.

Although I admit your code loops a great deal, mainly from one form of Dim to another form of Dim. OR maybe it dosnt, AND i have it wrong, it dosnt matter Nor does it interest me. :D

So i guess the next project you can handle yourself now.....
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top