Romancing the Code: The Literacy Narrative I Did Write

As noted previously, I had to learn the hard way about how to really focus in a good writing assignment. This is the finished product, the earlier draft of which is here: Romancing the Code: The Literacy Narrative I Wanted to Write.

This is the final version of a literacy narrative, originally written for UMass Lowell (online) College Writing I, Sec. 031, Professor Richard Keating, October 15, 2018. (Note to plagiarists: This has been submitted to the TurnItIn database, <sarcasm>so, by all means, copy away</sarcasm>.)

Douglas Wilcox
Richard Keating
UML College Writing I, Sec. 031
October 15, 2018

Romancing the Code

Phase 1: Literacy Narrative

In one of several clichés employed by twentieth century science fiction, computers are autonomous problem-solvers. They are almost never seen to be programmed by humans. The idea of a computer as a tool is refocused into its metanarrative, where the computer is an autonomous yet servile agent of its human master. A query is made, and the computer—via punched paper, data cards, audible output, or screen display—provides the answer to an enormously complex problem. Although I use computers to solve a vast number of practical problems in everyday life, programming itself, begun when I was in elementary school, provides the ultimate problem-solving experience.

The same year Star Wars was released, I met my first real computer: a Digital Equipment Corporation (DEC) PDP-8, at my town’s high school. Each terminal connected to this computer was a repurposed teletype machine. There was no screen display, only a nearly-endlessly spooling roll of paper. Each keystroke from the operator or each character output from the PDP was accompanied by a wonderfully complex sound of motors and servos moving the print element and its carriage across the platen, and hammering the right letter onto the paper (262LongRunner).

I was in love.

Through another school program, I got to play on a PDP-40, a massive device that would have made the PDP-8 weep with inferiority, had it been sentient. There I discovered the text adventure “Dungeon” (nee Zork) (Anderson, Kidder).

Creating my own text adventure game became my obsession. I had grand visions. I spent hours creating maps, and working to figure out subroutines that would be able to interpret user input, track inventory, handle world descriptions and actions, and even inject some humor while tracking hunger and thirst—“You would kill for a baloney-and-cheese sandwich.” There was no way for me to do a program this large on the DEC, but the Apple IIs that the junior high had would be perfect. They even had floppy drives, so I could store this creation on my own 5¼” diskette.

Not owning my own computer, I had to work offline—truly offline. I worked in notebooks, keeping the program flow in my head, and writing the code in longhand for later entry and debugging. I had the inspiration and functional model from other, better-written software, and a clear idea of what I wanted to do. I just had to figure out how.

A text adventure needs to provide a description of each location or room, and anything that might be portable in that room. The program needs to track the player’s location, and allow the player to move through the game world. My solution for handling this was effective, but contraindicated by speed and memory limitations at the time. The key was arrays—the computer equivalent of a numbered stack of index cards. I used an array of alphanumeric variables as a container, storing the description for each of the game’s locations by element number in the array. So, if the player moved to “location 104,” the description could be displayed by returning the description in “card” 104. That system was great for things which stayed in place, but what about portable items? For that I had to push further, but was still able to use an array structure. I invented a design where each portable item would be assigned to an item number in an array, and the data for that item would be stored in a predetermined portion of a text variable that contained, among other things, the item’s description. In the metaphor of the index cards, we might imagine that specific lines on each card record a specific kind of data, such as consistently having a title on the first line of every card.

Player movement could be controlled by setting the player’s location to a particular number corresponding to the description array and item locations. Switching the location was just a matter of coding which direction’s movement would take one to which location number and using that number to access the description and item arrays.

When I finally got enough of the modules coded and debugged, I ran it. It worked! It was slow—but it worked.

Now I work full time as a programmer, as I have for more than 15 years, and every part of my workday involves applying digital literacy directly to solving programming problems. I use my store of those skills and a variety software tools to accomplish this. The problems I solve are far more complicated—although they often still involve arrays—but they apply all the digital skills and literacy that began when I was smitten by the PDP-8, in all its teletype-driven glory.

Phase 2: Analysis

