Você está na página 1de 9

Sumber: http://forum.arduino.cc/index.php?topic=168375.

0
/*
Chaos Theory on your Scope!
Displays the lorenz attractor on your Oscilloscope.
Author: Chris Gozzard (cgozzard@yahoo.com)
Created: 25-5-13
License: This code CC-BY-SA 3.0 and is unsupported.
(see creativecommons.org/licenses for info)
the following circuit is on both PWM ports (5 and 6)
R
PWM OUT ----/\/\/\-----+------------ OUTPUT
|
=== C
|
GND
R = 10k
C = 0.1uF
Many thanks to John M. De Cristofaro for the original idea (based on his Oscilloscope
Christmas Tree circuit)
*/
float x_pos;
float y_pos;
int x_out = 5;
int y_out = 6;
float x = 0.7;
float y = 0;
float z = 0;
float alpha = 15.6;
int beta = 28;
float m0
= -1.143;
float m1
= -0.714;
float xdot;
float ydot;
float zdot;
float h;
float dt = 0.01;
void setup() {
pinMode(x_out, OUTPUT);
pinMode(y_out, OUTPUT);
// this next section changes the PWM frequency - don't mess with it!

TCCR0A = (1<<COM0A1 | 0<<COM0A0 |


(hi-lo PWM)
1<<COM0B1 | 0<<COM0B0 |
(hi-lo PWM)
1<<WGM01 | 1<<WGM00);

// clear OC0A on compare match


// clear OC0B on compare match
// set PWM lines at 0xFF

TCCR0B = ( 0<<FOC0A | 0<<FOC0B |


// no force compare match
0<<WGM02 |
// set PWM lines at 0xFF
0<<CS02
| 0<<CS01 |
// use system clock (no divider)
1<<CS00 );
TIMSK0 = (

0<<OCIE0B | 0<<TOIE0 |
0<<OCIE0A );

}
void loop() {
xdot = alpha*(y-x-h);
ydot = x - y + z;
zdot = (-beta)*y;
h = (m1*x)+(0.5*(m0-m1))*(abs(x+1)-abs(x-1));
x = x + (xdot*dt);
y = y + (ydot*dt);
z = z + (zdot*dt);

x_pos = 128+(50 * x);


y_pos = 128+(50 * y);
analogWrite(x_out, x_pos);
analogWrite(y_out, y_pos);
}

/*
Chaos Theory on your Scope!
Displays the lorenz attractor on your Oscilloscope.
Author: Chris Gozzard (cgozzard@yahoo.com)
Created: 25-5-13
License: This code CC-BY-SA 3.0 and is unsupported.
(see creativecommons.org/licenses for info)
the following circuit is on both PWM ports (5 and 6)
R
PWM OUT ----/\/\/\-----+------------ OUTPUT
|
=== C
|
GND
R = 10k
C = 0.1uF
Many thanks to John M. De Cristofaro for the original idea (based on his Oscilloscope
Christmas Tree circuit)
*/
int
int
int
int

x_pos;
// can be int
y_pos;
// can be int
x_out = 5;
y_out = 6;

float x = 0.70;
float y = 0;
float z = 0;
float
float
float
float
float

dt = 0.01;
alpha = 15.60 *dt; // precalculate the *dt
beta = -28*dt; // precalculate the * dt and the - sign
m0
= -1.143;
m1
= -0.714;

float m2 = 0.5 * (m0-m1); // precalculated const


float xdot;
float ydot;
float zdot;
float h;

void setup()
{
Serial.begin(115200);
pinMode(x_out, OUTPUT);
pinMode(y_out, OUTPUT);
// this next section changes the PWM frequency - don't mess with it!
TCCR0A = ( 1<<COM0A1 | 0<<COM0A0 |
// clear OC0A on compare match
(hi-lo PWM)
1<<COM0B1 | 0<<COM0B0 |
// clear OC0B on compare match (hi-lo PWM)
1<<WGM01 | 1<<WGM00);
// set PWM lines at 0xFF
TCCR0B = ( 0<<FOC0A | 0<<FOC0B |
// no force compare match
0<<WGM02 |
// set PWM lines at 0xFF
0<<CS02
| 0<<CS01 |
// use system clock (no divider)
1<<CS00 );
TIMSK0 = ( 0<<OCIE0B | 0<<TOIE0 |
0<<OCIE0A );
}
void loop()
{
float a = y-x;
// precalculate for reuse
xdot = alpha * (a-h);
ydot = (z-a) * dt;
zdot = beta * y;
h = (m1 * x) + m2 * (abs(x + 1) - abs(x - 1));
x = x + xdot;
y = y + ydot;
z = z + zdot;
x_pos = 128 + (int)(50*x);
y_pos = 128 + (int)(50*y);
analogWrite(x_out, x_pos);
analogWrite(y_out, y_pos);
}

