Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add washing machine lesson (not done yet)
Signed-off-by: Keith Packard <keithp@keithp.com>
- Loading branch information
1 parent
3f9daed
commit d77b1f8
Showing
69 changed files
with
770 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
SNEK_NO_BUILD_TARGETS = 1 | ||
SNEK_ROOT=../../.. | ||
|
||
include $(SNEK_ROOT)/snek-install.defs | ||
|
||
.SUFFIXES: .adoc .pdf .html | ||
|
||
ADOC_FILES=snek-washing-machine.adoc | ||
|
||
PDF_FILES=$(ADOC_FILES:.adoc=.pdf) | ||
HTML_FILES=$(ADOC_FILES:.adoc=.html) | ||
CSS_FILES=snek.css coderay-asciidoctor.css | ||
IMAGE_FILES=\ | ||
21980.dat.png \ | ||
3003.dat.png \ | ||
3022.dat.png \ | ||
3023.dat.png \ | ||
3034.dat.png \ | ||
3039.dat.png \ | ||
3040b.dat.png \ | ||
3460.dat.png \ | ||
3482.dat.png \ | ||
3634.dat.png \ | ||
3660.dat.png \ | ||
3666.dat.png \ | ||
3700.dat.png \ | ||
3701.dat.png \ | ||
3702.dat.png \ | ||
3738.dat.png \ | ||
3830.dat.png \ | ||
3831.dat.png \ | ||
3894.dat.png \ | ||
3895.dat.png \ | ||
41539.dat.png \ | ||
4459.dat.png \ | ||
4519.dat.png \ | ||
5306.dat.png \ | ||
75973.dat.png \ | ||
879.dat.png \ | ||
washing-machine-01.png \ | ||
washing-machine-02.png \ | ||
washing-machine-03.png \ | ||
washing-machine-04.png \ | ||
washing-machine-05.png \ | ||
washing-machine-06.png \ | ||
washing-machine-07.png \ | ||
washing-machine-08.png \ | ||
washing-machine-09.png \ | ||
washing-machine-10.png \ | ||
washing-machine-11.png \ | ||
washing-machine-12.png \ | ||
washing-machine-13.png \ | ||
washing-machine-14.png \ | ||
washing-machine-15.png \ | ||
washing-machine-16.png \ | ||
washing-machine-17.png \ | ||
washing-machine-18.png \ | ||
washing-machine-19.png | ||
|
||
INC_FILES=steps.adoc | ||
|
||
all: $(HTML_FILES) $(PDF_FILES) | ||
|
||
LETTER_ATTRIBUTES=--attribute='pdf-style=snek' | ||
ATTRIBUTES=--attribute="revdate=$(SNEK_DATE)" --attribute="version=$(SNEK_VERSION)" | ||
|
||
.adoc.html: | ||
asciidoctor -v -B$(SNEK_ROOT) -B. $(ATTRIBUTES) -b html5 $*.adoc | ||
|
||
.adoc.pdf: | ||
asciidoctor-pdf -B$(SNEK_ROOT) -B. $(ATTRIBUTES) $(LETTER_ATTRIBUTES) $*.adoc | ||
|
||
$(PDF_FILES): ../../snek-theme.yml $(IMAGE_FILES) $(INC_FILES) ../../../snek.svg | ||
|
||
DOCFILES=$(PDF_FILES) $(HTML_FILES) $(CSS_FILES) snek.svg $(IMAGE_FILES) | ||
|
||
$(HTML_FILES): $(INC_FILES) | ||
|
||
install: $(DOCFILES) | ||
install -d $(DESTDIR)$(DOCDIR) | ||
for i in $(DOCFILES); do install --mode=644 "$$i" $(DESTDIR)$(DOCDIR) || exit 1; done | ||
|
||
upload: $(DOCFILES) | ||
rsync -avz $(DOCFILES) ../../fonts $(SNEKDOC)/washing-machine | ||
|
||
steps.adoc: ../line-bug/make-step ../line-bug/make-steps | ||
../line-bug/make-steps washing-machine-??.html > $@ | ||
|
||
snek.css: ../../snek.css | ||
cp $^ $@ | ||
|
||
snek.svg: ../../../snek.svg | ||
cp $^ $@ | ||
|
||
coderay-asciidoctor.css: $(HTML_FILES) | ||
|
||
clean:: | ||
rm -f $(PDF_FILES) $(HTML_FILES) $(BOOK_FILES) coderay-asciidoctor.css | ||
rm -f washing-machine-??.adoc steps.adoc | ||
rm -f snek.css snek.svg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
= Snek Project #3: The Washing Machine | ||
Keith Packard <keithp@keithp.com>; Michael Ward <michaelward@sprintmail.com> | ||
:version: 0.0 | ||
:title-logo-image: image:washing-machine.jpg[] | ||
:revnumber: v{version} | ||
:revdate: 1 Jan 1970 | ||
:experimental: | ||
:icons: | ||
:icontype: svg | ||
:copyright: Keith Packard 2020 | ||
:doctype: article | ||
:numbered: | ||
:stylesheet: snek.css | ||
:linkcss: | ||
:toc: | ||
:pdf-stylesdir: ../.. | ||
:pdf-fontsdir: ../../fonts | ||
:source-highlighter: coderay | ||
:media: prepress | ||
|
||
ifndef::backend-pdf[] | ||
[#logo] | ||
[link=https://keithp.com/snek] | ||
image::snek.svg[Snek] | ||
endif::[] | ||
|
||
[colophon] | ||
[%nonfacing] | ||
== License | ||
|
||
Copyright © 2020 {authors} | ||
|
||
This document is released under the terms of the link:https://www.gnu.org/licenses/gpl-3.0.en.html[GNU General Public License, Version 3 or later] | ||
|
||
[dedication] | ||
[%nonfacing] | ||
== Acknowledgments | ||
|
||
Thanks to Michael Ward for helping design this lesson. | ||
|
||
[verse] | ||
{author} | ||
{email} | ||
https://keithp.com | ||
|
||
== The Washing Machine | ||
|
||
This lesson contains instructions for building and programming a | ||
“Washing Machine”, a simulated household appliance. | ||
|
||
ifdef::backend-pdf[<<<] | ||
== Building The Washing Machine | ||
|
||
Follow the next few pages to complete the construction of your washing | ||
machine. For the wheels, you can use any that will fit on the axles and | ||
not rub on the rest of the model. | ||
|
||
Important features: | ||
|
||
* One motor driving the drum | ||
* Two touch sensors, one to detect when the door is close | ||
and another to start the machine | ||
* Two lights to help tell what the machine is doing | ||
|
||
=== Sensing Touch | ||
|
||
You might want to review the *Switches* section from the Snekboard | ||
lesson because we're going to need to use the `pulldown` function | ||
here. | ||
|
||
=== Waiting For A Switch Press | ||
|
||
Our washing machine shouldn't start the cycle until the door is | ||
closed. To wait for that, we'll need to wait for our door switch to be | ||
_on_. If we use the `pulldown` function, when the switch is pressed, | ||
the value on the port will be 1 (or True). To wait for that to happen, | ||
we'll use a `while` loop, testing the door switch (A1) over and over | ||
again, but doing nothing in the meantime: | ||
|
||
[source,subs="verbatim,quotes"] | ||
---- | ||
pulldown(A1) | ||
while not read(A1): | ||
pass | ||
---- | ||
|
||
|
||
=== Simulating the Wash Cycle | ||
|
||
For this, we want the drum to slosh back and forth several | ||
times. Probably not as long as a real washing machine; that can take | ||
half an hour or more. We don't need it to go as fast as | ||
possible, so we'll use a lower speed setting. Here's how to make it | ||
slosh back and forth once: | ||
|
||
[source,subs="verbatim,quotes"] | ||
---- | ||
> *talkto(M1)* | ||
> *setpower(0.5)* | ||
> *setleft()* | ||
> *onfor(0.5)* | ||
> *setright()* | ||
> *onfor(0.5)* | ||
---- | ||
|
||
This makes it go one direction for a short amount of time, and then | ||
switch around and go the other way. | ||
|
||
To make it do this several times, we could just copy that code as many | ||
times as we want it to repeat. Or, we could ask the robot to repeat | ||
this a few times with a `for` loop. | ||
|
||
==== The For Loop | ||
|
||
The `for` loop asks snek to count, and then do something each | ||
time. It will count using numbers by using the `range` function. That | ||
tells snek how far to count. Snek starts counting at 0 and stops | ||
counting just before it reaches the value given to `range`. If you | ||
give range the value 10, then Snek will count 0, 1, 2, 3, 4, 5, 6, 7, | ||
8 and finally 9. This is ten different numbers, so range(10) means to | ||
count ten times starting at 0. | ||
|
||
[source,subs="verbatim,quotes"] | ||
---- | ||
> *for i in range(10):* | ||
+ *print(i)* | ||
+ | ||
0 | ||
1 | ||
2 | ||
3 | ||
4 | ||
5 | ||
6 | ||
7 | ||
8 | ||
9 | ||
> | ||
---- | ||
|
||
==== Washing Many Times | ||
|
||
We can now use a `for` loop to slosh back and forth as many times as | ||
we like, without needing to copy the slosh bits that many times. | ||
|
||
[source,subs="verbatim,quotes"] | ||
---- | ||
def wash(): | ||
talkto(M1) | ||
setpower(0.5) | ||
for i in range(10): | ||
setleft() | ||
onfor(0.5) | ||
setright() | ||
onfor(0.5) | ||
---- | ||
|
||
=== Simulating the Spin Cycle | ||
|
||
go fast. | ||
|
||
=== Adding Lights | ||
|
||
blink. | ||
|
||
=== Building The Washing Machine | ||
|
||
Follow the next few pages to complete the construction of your washing | ||
machine. | ||
|
||
include::steps.adoc[] | ||
|
||
=== Wiring The Washing Machine | ||
|
||
Here's one way to wire up the washing machine. If you wire it up | ||
differently, you'll need to adjust for that when programming the | ||
robot. | ||
|
||
1. Connect the motor driving the drum to M1. | ||
|
||
2. Connect the door switch A1 and the switch on top to A8. Make sure | ||
you insert the connectors the right way, with the black wire | ||
towards the center of the snekboard and the yellow or white wire | ||
towards the edge. | ||
|
||
3. Connect the lights to M2 and M3. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<HTML> | ||
<HEAD> | ||
<TITLE>washing-machine.ldr - Step 1</TITLE> | ||
</HEAD> | ||
<BR> | ||
<CENTER> | ||
<IMG SRC="washing-machine-01.png" ALT="Step 01" WIDTH=1024 HEIGHT=768><BR><BR> | ||
<br><table border=1><tr><td><center>Piece</center></td> | ||
<td><center>Bright Light Yellow</center></td> | ||
</tr> | ||
<tr><td><IMG SRC="41539.dat.png" ALT="Plate 8 x 8"></td> | ||
<td><center>1</center></td> | ||
</tr> | ||
</table> | ||
<br></CENTER> | ||
<BR><HR><BR><A HREF="washing-machine-02.html">Next</A><BR></HTML> |
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<HTML> | ||
<HEAD> | ||
<TITLE>washing-machine.ldr - Step 2</TITLE> | ||
</HEAD> | ||
<BR> | ||
<CENTER> | ||
<IMG SRC="washing-machine-02.png" ALT="Step 02" WIDTH=1024 HEIGHT=768><BR><BR> | ||
<br><table border=1><tr><td><center>Piece</center></td> | ||
<td><center>Bright Light Yellow</center></td> | ||
</tr> | ||
<tr><td><IMG SRC="3702.dat.png" ALT="Technic Brick 1 x 8 with Holes"></td> | ||
<td><center>2</center></td> | ||
</tr> | ||
<tr><td><IMG SRC="3894.dat.png" ALT="Technic Brick 1 x 6 with Holes"></td> | ||
<td><center>2</center></td> | ||
</tr> | ||
</table> | ||
<br></CENTER> | ||
<BR><HR><BR><A HREF="washing-machine-01.html">Previous</A> <A HREF="washing-machine-03.html">Next</A><BR></HTML> |
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<HTML> | ||
<HEAD> | ||
<TITLE>washing-machine.ldr - Step 3</TITLE> | ||
</HEAD> | ||
<BR> | ||
<CENTER> | ||
<IMG SRC="washing-machine-03.png" ALT="Step 03" WIDTH=1024 HEIGHT=768><BR><BR> | ||
<br><table border=1><tr><td><center>Piece</center></td> | ||
<td><center>Black</center></td> | ||
</tr> | ||
<tr><td><IMG SRC="4459.dat.png" ALT="Technic Pin with Friction"></td> | ||
<td><center>2</center></td> | ||
</tr> | ||
</table> | ||
<br></CENTER> | ||
<BR><HR><BR><A HREF="washing-machine-02.html">Previous</A> <A HREF="washing-machine-04.html">Next</A><BR></HTML> |
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<HTML> | ||
<HEAD> | ||
<TITLE>washing-machine.ldr - Step 4</TITLE> | ||
</HEAD> | ||
<BR> | ||
<CENTER> | ||
<IMG SRC="washing-machine-04.png" ALT="Step 04" WIDTH=1024 HEIGHT=768><BR><BR> | ||
<br><table border=1><tr><td><center>Piece</center></td> | ||
<td><center>Black</center></td> | ||
</tr> | ||
<tr><td><IMG SRC="3738.dat.png" ALT="Technic Plate 2 x 8 with Holes"></td> | ||
<td><center>4</center></td> | ||
</tr> | ||
</table> | ||
<br></CENTER> | ||
<BR><HR><BR><A HREF="washing-machine-03.html">Previous</A> <A HREF="washing-machine-05.html">Next</A><BR></HTML> |
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<HTML> | ||
<HEAD> | ||
<TITLE>washing-machine.ldr - Step 5</TITLE> | ||
</HEAD> | ||
<BR> | ||
<CENTER> | ||
<IMG SRC="washing-machine-05.png" ALT="Step 05" WIDTH=1024 HEIGHT=768><BR><BR> | ||
<br><table border=1><tr><td><center>Piece</center></td> | ||
<td><center>Bright Light Yellow</center></td> | ||
</tr> | ||
<tr><td><IMG SRC="3702.dat.png" ALT="Technic Brick 1 x 8 with Holes"></td> | ||
<td><center>2</center></td> | ||
</tr> | ||
<tr><td><IMG SRC="3894.dat.png" ALT="Technic Brick 1 x 6 with Holes"></td> | ||
<td><center>1</center></td> | ||
</tr> | ||
</table> | ||
<br></CENTER> | ||
<BR><HR><BR><A HREF="washing-machine-04.html">Previous</A> <A HREF="washing-machine-06.html">Next</A><BR></HTML> |
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<HTML> | ||
<HEAD> | ||
<TITLE>washing-machine.ldr - Step 6</TITLE> | ||
</HEAD> | ||
<BR> | ||
<CENTER> | ||
<IMG SRC="washing-machine-06.png" ALT="Step 06" WIDTH=1024 HEIGHT=768><BR><BR> | ||
<br><table border=1><tr><td><center>Piece</center></td> | ||
<td><center>Black</center></td> | ||
</tr> | ||
<tr><td><IMG SRC="3022.dat.png" ALT="Plate 2 x 2"></td> | ||
<td><center>2</center></td> | ||
</tr> | ||
<tr><td><IMG SRC="3034.dat.png" ALT="Plate 2 x 8"></td> | ||
<td><center>2</center></td> | ||
</tr> | ||
</table> | ||
<br></CENTER> | ||
<BR><HR><BR><A HREF="washing-machine-05.html">Previous</A> <A HREF="washing-machine-07.html">Next</A><BR></HTML> |
Oops, something went wrong.
Oops, something went wrong.