The rapid development of digital technologies in the digital era presents individuals in the emerging information society with situations that require them to employ a growing assortment of cognitive skills in order to perform and solve problems in digital environments. These skills are often referred to as “digital literacy” (Gilster, 1997; Inoue et al., 1997; Lanham, 1995; Pool, 1997), which is presented as a special kind of mindset that enables users to perform intuitively in digital environments, and to easily and effectively access the wide range of knowledge embedded in these environments (Gilster, 1997; Tapscott, 1998; EshetAlkalai, 2004; 2005) (Aviram and EshetAlkalai 1, emphasis mine).

The experience described in this narrative pertains to the phrase: “to perform and solve problems.” Problem-solving is the aspect of digital literacy that is most important in my life and career.

My first digital literacy skills were not very impressive, and many are now accessible by toddlers in today’s world of icons and GUIs: reading a directory, loading a program, running that program, and interacting with its prompts and output. Looking back over my computer literacy from childhood through the early days of my computer career, it is clear that my very meanest skills were a foundation of understanding that lasted for decades.

I worked in notebooks, keeping the program flow in my head, and writing the code in longhand for later entry and debugging.

Although the problems I solve are now more complex, the instant availability of explanations, sample code, and often complete example projects available online can make the level of problem solving significantly different. Given my skill level at the time, my limited access to computers, the nonexistence of the Internet, and a lack of established patterns, there was more room for innovation at a basic level. Innovation is still significant, but it tends to occur 

I spent hours creating maps, and working to figure out subroutines that would be able to interpret user input, track inventory, handle world descriptions and actions, and even inject some humor while tracking hunger and thirst….

It was somewhat surprising to explore this time period, and to renew my awareness of just how exhilarating computer tasks were. I was able to continually improve programming concepts and problem-solving by my sometimes weak attempts to replicate things I had seen. Writing my own text adventure was a wonderfully motivating force for improving my programming and the problem-solving that went along with it. I still advise those who want to learn a new platform on language to think of something that they really want to build as a first project.

That system was great for things which stayed in place, but what about portable items? For that I had to push further.

Although it is true that I knew far less, I was also working with a programming language that was more limited in its abilities, and accomplishing what I wanted often required a finer-grained ingenuity.  

The “growing assortment of cognitive skills” (Aviram and EshetAlkalai) is particularly evident in the development of problem-solving. Like any cognitive skill practice, problem-solving begets even more refined problem-solving, leading to gains in the complexity of problems that can be solved, and the ease with which they can be solved.

Works Cited

262LongRunner. “Teletype Model 33 ASR.wmv.” YouTube, YouTube, 16 Apr. 2012, www.youtube.com/watch?v=ObgXrIYKQjc. Online video.

Aharon Aviram and Yoram EshetAlkalai, “Towards a Theory of Digital Literacy: Three Scenarios for the Next Steps.” European Journal of Open, Distance and E-Learning. 2006. Retrieved from https://pdfs.semanticscholar.org/c680/679dc70baf4727cfd5f97b8535d62137914e.pdf?_ga=2.58484906.1842711008.1538448028-1659923920.1538448028. Document download.

Anderson, Tim. “The History of Zork.” The Wayback Machine, 1985, web.archive.org/web/20060427000213/http://www.csd.uwo.ca/Infocom/Articles/NZT/zorkhist.html. Web page.

Kidder, Tracy. The Soul of a New Machine. Little, Brown and Company, 2000. Print.

Feedback

Professor Keating’s Final Response:

Hi Doug,

As I read the final version of this exceptionally well revised essay, I reflect on how the vast majority of my students see digital literacy in terms of language, or a lexicon of terms common to a discipline. You see it in terms of a numerical logic, a binary code of understanding. That’s just as applicable, different cognition, same result!

Fine start to the semester, RSK


Romancing the Code: The Literacy Narrative I Wanted to Write

This was a relatively early draft and analysis of a literacy narrative, originally written for UMass Lowell (online) College Writing I, Sec. 031, Professor Richard Keating, September 30, 2018. The more concise version will be published separately. (Note to plagiarists: This has been submitted to the TurnItIn database, <sarcasm>so, by all means, copy away</sarcasm>.)

I loved writing this essay, but desperately needed to cut it down to a much smaller size and intense focus. (That was the hardest part of the work.) Still, this history of my first exposure to computers is something I wanted to publish. The final version of this essay is here: Romancing the Code: The Literacy Narrative I Did Write.

Computers in Digital Literacy: Problem-Solvers versus Problem-Solving