Sumber: http://www.4thharmonic.com/Lorenz%20Attractor%20-%20Arduino%20code.txt
/* Lorenz Attractor - James Dunn
* Created 31/12/2008
* Uses Edward Lorenz's original equations:
*
* dx/dt=s(y-x)
* dy/dt=rx-y-xz
* dz/dt=xy-bz
*
* where s =10, r=28, and b=8/3.
* Starting values for x,y and z are 0,1, and 0 respectively
*/
#define TIMER_CLK_DIV1
float s = 10;
float r = 28;
float b = 8/3;
float x = 0;
float y = 1;
float z = 0;
float xn = 0;
float yn = 1;
float zn = 0;
float dt = 0.005;
int xout = 0;
int zout = 0;

0x01
//
//
//
//
//
//
//
//
//
//
//
//

// Timer clocked at F_CPU

declare value for s


declare value for r
declare value for b
declare starting value for x
declare starting value for y
declare starting value for z
next value for x
next value for y
next value for z
declare value for dt
declare value for xout
declare value for zout

void setup()
{
TCCR1B = (TCCR1B & ~0x07) | TIMER_CLK_DIV1;
}
void loop()
{
xn = s*(y-x);
yn = (r*x)-y-(x*z);
zn = (x*y)-(b*z);
x = x+xn*dt;
y = y+yn*dt;
z = z+zn*dt;
xout = x*6+128;
zout = z*4;
analogWrite(9, xout);
analogWrite(10, zout);
}

//
//
//
//
//
//
//
//
//
//

calculate next x value


calculate next y value
calculate next z value
add xn to x and multiply by
add yn to y and multiply by
add zn to z and multiply by
increase resolution and add
increase resolution
write x PWM wave to pin 9
write z PWM wave to pin 10

time factor
time factor
time factor
offset

Sumber: http://ogahide.blogspot.com/2013/03/my-first-arduino-projectlorenz.html
//Lorenz attracctor
//Mar 3, 2013
//Parameters from Xppaut (http://www.math.pitt.edu/~bard/xpp/xpp.html)
const int LEDx=9;
const int LEDy=10;
const int LEDz=11;
//variables
float x=-7.5;
float y=-3.6;
float z=30;
float newx;
float newy;
float newz;
//parameters
const float r=27;
const float s=10;
const float b=2.66666;
float brightness_x;
float brightness_y;
float brightness_z;
const float dt=0.025;
float
float
float
float
float
float

maxX=x+1;
minX=x-1;
maxY=y+1;
minY=y-1;
maxZ=z+1;
minZ=z-1;

void setup(){
pinMode(LEDx,OUTPUT);
pinMode(LEDy,OUTPUT);
pinMode(LEDz,OUTPUT);
}
void loop(){
maxX=max(maxX,x);
minX=min(minX,x);
maxY=max(maxY,y);
minY=min(minY,y);
maxZ=max(maxZ,z);
minZ=min(minZ,z);
//exponential Euler
newx=exp(-s*dt)*x+(1-exp(-s*dt))*y;// dx/dt=s*(-x+y)
newy=exp(-dt)*y+(1-exp(-dt))*x*(r-z);// dy/dt=r*x-y-x*z
newz=exp(-b*dt)*z+(1-exp(-b*dt))*x*y;// dz/dt=-b*z+x*y

x=newx;
y=newy;
z=newz;

//sending the values to Serial


Serial.print(x,4);
Serial.print(" ");
Serial.print(y,4);
Serial.print(" ");
Serial.print(z,4);
Serial.print("\n");

//setting the intensity of LEDs


brightness_x=255*(x-minX)/(maxX-minX);
brightness_y=255*(y-minY)/(maxY-minY);
brightness_z=255*(z-minZ)/(maxZ-minZ);
analogWrite(LEDx,brightness_x);
analogWrite(LEDy,brightness_y);
analogWrite(LEDz,brightness_z);
delay(30);

Sumber: http://jlswbs.blogspot.com/2011/12/hyper-lorenz.html

http://www.worldacademicunion.com/journal/1749-3889-3897IJNS/IJNSVol08No1Paper18.pdf
http://www.arduino.cc/
http://excamera.com/sphinx/gameduino/
-------------------------------------------------------------------------------------------------------------#include "SPI.h"
#include "GD.h"
byte
float
float
float
float
float
float
float
float
float
float
float
float
float

i;
a = 10;
b = 8/3;
c = 30;
d = 10;
x = 1;
y = 1;
z = 1;
w = 1;
xn = x;
yn = y;
zn = z;
wn = w;
dt = 0.005;

void setup()
{
GD.begin();
GD.ascii();
GD.wr16(RAM_SPRPAL + (0 * 2), 0x8000);
GD.wr16(RAM_SPRPAL + (1 * 2), RGB(255, 255, 255));
GD.fill(RAM_SPRIMG, 0, 256);
GD.wr(RAM_SPRIMG + 0x78, 1);
GD.putstr(15, 1, "Hyper-Lorenz attractor");
}
void loop()
{
xn = a*(y-x);
yn = x*(c-z)-y+w;
zn = x*y-b*z;
wn = -d*x;
x = x+xn*dt;
y = y+yn*dt;
z = z+zn*dt;

w = w+wn*dt;
GD.sprite (i++,200+(8*x),10+(4.5*z),0,0,0);
}

Você também pode gostar