Chaotic damped pendulum

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "TFT_4DGL.h"
00002 
00003 TFT_4DGL lcd(p9,p10,p11);
00004 
00005 int main() {
00006 
00007     double x1,y1,z1,x,y,z,dt;
00008     int   xp,yp,sl,sk;
00009    
00010     float a = 0.6;
00011     float b = 0.005;
00012     float c = 0.7;
00013 
00014     x1 = 0;
00015     y1 = 0;
00016     z1 = 0;
00017 
00018     sl = 0;
00019     sk = 0;
00020     
00021     dt = 0.05;
00022 
00023     while(1)
00024     
00025     {
00026     
00027         x = x1+(y1)*dt;
00028         y = y1+(-sin(x1)-b*y1+a*cos(c*z1))*dt;
00029         z = z1+(c)*dt;
00030 
00031         yp = (int)floor(y*25);
00032         xp = (int)floor(yp*sin(x));
00033         
00034         if (sk==5) {
00035         
00036         lcd.pixel(120+(yp/2),sl,RED);
00037         
00038         sk=0;
00039         sl++;
00040         
00041         if (sl==320) {
00042         
00043         sl=0;
00044         
00045         lcd.cls();
00046       
00047         }
00048        
00049    }
00050         lcd.pixel(120+yp,160+xp,WHITE);
00051 
00052         sk++;
00053       
00054         x1 = x;
00055         y1 = y;
00056         z1 = z;
00057 
00058     }
00059  
00060 }