Clifford chaotic attractor - uVGAII(SGC) 4DGL version 640x480 pin p9 - rx, pin p10 - tx, pin p11 - rst

Dependencies:   mbed

Committer:
JLS
Date:
Sat Sep 03 14:44:19 2011 +0000
Revision:
0:21ffd53de6c8

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JLS 0:21ffd53de6c8 1 #include "mbed.h"
JLS 0:21ffd53de6c8 2
JLS 0:21ffd53de6c8 3 Serial _cmd (p9, p10);
JLS 0:21ffd53de6c8 4 DigitalOut _rst (p11);
JLS 0:21ffd53de6c8 5
JLS 0:21ffd53de6c8 6 void startVGA();
JLS 0:21ffd53de6c8 7 void baudrate();
JLS 0:21ffd53de6c8 8 void cls();
JLS 0:21ffd53de6c8 9 void pixel(int, int, int);
JLS 0:21ffd53de6c8 10 int writeCOM(char *, int);
JLS 0:21ffd53de6c8 11
JLS 0:21ffd53de6c8 12
JLS 0:21ffd53de6c8 13 int main() {
JLS 0:21ffd53de6c8 14
JLS 0:21ffd53de6c8 15 startVGA ();
JLS 0:21ffd53de6c8 16
JLS 0:21ffd53de6c8 17 float x = 1;
JLS 0:21ffd53de6c8 18 float y = 1;
JLS 0:21ffd53de6c8 19
JLS 0:21ffd53de6c8 20 float ix = 0;
JLS 0:21ffd53de6c8 21 float iy = 0;
JLS 0:21ffd53de6c8 22
JLS 0:21ffd53de6c8 23 float a = -1.4;
JLS 0:21ffd53de6c8 24 float b = 1.6;
JLS 0:21ffd53de6c8 25 float c = 1;
JLS 0:21ffd53de6c8 26 float d = 0.7;
JLS 0:21ffd53de6c8 27
JLS 0:21ffd53de6c8 28 while (1) {
JLS 0:21ffd53de6c8 29
JLS 0:21ffd53de6c8 30 ix = sin(a*y) - c*cos(a*x);
JLS 0:21ffd53de6c8 31 iy = sin(b*x) - d*cos(b*y);
JLS 0:21ffd53de6c8 32
JLS 0:21ffd53de6c8 33 pixel(375+(180*ix),255+(150*iy),65534);
JLS 0:21ffd53de6c8 34
JLS 0:21ffd53de6c8 35 x = ix;
JLS 0:21ffd53de6c8 36 y = iy;
JLS 0:21ffd53de6c8 37
JLS 0:21ffd53de6c8 38 }
JLS 0:21ffd53de6c8 39 }
JLS 0:21ffd53de6c8 40
JLS 0:21ffd53de6c8 41
JLS 0:21ffd53de6c8 42 void startVGA () {
JLS 0:21ffd53de6c8 43
JLS 0:21ffd53de6c8 44 _rst = 1;
JLS 0:21ffd53de6c8 45 _rst = 0;
JLS 0:21ffd53de6c8 46 wait_ms(1);
JLS 0:21ffd53de6c8 47 _rst = 1;
JLS 0:21ffd53de6c8 48 wait(3);
JLS 0:21ffd53de6c8 49
JLS 0:21ffd53de6c8 50 while (_cmd.readable()) _cmd.getc();
JLS 0:21ffd53de6c8 51
JLS 0:21ffd53de6c8 52 char autobaud[1] = "";
JLS 0:21ffd53de6c8 53 autobaud[0] = '\x55';
JLS 0:21ffd53de6c8 54 writeCOM(autobaud, 1);
JLS 0:21ffd53de6c8 55
JLS 0:21ffd53de6c8 56 baudrate();
JLS 0:21ffd53de6c8 57
JLS 0:21ffd53de6c8 58 cls();
JLS 0:21ffd53de6c8 59
JLS 0:21ffd53de6c8 60 char dispctr[3]= "";
JLS 0:21ffd53de6c8 61 dispctr[0] = '\x59';
JLS 0:21ffd53de6c8 62 dispctr[1] = 0x0c;
JLS 0:21ffd53de6c8 63 dispctr[2] = 0x01;
JLS 0:21ffd53de6c8 64 writeCOM(dispctr, 3);
JLS 0:21ffd53de6c8 65
JLS 0:21ffd53de6c8 66 }
JLS 0:21ffd53de6c8 67
JLS 0:21ffd53de6c8 68
JLS 0:21ffd53de6c8 69 void pixel(int x, int y, int color) {
JLS 0:21ffd53de6c8 70
JLS 0:21ffd53de6c8 71 char pixel[7]= "";
JLS 0:21ffd53de6c8 72
JLS 0:21ffd53de6c8 73 pixel[0] = '\x50';
JLS 0:21ffd53de6c8 74
JLS 0:21ffd53de6c8 75 pixel[1] = (x >> 8) & 0xFF;
JLS 0:21ffd53de6c8 76 pixel[2] = x & 0xFF;
JLS 0:21ffd53de6c8 77
JLS 0:21ffd53de6c8 78 pixel[3] = (y >> 8) & 0xFF;
JLS 0:21ffd53de6c8 79 pixel[4] = y & 0xFF;
JLS 0:21ffd53de6c8 80
JLS 0:21ffd53de6c8 81 pixel[5] = (color >> 8) & 0xFF;
JLS 0:21ffd53de6c8 82 pixel[6] = color & 0xFF;
JLS 0:21ffd53de6c8 83
JLS 0:21ffd53de6c8 84 writeCOM(pixel, 7);
JLS 0:21ffd53de6c8 85 }
JLS 0:21ffd53de6c8 86
JLS 0:21ffd53de6c8 87
JLS 0:21ffd53de6c8 88 void baudrate() {
JLS 0:21ffd53de6c8 89
JLS 0:21ffd53de6c8 90 char baudrate[2]= "";
JLS 0:21ffd53de6c8 91
JLS 0:21ffd53de6c8 92 baudrate[0] = '\x51';
JLS 0:21ffd53de6c8 93 baudrate[1] = '\x0F';
JLS 0:21ffd53de6c8 94
JLS 0:21ffd53de6c8 95 int i, resp = 0;
JLS 0:21ffd53de6c8 96
JLS 0:21ffd53de6c8 97 while (_cmd.readable()) _cmd.getc();
JLS 0:21ffd53de6c8 98
JLS 0:21ffd53de6c8 99 long speed = speed = 281000;
JLS 0:21ffd53de6c8 100
JLS 0:21ffd53de6c8 101 for (i = 0; i <2; i++) _cmd.putc(baudrate[i]);
JLS 0:21ffd53de6c8 102 _cmd.baud(speed);
JLS 0:21ffd53de6c8 103
JLS 0:21ffd53de6c8 104 while (!_cmd.readable()) wait_ms(1);
JLS 0:21ffd53de6c8 105
JLS 0:21ffd53de6c8 106 if (_cmd.readable()) resp = _cmd.getc();
JLS 0:21ffd53de6c8 107 switch (resp) {
JLS 0:21ffd53de6c8 108 case '\x06' :
JLS 0:21ffd53de6c8 109 resp = 1;
JLS 0:21ffd53de6c8 110 break;
JLS 0:21ffd53de6c8 111 case '\x15' :
JLS 0:21ffd53de6c8 112 resp = -1;
JLS 0:21ffd53de6c8 113 break;
JLS 0:21ffd53de6c8 114 default :
JLS 0:21ffd53de6c8 115 resp = 0;
JLS 0:21ffd53de6c8 116 break;
JLS 0:21ffd53de6c8 117 }
JLS 0:21ffd53de6c8 118
JLS 0:21ffd53de6c8 119 }
JLS 0:21ffd53de6c8 120
JLS 0:21ffd53de6c8 121
JLS 0:21ffd53de6c8 122 int writeCOM(char *command, int number) {
JLS 0:21ffd53de6c8 123
JLS 0:21ffd53de6c8 124 int i, resp = 0;
JLS 0:21ffd53de6c8 125
JLS 0:21ffd53de6c8 126 while (_cmd.readable()) _cmd.getc();
JLS 0:21ffd53de6c8 127
JLS 0:21ffd53de6c8 128 for (i = 0; i < number; i++) _cmd.putc(command[i]);
JLS 0:21ffd53de6c8 129
JLS 0:21ffd53de6c8 130 while (!_cmd.readable()) wait_ms(1);
JLS 0:21ffd53de6c8 131 if (_cmd.readable()) resp = _cmd.getc();
JLS 0:21ffd53de6c8 132 switch (resp) {
JLS 0:21ffd53de6c8 133 case '\x06' :
JLS 0:21ffd53de6c8 134 resp = 1;
JLS 0:21ffd53de6c8 135 break;
JLS 0:21ffd53de6c8 136 case '\x15' :
JLS 0:21ffd53de6c8 137 resp = -1;
JLS 0:21ffd53de6c8 138 break;
JLS 0:21ffd53de6c8 139 default :
JLS 0:21ffd53de6c8 140 resp = 0;
JLS 0:21ffd53de6c8 141 break;
JLS 0:21ffd53de6c8 142 }
JLS 0:21ffd53de6c8 143
JLS 0:21ffd53de6c8 144 return resp;
JLS 0:21ffd53de6c8 145 }
JLS 0:21ffd53de6c8 146
JLS 0:21ffd53de6c8 147
JLS 0:21ffd53de6c8 148 void cls() {
JLS 0:21ffd53de6c8 149 char cls[1] = "";
JLS 0:21ffd53de6c8 150 cls[0] = '\x45';
JLS 0:21ffd53de6c8 151 writeCOM(cls, 1);
JLS 0:21ffd53de6c8 152 }