Phase 1: Literacy Narrative

When I was nine years old, the world of science fiction changed with the release of Star Wars. The film is, of course, merely space opera, and more fitting of the term science fantasy than science fiction, but it was remarkable for its technical presentation and fully realized worldbuilding, rather than for its originality or brilliance of story. (See Campbell, 2008.)

In much of twentieth century science fiction, computers are autonomous problem-solvers. They are almost never programmed by humans. A query is made, and the computer—via punched paper, data cards, audible output, or screen display—provides the answer to an enormously complex problem. The idea of a computer as a tool is reduced to its metanarrative: The computer is godlike—omniscient and often omnipresent—and not necessarily benign. Star Wars avoided this trope, turning sentient, autonomous computers into a digital underclass—droids—while presenting computers with which “humans” would directly interact in a way that was more akin to our current state of the art. The Star Wars world includes custom-purposed computer appliances, such as a “navicomputer” (Wookiepedia), as well as networked data storage and retrieval devices that would not be out of place in our own world. Although we use computers to solve a vast number of problems in everyday life, even commonly as our own navicomputer devices, it is the act of programming itself which provides me the greatest problem-solving experience.

The same year Star Wars was released, I met my first real computer: a Digital Equipment Corporation (DEC) PDP-8 (Fig. 1) at my town’s high school. Each terminal connected to this computer was a repurposed teletype machine (Fig. 2). There was no screen display, only a nearly-endlessly spooling roll of paper. Each keystroke from the operator or each character output from the PDP was accompanied by a wonderfully complex sound of motors and servos moving the print element and its carriage across the platen, and hammering the right letter onto the paper (262LongRunner). This sound was so iconic that we continue to associate it with the background noises of the era’s television newsrooms.

Fig. 1. Front panel of a PDP-8/e (Claessen).

At age nine, with no previous experience with computers, I was incapable of using them for anything beyond running simple math programs written by high school students. It is difficult to appreciate now, but in a world where pocket calculators were relatively rare, having a computer prompt for two numbers and then displaying their product or dividend was a marvel.

Fig. 2. A model ASR 33 teletype machine, like those used to communicate with the PDP-8 (Hudson).

Beyond such number-crunching, computers immediately proved to be greatly entertaining. I ran student-written programs such as “Guess,” in which the user would enter a number between 1 and 100, and the computer would respond with, “Too high,” or “Too low.” I printed text-based art, my favorite being a cartoon of Snoopy, shaking his fist and saying, “Curse you, Red Baron!” (Fig. 3). One could print banners of words where each letter in the banner’s text was composed of many smaller letters. I printed calendars for the current year, my birth year, and the unbelievably far-off year 2000.

I was in love.

This elementary-school experience did nothing to assuage my longing to use computers. Through another school program I got to play on a PDP-40 at a nearby enterprise, a massive device that would have made the PDP-8 weep with inferiority, had it been sentient. There I discovered the text adventure “Dungeon” (later and more commonly known as Zork) (Anderson, Kidder). I was enthralled with text adventures. I was determined to program my own.

Fig. 3. Snoopy ASCII art (Modified from asciiworld.com).

In my junior high years, we had access to Apple II computers repackaged by Bell & Howell to be nearly indestructible. We also secured access to the PDP-8 at the high school. By this time the teletype machines were gone, replaced mostly by dot-matrix printers from DEC, and supplemented by three glorious CRT terminals, VT05s (Fig. 4). DEC had donated these CRTs to my junior high school’s HAL (High Ability Learner) program, but I was the first to negotiate access to them. I stayed after school until 5:00 every day I could, just to get time on these. I began to learn BASIC, back in the ancient times when it still required line numbers.

Fig. 4. A DEC VT05 serial terminal. (Autopilot)

Not having a computer of my own presented a problem that might seem odd today. I had to work offline—truly offline—without even a search engine, and then try to code what I had done in the time I could get access to the computer. So, I worked in notebooks, keeping the program flow in my head, and writing the code in longhand that I would hope to later enter and perfect.

I tried my hand at a number of different programs, but creating my own text adventure game became my obsession. My first attempt at a text adventure was quite limited. It offered nothing more than multiple-choice prompts to make action choices, a far cry from the verb-object command-parsing that Zork could do. My program was shameful, borrowing scenes and catch phrases from Tom Baker’s incarnation of Dr. Who, and not much more complex than a choose-your-own-adventure book. One-quarter of the way through, I ran the program, and the computer spit out an inexplicable error. It was not the usual problem of a missing parenthesis or a syntax error, but something I could not diagnose.

