Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
*.xcodeproj
4 changes: 2 additions & 2 deletions SCTVcode/SCTVcode.ino
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
// V 1.1.1 05/14/22 DF Adding SCT-A board with Teensy 4.1, different I/O pins
// V 1.2.0 12/14/22 DF Updated USB host library local copy

char versionNo[] = "Version 1.2.0\n";
char versionNo[] = "Version 1.2.0sf\n";

// THINGS TO DO

Expand Down Expand Up @@ -111,7 +111,7 @@ char versionNo[] = "Version 1.2.0\n";

// SCTV-E up has Teensy 4.1 and SPI DAC, SCTV-D down use Teensy 3.6 with internal DAC
// Comment out the line below if compiling for board with Teensy 3.6 (SCTV-A..D)
#define SCTVE
// #define SCTVE

// The SCT has the Teensy 4.1 and external DAC, it also has different pins
// defined for many functions.
Expand Down
90 changes: 90 additions & 0 deletions SCTVcode/te_etchasketch.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// ------------------------------ Etch-A-Sketch -------------------------------

struct Point {
int x;
int y;
};

const int MAX_SEGMENTS = 1000;
const int END_TOKEN = -9999;

Point* segments;
Point* segment;
Point direction;
int x, y;

struct item etchList[] = {};

void getControlsXY() {
// read the position controls for X,Y, and average for smooth readings
for (int i = 0; i < 40; i++) {
x += analogRead(XPosPin) - 512; // read position controls
y += analogRead(YPosPin) - 512; // make bipolar so midpoint is nominal
}
// Center in the display area, scale for correct overshoot
x = x / 20;
y = y / 20;
}

void resetEtchASketch() {
if (segments == 0) {
segments = (Point*)malloc(sizeof(Point) * (MAX_SEGMENTS+2));
}
direction.x = 0;
direction.y = 0;

getControlsXY();
segment = segments;
segment[0].x = x;
segment[0].y = y;
segment[1].x = END_TOKEN;
}

void etchASketch() {
if (pushed) {
// selector button pushed: erase all traces
resetEtchASketch();
pushed = false;
}

// read X,Y control knobs and extend trace segments to it
getControlsXY();
int dx = x - segment->x;
int dy = y - segment->y;
int ds = sqrt((dx*dx + dy*dy) * 64);
if (ds != 0) {
// Serial.printf("Etch: xy=(%d,%d), ds=%d\n", x, y, ds);
// int n = segment - segments;
// Serial.printf(" dir=(%d,%d) %d segs, (%d,%d)-(%d,%d)\n",
// direction.x, direction.y, n, segment[0].x, segment[0].y, x, y);
// normalized direction vector for this segment
dx = 64 * dx / ds;
dy = 64 * dy / ds;
int diff = abs(dx - direction.x) + abs(dy - direction.y);
if (diff > 2 && segment < segments + MAX_SEGMENTS) {
// have changed direction: start new segment
// Serial.printf(" dx,dy=(%d,%d), ds=%d\n", dx, dy, ds);
direction.x = dx;
direction.y = dy;
segment++;
segment[0].x = x;
segment[0].y = y;
segment[1].x = END_TOKEN;
} else {
// else just extend last segment
segment->x = x;
segment->y = y;
}
}

// draw current list of trace segments
Scale = 1;
Shape = lin;
for (Point* seg = segments; seg[1].x != END_TOKEN; seg++) {
XStart = seg[0].x;
YStart = seg[0].y;
XEnd = seg[1].x;
YEnd = seg[1].y;
DoSeg(); // draw a line from (XStart,YStart) to (XEnd,YEnd)
}
}
3 changes: 2 additions & 1 deletion SCTVcode/w_menus.ino
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct item locMenu[] = {
// This is the clock display option list

// If Clock is zero; then draw hands
const int NClks = 8; // number of clock faces to choose from (splash doesn't count)
const int NClks = 9; // number of clock faces to choose from (splash doesn't count)

// list of clock face draw lists
item * ClkList[] =
Expand All @@ -97,6 +97,7 @@ item * ClkList[] =
time6dList, // 6 digit digital clock with date
haikuList, // some poetry at random
// flwList, // four letter words at random
etchList, // Etch-A-Sketch
splashList, // splash screen vanishes when knob touched
0};
// -------------------------- Menu navigation -----------------------
Expand Down
12 changes: 9 additions & 3 deletions SCTVcode/z_main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ void loop()
myGps.encode(userial.read());
}

if ((theClock != 1) && (theClock != 2)) // Pong and Tetris use position controls as paddles
{
if ((theClock != 1) && (theClock != 2) && (theClock != 8)) // Pong, Tetris, and Etch-A-Sketch
{ // use position controls as paddles
xPos = yPos = 0;
for (i=0;i<40;i++) {
xPos += analogRead(XPosPin) - 512; // read the position controls
Expand Down Expand Up @@ -189,17 +189,23 @@ void loop()
{
reset_tetris();
}
if (theClock == 8)
{
resetEtchASketch();
}
EncDir = 0;
}
whichList = ClkList[theClock]; // point to the clock drawlist we are displaying now
if (theClock == 0) DrawClk(); // clock 0 has hands to draw
if (theClock == 1) doPong(); // clock 1 is Pong
if (theClock == 2) drawTetris(); // clock 2 is Tetris
if (pushed)
if (theClock == 8) etchASketch(); // clock 8 is Etch-A-Sketch
if (theClock != 8 && pushed)
{
whichList = mainMenu;
HotItem = 1;
InMenu = true;
Serial.printf("Button pushed. theClock=%d\n", theClock);
}
}

Expand Down