# trying to piece together 2 bits of code

hi im very new to coding and im trying to piece together 2 separate bits of code for a school project but from what i understand there is no reason they couldn't be modified to work together. what they 2 bits of code are is a speed reaction game and a bit of code that uses an ldr to speed up a light sequence. i wanted the ldr code to be used to speed up the sequence of lights in the reaction game if anyone would be able to help me with this it would be very appreciated.

here are the links to the 2 separate parts;

im trying to piece together 2 separate bits of code for a school project

This is not the homework hot line. YOU are supposed to do your school work. Otherwise, you won't learn anything.

So, what have you tried? Reading an LDR value is trivial.

``````				/* Increase score (speed).
By decreasing the timer interval we increase the speed. */
timerMillis -= 50;
``````

I suspect that you want to subtract something other than 50 on every iteration of the loop, but what the relationship between light level and the value to use in this statement is something that you haven't defined.

hi paul thanks for the quick response i know i should be figuring this all out by myself but my lecturer is away and we havent been given much time to learn arduino yet or for this project so this was my sort of last resort.

i believe the - 50 is for when the player scores a point on the game it speeds it up making it harder. i wanted to implement ldr along side this so the player wouldn't be able to hold there finger on the button as the ldr would be placed next to it, so when the player has their finger covering it the game would get faster making it more difficult

So, somewhere in the code, you need to read the LDR. You need to adjust, somehow, someway, the value in timerMillis (stupid name; millis() returned a value that is NOT a timer) or the value that the code will subtract from timerMillis next time (for whatever next time means).

You still have not defined what you want to change, or how you want to map the LDR value.

i want the ldr to change the speed of how the light sequence. i would have to make it so the ldr would speed up it with a higher resistance(lower light level on the ldr)

so if the ldr was read and showed a high resistance it would change the value of the timerMillis to a lower one i believe to speed up the light sequence

harryberry272:
i want the ldr to change the speed of how the light sequence. i would have to make it so the ldr would speed up it with a higher resistance(lower light level on the ldr)

so if the ldr was read and showed a high resistance it would change the value of the timerMillis to a lower one i believe to speed up the light sequence

Good description. You are almost at the point where you can make the changes, yourself!

It's just logic!

Paul

so if the ldr was read and showed a high resistance it would change the value of the timerMillis to a lower one i believe to speed up the light sequence

Well, of course it would. The question that you steadfastly refuse to answer is BY HOW MUCH?

im not sure how much i would want to change it by yet. i will probably have to test out different amounts and decide which value would give the best result