“Doc” (Donald Harrison), the high school’s computer science teacher, helped me out. Although my program was tiny, it was too big for the execution space on the PDP-8. He taught me how to link multiple programs so I could jump to one from another, and I was able to complete my first adventure. It did teach me the basics of programming, even though what I wrote was not much more than a pile of print and goto statements, hooked together with the occasional numeric input. Even so, knowledge of programming meant problem-solving.

I had grander visions. My next adventure was more original. I spent hours creating maps, this time avoiding established fandom, and more time figuring out subroutines that would be able to interpret input, track inventory, handle world descriptions and actions, and even inject some humor while tracking hunger and thirst—“You would kill for a baloney-and-cheese sandwich.” There was no way for me to do a program this large on the DEC, but the Apple IIs that the junior high had would be perfect (Fig. 5). They even had floppy drives, so I could store my creations on my own 5¼” diskette. Innovation was exhilarating.

There were no obvious patterns to follow, and the BASIC language itself was somewhat limited. There were no premade frameworks. I had books, which were very limited, and often inapplicable to a particular system just when I needed to learn something advanced. (The deeper one went, the less universal computer languages with the same name became—radically different from today’s write-once-deploy-everywhere languages like Java.) I had the inspiration and functional model from other, better-written software, and a clear idea of what I wanted to do. I just did not know how.

Fig. 5. A Bell & Howell Apple II+, sporting the same floppy drives we used. (Mightyohm)

In a text adventure, one of the most important things is providing a description of each location or room, and anything that might be movable in that room. In that context, the program needs to track the player’s location, and allow the player to move in a specific direction, such as “move north.” My solution may have been clever, if contraindicated by speed or memory limitations at the time. I used an array (something like a deck of cards) of alphanumeric variables as a container, storing the location description for each “room” by element number in the array. So, if the player moved to “location 104,” the description could be displayed by accessing a function that would return the description in “card” 104.That system was great for things which stayed in place, but what about portable items? For that I had to push further, and I invented a design which was not dissimilar to what is now called a bitmap. Each portable item would have an item number, but the data for that item would be stored in a predetermined part of a text variable that contained, among other things, the item’s description. In a simple example, the first three characters of the text variable might contain the location number, which could even be a number showing it to be in the player’s own inventory. The description of the item would then be the fourth character in the text to the end of it. Now we use object-oriented languages to create models of such things, in a way that often mimics the real world. A car is often used to illustrate this. A car is a generalized object, and has properties such as color, model, size, number of passengers, make, year of manufacture, or VIN.

Player movement could be controlled by setting the player’s location to a particular number, and the same location number could be used to get the description of the location and then display any portable items that were there. Switching the location was just a matter of coding which direction’s movement would take one to which location number.

When I finally got enough of the modules coded and debugged, I ran it. It worked! There was one last problem: speed. Between entering a command and waiting for the program to do something was a pause of 5 or 10 seconds. But it worked.

More than a decade later, I encountered the published source code of Zork (and even got it to run in a Windows FORTRAN environment). I was blown away by the simplicity of Zork’s code. The huge, complicated processing modules I had created were not used. Zork had a simple data structure, with a number of pointers, in some ways similar to my array-storage design, but infinitely more elegant.

Now I work full time as a programmer, as I have for more than 15 years, and every part of my workday involves applying digital literacy directly to solving programming problems, ensuring our software is secure, and giving our customers new or better experiences. I use a dizzying array of software tools to accomplish this. The problems I solve are far more complicated, but they apply all the digital skills and literacy that began when I was smitten by the PDP-8, in all its teletype-driven glory.

Someday, we may indeed interact with our computers like much of our science fiction predicted. When that day arrives, however, it will surely include its own tangle of media literacy problems to be solved.

Phase 2: Analysis

