Hello all,
This is my first post and I am fairly new to Arduino and all that programming stuff, so be bear with me. I am trying to write some code for a hypothetical fusion reactor. I read about a linear accelerator used for fusion by a company called Helion Energy in Popular Mechanics.(http://www.popularmechanics.com/science/energy/next-generation/is-fusion-power-finally-for-real-2) It inspired me to research and theorize my own version of Helion's reactor. A very basic exploration would be that it takes the two linear accelerators and puts them into a circle with the electromagnets at even spacing. I want an exponential function to turn of and on the electromagnets to accelerate the deuterium plasma, but I'm going to substitute the electromagnets with LEDs for demonstration purposes. The process I came up with is as follows:
1) setup exponential funtion: t(.5)^x t= time x= cycle number
2) substitute whatever starting time for t, e.g. 10000(.5)^x
3) substitute first cycle number for x, e.g. 10000(.5)^1 = 5000
4) take output of function (5000) and put into delay() function
digitalWrite(ledPin1, HIGH);
delay(5000)
5) do this for 1 cycle (for 15 leds)
e.g.
digitalWrite(ledPin1, HIGH);
delay(5000)
digitalWrite(ledPin1, LOW);
delay(5000)
digitalWrite(ledPin2, HIGH);
delay(5000)
digitalWrite(ledPin2, LOW);
delay(5000)
ect...
6) after the first number cycle take the cycle number and add 1 to it, then put it in for x ,
e.g. 10000(.5)^2 = 2500
7) take the answer (2500) and repeat steps 4-6
8) do this x amount of times
Thank you for reading, I would really appreciate some help as this is beyond my code writing abilities.
It shouldnt be complicated math, its a simple exponential function, just multiplication and raising numbers to different powers, then just substituting numbers in different places. Please explain why that is too complicated for an Arduino, cause I don't see the problem.
Paranemertes:
It shouldnt be complicated math, its a simple exponential function, just multiplication and raising numbers to different powers, then just substituting numbers in different places. Please explain why that is too complicated for an Arduino, cause I don't see the problem.
Well as long as the calculation can work with the precision limit of the Arduino float variable. Note that double is the same as float in the arduino platform. As you are going to use LEDs to simulate the rotating field, speed is most likely not a great problem, as if to fast you wouldn't sense movement at all. ;)
Note that there are other math libraries avalible if required, trade-off is the normal memory space and speed hit one may have to take.
Ummmmm.... yeah, I am not familiar w/that. Like I said, pretty new to this. What I want is a function that will cut the time delay between LED's in half every cycle. I guess I could just write the entire output of what I described the function to do, but I am trying to learn more and break away from just manually writing all the code for it.
Once you properly define the equation, implementing it in code is trivial. The Arduino's ability to solve the equation, and produce the answers that you expect are two different issues. Keeping the variable type consistent and correct goes a long way towards solving the second issue (as does realistic expectations). The first issue is the nature of the beast.
Like it says on the side of my posts, I'm a newbie. That function works, because its not written in Arduino syntax, I don't know how to write it in the syntax, that's why I am asking for help on the forum.
Then it is time to start debugging. Changing things to see how that affects different parts of the code. Add in Serial.print() statements (and use the IDE's Serial Monitor) to see what is happening where.
Something to consider, the calculation you are using doesn't really make much sense.
myTime is set to 10000 and cycleCount increments on each loop (as long as the input pin is in a HIGH state.)
So the
int myTime=10000;
long answer = pow((myTime*0.5),cycleCount);
The first iteration of your code cycleCount is 0, so answer will be:
answer = pow((10000*0.5), 0) = pow(5000,0) = 1.
This means your LED will be on for 1 milliseconds and off for 2 milliseconds. (You won't be able to see this happen.)
Second iteration:
answer = pow((10000*0.5), 1) = pow(5000, 1) = 5000.
LED will be on for 5000ms and then off for 5000ms.
Third iteration:
answer = pow((10000*0.5), 2) = pow(5000, 2) = 25,000,000.
LED will be on for 25000000 milliseconds and off for 25000000 millseconds. (That's 25,000 seconds or 416 minutes.)
Since you are observing stable 10-second intervals this tells you something isn't working as expected. So maybe a first step is use a calculation that yields a reasonable delay. Then work on if the math is working correctly.