# Exponential Functions for Fusion Acceleration

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.

You are aware that this is an 8 bit microcontroller that doesn't quite like big numbers and complicated maths, right?

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.

http://arduino.cc/en/Reference/Float

Lefty

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.

10000(.5)^1 = 5000

10000(.5)^2 = 2500

I think your calculator needs new batteries...

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.

There's the "pow" function. http://arduino.cc/en/Reference/Pow

yeah, I know about the math functions, I think this is how one would write the function in Arduino syntax:

10000 * 0.5 pow(variable1) == variable2

But I am really not sure, that's my best guess. Can someone confirm that? thanks

You aren't writing in "Arduino Syntax" you are writing in "C".

" 10000 * 0.5 pow(variable1) == variable2"

In C "==" is an equality operator. You use it to compare two values. So this statement doesn't make sense.

Ok, thanks. yeah see I dont really know much about this. how would one actually write the function?

Paranemertes: Ok, thanks. yeah see I dont really know much about this. how would one actually write the function?

I would recommend one use the keyboard on their PC. ;)

``````int myTime=10000;
int cycleCount=0;
int ledPin1 = 13;

void setup() {
// whatever
}

void loop() {
cycleCount++;
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin1, LOW);
}
``````

Wow, thanks James C4S, that's really helpful. If was going to teat this on one LED with a push button starting the process would this work?

int myTime=10000; int cycleCount=0; int ledPin1 = 13; int buttonState = 0; const int buttonPin = 2;

void setup() { pinMode(ledPin1, OUTPUT); pinMode(buttonPin, INPUT); }

void loop() {

if (buttonState == HIGH) {

cycleCount++; long answer = pow((myTime*0.5),cycleCount); digitalWrite(ledPin1, HIGH); delay (answer); digitalWrite(ledPin1, LOW); delay (answer); } else { digitalWrite(ledPin1, LOW); } }

-thanks

Ok, well that code didn't work. The LED flashed on for 10 seconds and then off for 10 seconds then back on and didn't turn off. Any suggestions?

Change “myTime”, “cycleCount”, and “answer” to unsigned long.

Does the behavior change?

No, like I said it blinks the LED on for 10 seconds, off for 10 seconds, then on for as long as I care to watch it, which was about 3 minutes.

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;
``````

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.

Yeah, maybe you can help me with this too, I have never used the Serial.print() function, but I will give it my best.

I gave this a try, but all I got was a repeating '0' popping up on the serial monitor.

unsigned long int myTime=10000; unsigned long int cycleCount=0;

void setup() { Serial.begin(9600); }