The rapid development of digital technologies in the digital era presents individuals in the emerging information society with situations that require them to employ a growing assortment of cognitive skills in order to perform and solve problems in digital environments. These skills are often referred to as “digital literacy” (Gilster, 1997; Inoue et al., 1997; Lanham, 1995; Pool, 1997), which is presented as a special kind of mindset that enables users to perform intuitively in digital environments, and to easily and effectively access the wide range of knowledge embedded in these environments (Gilster, 1997; Tapscott, 1998; EshetAlkalai, 2004; 2005). (Aviram and EshetAlkalai, 2006, emphasis mine)

My experience, described in this narrative, tends to present two foci: “a growing assortment of cognitive skills” and “to perform and solve problems.” Although the two are intrinsically linked, problem-solving is the one that is most unique to my own narrative., and the one that is most important in my life and career.

So, I worked in notebooks, keeping the program flow in my head, and writing the code in longhand that I would hope to later enter and perfect.

My first skills were not very impressive, and are now accessible by toddlers in today’s world of icons and GUIs: reading a directory, loading a program, running that program, and then interacting with its prompts and output. Tracing computer literacy from childhood through the early days of my computer career, it is clear that my very meanest skills were a foundation of understanding that lasted for decades. (RUNH was the command used to launch a program, and I only recently learned that that it was used to launch a FORTRAN module on the PDP.)

I spent hours creating maps, this time avoiding established fandom, and more time figuring out subroutines that would be able to interpret input, track inventory, handle world descriptions and actions, and even inject some humor while tracking hunger and thirst….

It was somewhat surprising to explore this time period, and to renew my awareness of just how exhilarating computer tasks were. Computers were often about games. I was able to continually improve programming concepts and problem-solving by my somewhat weak attempts to replicate things I had seen. Writing my own text adventure was a motivating force for improving my programming and the problem-solving that went along with it.

There were no obvious patterns to follow, and the BASIC language itself was somewhat limited. There were no premade frameworks. I had books, which were very limited, and often inapplicable to a particular system just when I needed to learn something advanced.

Although the problems I solve are now more complex, the instant availability of explanations, sample code, and often complete example projects can make the level of problem solving significantly different. Although it is true that I knew far less, I was also working with a programming language that was more limited in its abilities, and accomplishing what I wanted often required a finer grained ingenuity.

Works Cited

262LongRunner. “Teletype Model 33 ASR.wmv.” YouTube, YouTube, 16 Apr. 2012, www.youtube.com/watch?v=ObgXrIYKQjc. Online video.

Aharon Aviram and Yoram EshetAlkalai, “Towards a Theory of Digital Literacy: Three Scenarios for the Next Steps.” European Journal of Open, Distance and E-Learning. 2006. Retrieved from https://pdfs.semanticscholar.org/c680/679dc70baf4727cfd5f97b8535d62137914e.pdf?_ga=2.58484906.1842711008.1538448028-1659923920.1538448028. Document download.

Anderson, Tim. “The History of Zork.” The Wayback Machine, 1985, web.archive.org/web/20060427000213/http://www.csd.uwo.ca/Infocom/Articles/NZT/zorkhist.html. Web page.

Asciiworld.com: Snoopy, ASCIIWorld.com, http://www.asciiworld.com/-Snoopy,512-.html.

Autopilot. “File:VT05.jpg.” The original DEC serial terminal, the VT05, Wikimedia Commons, 6 May 2012, https://commons.wikimedia.org/w/index.php?curid=19364852. Online image.

Campbell, Joseph. The Hero with a Thousand Faces. New World Library, 2008. Print.

Claessen, Simon. “File:Digital PDP-8F.Jpg.” PDP-8/F Front Panel, Wikimedia Commons, 25 Sept. 2014, commons.wikimedia.org/w/index.php?curid=63802103. Online image.

Hudson, Trammell. “Model ASR33 Teletype.” Model ASR33 Teletype – Trammell Hudson’s Projects, Trammell Hudson, 29 Oct. 2017, trmm.net/Model_ASR33_Teletype. Web page.

Kidder, Tracy. The Soul of a New Machine. Little, Brown and Company, 2000. Print.

Mightyohm. “File:Bell_and_Howell_Apple_II.jpg.” Bell and Howell Apple II+, Wikimedia Commons, 07 Jan. 2011, commons.wikimedia.org/wiki/File:Bell_and_Howell_Apple_II.jpg. Online image.

“Navigation Computer.” Wookieepedia, FANDOM, 25 Apr. 2015, starwars.wikia.com/wiki/Navigation_computer. Web page.

