// Open Laser Show DAC Example - Circle
// Draws a nice circle and shifts the phase so it rotates.
#include <OLSD.h>
#include <standard.h>
OLSD dac;
//This works max number 16382
//unsigned int x[] = {
// 8191, 8448, 8705, 8962, 9218, 9472, 9726, 9978, 10228, 10476, 10722, 10966, 11206, 11444, 11679, 11910, 12137, 12361, 12580, 12795, 13006, 13211, 13412, 13608, 13798, 13983, 14162, 14335, 14502, 14663, 14818, 14966, 15107, 15241, 15369, 15489, 15602, 15708, 15807, 15898, 15981, 16057, 16125, 16185, 16237, 16281, 16317, 16346, 16366, 16378, 16382, 16378, 16366, 16346, 16317, 16281, 16237, 16185, 16125, 16057, 15981, 15898, 15807, 15708, 15602, 15489, 15369, 15241, 15107, 14966, 14818, 14663, 14502, 14335, 14162, 13983, 13798, 13608, 13412, 13211, 13006, 12795, 12580, 12361, 12137, 11910, 11679, 11444, 11206, 10966, 10722, 10476, 10228, 9978, 9726, 9472, 9218, 8962, 8705, 8448, 8191, 7934, 7677, 7420, 7164, 6910, 6656, 6404, 6154, 5906, 5660, 5416, 5176, 4938, 4703, 4472, 4245, 4021, 3802, 3587, 3376, 3171, 2970, 2774, 2584, 2399, 2220, 2047, 1880, 1719, 1564, 1416, 1275, 1141, 1013, 893, 780, 674, 575, 484, 401, 325, 257, 197, 145, 101, 65, 36, 16, 4, 0, 4, 16, 36, 65, 101, 145, 197, 257, 325, 401, 484, 575, 674, 780, 893, 1013, 1141, 1275, 1416, 1564, 1719, 1880, 2047, 2220, 2399, 2584, 2774, 2970, 3171, 3376, 3587, 3802, 4021, 4245, 4472, 4703, 4938, 5176, 5416, 5660, 5906, 6154, 6404, 6656, 6910, 7164, 7420, 7677, 7934
//};
//unsigned int y[] = {
// 8191, 8448, 8705, 8962, 9218, 9472, 9726, 9978, 10228, 10476, 10722, 10966, 11206, 11444, 11679, 11910, 12137, 12361, 12580, 12795, 13006, 13211, 13412, 13608, 13798, 13983, 14162, 14335, 14502, 14663, 14818, 14966, 15107, 15241, 15369, 15489, 15602, 15708, 15807, 15898, 15981, 16057, 16125, 16185, 16237, 16281, 16317, 16346, 16366, 16378, 16382, 16378, 16366, 16346, 16317, 16281, 16237, 16185, 16125, 16057, 15981, 15898, 15807, 15708, 15602, 15489, 15369, 15241, 15107, 14966, 14818, 14663, 14502, 14335, 14162, 13983, 13798, 13608, 13412, 13211, 13006, 12795, 12580, 12361, 12137, 11910, 11679, 11444, 11206, 10966, 10722, 10476, 10228, 9978, 9726, 9472, 9218, 8962, 8705, 8448, 8191, 7934, 7677, 7420, 7164, 6910, 6656, 6404, 6154, 5906, 5660, 5416, 5176, 4938, 4703, 4472, 4245, 4021, 3802, 3587, 3376, 3171, 2970, 2774, 2584, 2399, 2220, 2047, 1880, 1719, 1564, 1416, 1275, 1141, 1013, 893, 780, 674, 575, 484, 401, 325, 257, 197, 145, 101, 65, 36, 16, 4, 0, 4, 16, 36, 65, 101, 145, 197, 257, 325, 401, 484, 575, 674, 780, 893, 1013, 1141, 1275, 1416, 1564, 1719, 1880, 2047, 2220, 2399, 2584, 2774, 2970, 3171, 3376, 3587, 3802, 4021, 4245, 4472, 4703, 4938, 5176, 5416, 5660, 5906, 6154, 6404, 6656, 6910, 7164, 7420, 7677, 7934
//};
//This does not work max number 16384
unsigned int x[] = {
8192, 8449, 8706, 8963, 9219, 9474, 9727, 9979, 10229, 10477, 10723, 10967, 11208, 11445, 11680, 11911, 12139, 12362, 12581, 12797, 13007, 13213, 13414, 13609, 13800, 13985, 14164, 14337, 14504, 14665, 14819, 14967, 15109, 15243, 15371, 15491, 15604, 15710, 15809, 15900, 15983, 16059, 16127, 16187, 16239, 16283, 16319, 16348, 16368, 16380, 16384, 16380, 16368, 16348, 16319, 16283, 16239, 16187, 16127, 16059, 15983, 15900, 15809, 15710, 15604, 15491, 15371, 15243, 15109, 14967, 14819, 14665, 14504, 14337, 14164, 13985, 13800, 13609, 13414, 13213, 13007, 12797, 12581, 12362, 12139, 11911, 11680, 11445, 11208, 10967, 10723, 10477, 10229, 9979, 9727, 9474, 9219, 8963, 8706, 8449, 8192, 7935, 7678, 7421, 7165, 6910, 6657, 6405, 6155, 5907, 5661, 5417, 5176, 4939, 4704, 4473, 4245, 4022, 3803, 3587, 3377, 3171, 2970, 2775, 2584, 2399, 2220, 2047, 1880, 1719, 1565, 1417, 1275, 1141, 1013, 893, 780, 674, 575, 484, 401, 325, 257, 197, 145, 101, 65, 36, 16, 4, 0, 4, 16, 36, 65, 101, 145, 197, 257, 325, 401, 484, 575, 674, 780, 893, 1013, 1141, 1275, 1417, 1565, 1719, 1880, 2047, 2220, 2399, 2584, 2775, 2970, 3171, 3377, 3587, 3803, 4022, 4245, 4473, 4704, 4939, 5176, 5417, 5661, 5907, 6155, 6405, 6657, 6910, 7165, 7421, 7678, 7935
};
unsigned int y[] = {
8192, 8449, 8706, 8963, 9219, 9474, 9727, 9979, 10229, 10477, 10723, 10967, 11208, 11445, 11680, 11911, 12139, 12362, 12581, 12797, 13007, 13213, 13414, 13609, 13800, 13985, 14164, 14337, 14504, 14665, 14819, 14967, 15109, 15243, 15371, 15491, 15604, 15710, 15809, 15900, 15983, 16059, 16127, 16187, 16239, 16283, 16319, 16348, 16368, 16380, 16384, 16380, 16368, 16348, 16319, 16283, 16239, 16187, 16127, 16059, 15983, 15900, 15809, 15710, 15604, 15491, 15371, 15243, 15109, 14967, 14819, 14665, 14504, 14337, 14164, 13985, 13800, 13609, 13414, 13213, 13007, 12797, 12581, 12362, 12139, 11911, 11680, 11445, 11208, 10967, 10723, 10477, 10229, 9979, 9727, 9474, 9219, 8963, 8706, 8449, 8192, 7935, 7678, 7421, 7165, 6910, 6657, 6405, 6155, 5907, 5661, 5417, 5176, 4939, 4704, 4473, 4245, 4022, 3803, 3587, 3377, 3171, 2970, 2775, 2584, 2399, 2220, 2047, 1880, 1719, 1565, 1417, 1275, 1141, 1013, 893, 780, 674, 575, 484, 401, 325, 257, 197, 145, 101, 65, 36, 16, 4, 0, 4, 16, 36, 65, 101, 145, 197, 257, 325, 401, 484, 575, 674, 780, 893, 1013, 1141, 1275, 1417, 1565, 1719, 1880, 2047, 2220, 2399, 2584, 2775, 2970, 3171, 3377, 3587, 3803, 4022, 4245, 4473, 4704, 4939, 5176, 5417, 5661, 5907, 6155, 6405, 6657, 6910, 7165, 7421, 7678, 7935
};
int a = 0;
int b = 50;
unsigned int x_send;
unsigned int y_send;
long previousMillis = 0;
void setup()
{
dac.Init();
// Set the point output rate really slow since floating point is really slow
// No need to go faster
dac.SetOutputRate(12000);
}
// Phase is global so it is persistant through the loop function callss
float phase = 0.0;
void loop()
{
unsigned long currentMillis = millis();
//float x,y,a;
// Calculate and draw a circle using sine and cosine
// This is a little slow given the floating point math on this processor
//for (a = 0.0; a <= (2.0 * PI); a += 0.1)
// Calculate x and y using our angle in radians
// Include a phase shift so the circle rotates
//x = sin(a + phase);
//y = cos(a);
// Change the +/-1.0 numbers into unsigned integers
//x = x * 32760.0 + 32760.0;
//y = y * 32760.0 + 32760.0;
// Output the point
x_send = x[a];
y_send = y[b];
//if(currentMillis - previousMillis > 500){
//previousMillis = currentMillis;
dac.OutputPoint(x_send, y_send, 255, 255, 255);
a++;
b++;
if(a >= sizeof(x)/sizeof(int)){
a = 0;
}
if(b >= sizeof(y)/sizeof(int)){
b = 0;
}
//}
// Change the phase for next time we draw the circle
//phase += (PI / 360.0);
//if (phase > (2.0 * PI)) phase = 0.0;
}