Astronomy from the Driveway

Took Sarah ‘s father out planetgazing (finally) to the exotic location of his driveway.

Fabulous viewing of Jupiter and Saturn tonight with his NexStar 130 SLT and the lenses our dear friends gave us (one advantage of driving to Indiana, I could bring more stuff).

I have finally, definitely, seen the Great Spot! In our view Jupiter was inverted as in the image just above, but the 2 major cloud bands and the Great Spot were clearly visible! (As were all 4 Galilean moons.)

Saturn and Titan made for a fine sight as well.

Bad Dog!

Juno, do you know what this is?

This is an animal warning card the US Post Office uses.

Do you know what it says about you?

Friendly.

The mail carriers believe you are friendly. Mail carriers, Juno. Think about it. A dog’s mortal enemies. Friendly.

Bad dog!

A Week Without

Sarah Latimer is away camping in the White Mountains for a week.

She doesn’t think we can survive without her.

We aim to prove her wrong.

Day 1.

Grocery shopping has been made greatly easier. A week of this will be a trifle.

Day 2.

Our efficiency in daily tasks has improved dramatically:

  1. Reduction in dishes used by eating out of the same pots in which we cook. (Not that we are cooking; Pop Tarts rule!)
  2. Further reduction in dishes by drinking from containers, rather than wasting time and resources dirtying glasses.
  3. Juno (our dog) provides excellent dish-cleaning service, indistinguishable from dishwasher processing.
  4. Still more time saved by not showering or bathing.
  5. Who needs to put on clean clothes every day?

Wait, what is that? …

Day 2, Continued.

Holy, freaking crap! There is nothing left of the Pop Tarts but wrappers. Do you children have no discipline at all?!

(The boogers mumble something about apples and trees.)

We’re ruined! Doomed. Do you hear me!? We’re going to starve, or worse, have to eat something I cook! Do you remember fiasco of the pancakes? Ashish remembers the pancakes? (“You cooked steak? I thought you were going to make pancakes.”)

This could get interesting, in a “Define, ‘interesting,’” sort of way.

Day 3.

Someone in this house smells. It seems to be worse around the children. And the kitchen.

Maybe the philosophy of, “Why clean? It’ll just get dirty again,” needs some reevaluation.

At least Juno is happy, although this morning she walked over to me, looked me right in the face, sniffed once, and ran away.

And. We’re hungry. The children are sticking firmly to their commitment to starve before they eat anything I might cook.

What we thought was thunder turned out to be the combined output of stomachs rumbling.

How much longer?

Day 4.

It’s midnight now. The house is dark. I am not sure how this will turn out. The kids are all desperately sick, throwing up. I can hear my son and daughter retching in separate bathrooms. I went in to check on them a few minutes ago, to see what was coming up.

I think I’m okay, at least for the moment. But of course the odds aren’t good: most of the people involved in this business are already dead. And there are so many things I can’t know for sure.

I have a ringing in my ears, which is a bad sign. And I feel a vibrating in my chest and abdomen. The baby is spitting up, not really vomiting. I am feeling dizzy. I hope I don’t lose consciousness. The kids need me, especially the little one. They’re frightened. I don’t blame them.

I am, too.

(With apologies to Michael Crichton.)

Day 5.

We have, at last found something we can agree on eating. Thankfully, we have (had?) a real dog, rather than a Chihuahua or something tiny.

Weasley Clock Code – Now with WiFi

Back at one of Veracode’s Hackathons, I published the video below.

My Original Weasley Clock

The New and Improved Weasley Clock(s)

(Original post is here.) I was determined to update the code to use WiFi, and make some other improvements, so finally rewrote it. Here’s the first major revision:

#include 
#include "Adafruit_IO_Client.h"
#include 

/**
 * https://www.amazon.com/gp/product/B015RQ97W8/ref=oh_aui_search_detailpage?ie=UTF8&psc=1
 * 5-wire unipolar steppers with controller
 * Longruner 5x Geared Stepper Motor 28byj 48 Uln2003 5v Stepper Motor Uln2003 Driver 
 * Board for arduino LK67
 * 
 * AWESOME details on these motors/controllers:
 * https://arduino-info.wikispaces.com/SmallSteppers
 * 
 * Much Better than standard stepper library: AccelStepper
 * http://www.airspayce.com/mikem/arduino/AccelStepper/classAccelStepper.html
 * 
 * Weasley Clock
 * -------------
 * 
 * Created by Doug "LegoDoug" Wilcox for Veracode Hackathon IX.
 * 
 * Video of the completed project is at https://www.youtube.com/embed/oRUViFnxKsg.
 * 
 * "Share and enjoy."
 */

/************************* WiFi Access Point *********************************/
#define WLAN_SSID "DefinitelyNotMySSID"              // "...your SSID..." Amusingly, the cannot contains spaces or hyphens.
#define WLAN_PASS "TotallyNotTheRealPassword"        // "...your password..."


/************************* Adafruit.io Setup *********************************/

#define AIO_SERVER           "io.adafruit.com"
#define AIO_SERVERPORT       1883                           // use 8883 for SSL, otherwise use 1883
#define AIO_USERNAME         "TotallyNotMyAdaFruitIOUser"   // "...your AIO username (see https://accounts.adafruit.com)..."
#define AIO_KEY              "TotallyNotMyAdafruitIOKey"    // "...your AIO key..."
#define AIO_FEED_PATH        "/feeds/"
#define AIO_PUBLISH_FEED     "weasleyclockposition"
#define AIO_SUBSCRIBE_FEED   "weasleyclockstatus"

// Motor pin definitions
#define motorPin1  14    // IN1 on the ULN2003 driver 1
#define motorPin2  12    // IN2 on the ULN2003 driver 1
#define motorPin3  13    // IN3 on the ULN2003 driver 1
#define motorPin4  15    // IN4 on the ULN2003 driver 1

#define DELAY 1
#define HALFSTEP 8

/************ Global State (you don't need to change this!) ******************/

// Create an ESP8266 WiFiClient class to connect to the WiFi network.
WiFiClient client;
// or... use WiFiFlientSecure for SSL
// WiFiClientSecure client;

// Create an Adafruit IO Client instance.  Notice that this needs to take a
// WiFiClient object as the first parameter, and as the second parameter a
// default Adafruit IO key to use when accessing feeds (however each feed can
// override this default key value if required, see further below).
Adafruit_IO_Client aio = Adafruit_IO_Client(client, AIO_KEY);

// Alternatively to access a feed with a specific key:
Adafruit_IO_Feed clockFeed = aio.getFeed(AIO_SUBSCRIBE_FEED, AIO_KEY);

// States
const String LD_HOME         = "ld_na";
const String LD_TRAVELING    = "ld_tr";
const String LD_VERACODE     = "ld_of";
const String LD_CHURCH       = "ld_ch";
const String LD_MORTAL_PERIL = "ld_mp";
const String LD_GLOUCESTER   = "ld_gl";
const String PLUS_ONE        = "plus_1";
const String MINUS_ONE       = "minus_1";
const String PLUS_FIVE       = "plus_5";
const String MINUS_FIVE      = "minus_5";
const String NO_MOVEMENT     = "none";

// Steps
const int STEPS_HOME         = 0;
const int STEPS_TRAVELING    = 600;
const int STEPS_VERACODE     = 1250;
const int STEPS_CHURCH       = 1900;
const int STEPS_MORTAL_PERIL = 2600;
const int STEPS_GLOUCESTER   = 3450;
const int STEPS_ONE          = 32;
const int STEPS_FIVE         = 5 * 32;

String fValue = "";

const unsigned long requestInterval = 5000L; // delay between updates, in milliseconds

void stepBySteps(int newPosition, boolean resetWhenDone = false);

AccelStepper clockStepper(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);

void setup() {
  Serial.begin(115200);
  delay(10);

  // Connect to WiFi access point.
  Serial.println(); Serial.println();
  Serial.print("Connecting to ");
  Serial.println(WLAN_SSID);

  WiFi.begin(WLAN_SSID, WLAN_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println();
  Serial.println("WiFi connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  clockStepper.setMaxSpeed(1000.0);
  clockStepper.setAcceleration(100.0);
  clockStepper.setSpeed(200);
  clockStepper.setCurrentPosition(0);
}

void loop() {
  // Wait for a bit and read the current feed value.
  Serial.println(F("Waiting ..."));
  delay(requestInterval);
  // To read the latest feed value call the receive function on the feed.
  // The returned object will be a FeedData instance and you can check if it's
  // valid (i.e. was successfully read) by calling isValid(), and then get the
  // value either as a text value, or converted to an int, float, etc.

  Serial.println(F("Checking feed ..."));
  FeedData latest = clockFeed.receive();
  if (latest.isValid()) {
    Serial.print(F("Received value from feed: ")); Serial.println(latest);
    // By default the received feed data item has a string value, however you
    // can use the following functions to attempt to convert it to a numeric
    // value like an int or float.  Each function returns a boolean that indicates
    // if the conversion succeeded, and takes as a parameter by reference the
    // output value. Also, beware. There seems to be a limit on how long the
    // feed value can be. I had trouble when "minus_five" was used, which makes
    // me think the limit is 8 characters.

    // Want some fun? Learng about "conversion from 'FeedData' to non-scalar type 'String' requested" the hard way.
    fValue = latest;

    if(fValue == LD_HOME) {
      Serial.println("Nashua");
      stepBySteps(STEPS_HOME);
    }
    if(fValue == LD_TRAVELING) {
      Serial.println("Traveling");
      stepBySteps(STEPS_TRAVELING);
    }
    if(fValue == LD_VERACODE) {
      Serial.println("Veracode");
      stepBySteps(STEPS_VERACODE);
    }
    if(fValue == LD_CHURCH) {
      Serial.println("Church");
      stepBySteps(STEPS_CHURCH);
    }
    if(fValue == LD_MORTAL_PERIL) {
      Serial.println("Mortal Peril!");
      stepBySteps(STEPS_MORTAL_PERIL);
    }
    if(fValue == LD_GLOUCESTER) {
      Serial.println("Glostah");
      stepBySteps(STEPS_GLOUCESTER);
    }
    if(fValue == PLUS_ONE) {
      Serial.println("Forward one.");
      stepBySteps(clockStepper.currentPosition() + STEPS_ONE, true);
    }
    if(fValue == MINUS_ONE) {
      Serial.println("Back one.");
      stepBySteps(clockStepper.currentPosition() - STEPS_ONE, true);
    }
    if(fValue == PLUS_FIVE) {
      Serial.println("Forward five.");
      stepBySteps(clockStepper.currentPosition() + STEPS_FIVE, true);
    }
    if(fValue == MINUS_FIVE) {
      Serial.println("Back five.");
      stepBySteps(clockStepper.currentPosition() - STEPS_FIVE, true);
    }
    if(fValue == NO_MOVEMENT || fValue == "") {
      Serial.println("Not moving.");
    }
  } else {
    Serial.print(F("Failed to receive the latest feed value!"));
  }
}

void stepBySteps(int newPosition, boolean resetWhenDone) {
  clockStepper.enableOutputs();
  clockStepper.moveTo(newPosition);

  while (clockStepper.isRunning()) {
    clockStepper.run();
    delay(DELAY);
  }
  clockStepper.disableOutputs();

  if (resetWhenDone) {
    clockStepper.setCurrentPosition(0);
  }
  
}

Still to come, if I ever get around to it:

  • Alternative methodologies for reading the feed (publish/subscribe).
  • Secure WiFi communication.
  • Adjustment (such as after power disconnect) via an induction sensor.

One Cool Hotspot

Okay, wanna see something really cool? (Actually, it’s kinda hot …)

Below is a cropped image from a 1969 National Geographic map of the seafloor, showing the Pacific basin. What’s the cool part? See that long, almost L-shaped line of ridges and seamounts and islands that has Hawaii at the very end? That’s where the Pacific Plate has slowly moved over a hotspot in the earth’s mantle, which causes seamounts to form, and, occasionally, islands like Midway or Hawaii.

Pacific Floor Ocean Map, National Geographic, 1969.

The ridges show the movement of the Pacific plate over the last 75,000,000 years. Kind of slow movement, only about 6,000 km in that time, or 0.000000009132 km/h, about 80 mm/year.

That bend in the L is where the Pacific plate shifted direction 43,000,000 years ago.

In case you’re wondering where it goes as it moves, you can see the trenches on the top and left edges of the plate. Those are subduction zones, including the Marianas Trench, the deepest part of the ocean on earth. That’s where the Pacific plate is moving underneath the other plates, getting recycled very, very slowly.


Notes: