-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
523 lines (466 loc) · 16.1 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Raspbery Pi Python Coding 101</title>
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/black.css">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/monokai.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section id="start">
<h2>Raspbery Pi<br/>Python Coding 101</h2>
<img src="images/synshop.logo.v4.svg" style="width: 25%;"/><br/>
SYN Shop, Henderson, Nevada, USA<br/>
<a href="https://github.com/synshop/RaspberryPiCoding101/">
Fork This Project on Github
<img src="./images/Ei-sc-github.svg" style="filter: invert(100%); height: 50px" />
</a>
</section>
<section>
<h1>Goals</h1>
<ol>
<li>Learn to code Python in 3 hours<br/>or less</li>
<li>Inspire you to do more with your<br/>Raspberry Pi after you leave</li>
<li>Inspire to hack more in life ;)</li>
</ol>
</section>
<section>
<h1>Agenda</h1>
<ul>
<li><a href="#/lesson0">0: Patience, Parts, & Prep</a></li>
<li><a href="#/lesson1">1: Hello World</a></li>
<li><a href="#/lesson2">2: Light</a></li>
<li><a href="#/lesson3">3: Button</a></li>
<li><a href="#/lesson4">4: Light Button Game</a></li>
</ul>
</section>
<section id="lesson0">
<h2>0: Patience, Parts & Prep</h2>
<p>
Know your parts! Reference next parts side to know what's what.
</p>
<p>
Be patient! Confusion 🤯 is expected when learning something new. We're are here
to help! 🤗
</p>
<p>
Finally - help others if they look like they need it!
</p>
</section>
<section >
<h2>0: Parts List</h2>
<table class="parts-table">
<tbody>
<tr>
<td nowrap>Raspberry Pi</td>
<td><img src="images/pi4.board.jpeg"/></td>
<td>HDMI Cable</td>
<td><img src="images/hdmi.cable.jpeg"/></td>
</tr>
<tr>
<td>LED</td>
<td><img src="images/LED2.jpeg"/> </td>
<td>Case</td>
<td><img src="images/laser.cut.case.jpg"/></td>
</tr>
<tr>
<td>Button</td>
<td><img src="images/button.jpeg"/></td>
<td>Power Supply</td>
<td><img src="images/power.supply.jpeg" /></td>
</tr>
<tr>
<td nowrap>GPIO Pins</td>
<td><img src="images/gpio.pins.png"/></td>
<td>HDMI Cable</td>
<td><img src="images/hdmi.cable.jpeg"/></td>
</tr>
<tr>
<td>GPIO leaf</td>
<td><img src="images/GPIO.leaf.jpeg"/></td>
<td nowrap>Micro SD Card</td>
<td><img src="images/micro.sd.card.jpeg"/></td>
</tr>
<tr>
<td colspan="4" >Display, Keyboard & Mouse</td>
</tr>
</tbody>
</table>
</section>
<section id="">
<h2>0: Prep your Raspberry Pi</h2>
<ol>
<li>Place GPIO leaf over the GPIO pins</li>
<li>Put Micro SD Card into slot on Pi (it may be there already)</li>
<li>Plug HDMI cable into monitor and Pi (use left HDMI on Pi)</li>
<li>Plug keyboard and mouse into PI</li>
<li>Plug the Power supply into the powerstrip and finally into the Pi</li>
</ol>
<p>Your Pi should start up and show on the screen. No? Check all connections, remove
and re-insert SD card, try again.</p>
</section>
<section id="" class="reduced_images">
<h2>0: Get ready to start coding</h2>
<p>
Open "Mu" and "Chromium Web Browser": <img src="images/launcher.icons.png" style="width: 10%; ">
</p>
<p>
Arrange the windows like this:<br/>
<img src="images/side.by.side.png" />
</p>
</section>
<section id="lesson1">
<h2>1: Hello World</h2>
<p>In Mu enter this code and click the <img src="images/run.button.png" /> button.</p>
<pre><code class="hljs" data-trim >
print("Hello World")
</code></pre>
<p> When prompted to save, find the
<code>Documents</code> folder and name the file <code>Lesson1.py</code>.</p>
<p>If "Hello World" shows up below, congrats you're now a coder! 🎉🙌🏽</p>
<p>If "Hello World" doesn't show up, congrats, you're a coder too, but now can debug like a coder 🤪</p>
</section>
<section id="">
<h2>1: Hello World++</h2>
<p>Let's add the concept of a <code>while</code> loop and a few variables.
Edit your code to look like it does below and where
it says <code>YOUR_NAME</code> put your name instead:</p>
<pre><code class="hljs" data-trim data-line-numbers>
name = "YOUR_NAME"
count = 1
while count < 6:
print("Hi " + name + " count is " + str(count))
count += 1
print("Bye!")
</code></pre>
<p>Click the <img src="images/stop.button.png" /> button and then the <img src="images/run.button.png" /> button.
5 lines should show like: <code>Hi Bob count is 4</code>.
</p>
<p>Note - code in this presentation has line numbers (eg 1-6 above). Don't type those in your
editor! That's just for the educator to be able to reference the code.</p>
</section>
<section id="">
<h2>1: Hello World wrap up</h2>
<p>
Nice work! </p>
<p>You should now know how to assign variables
as seen with <code>name</code>
and <code>count</code>. As well, we made a
<code>while</code> loop run for 5 times increasing the
<code>count</code> variable by one each time. Finally, you have to start
and stop the code when you make changes want to try the code again.
</p>
<p>Feel free to go
back and change this code to do different things. Can you make it run 100 times? Print emoji 🤷♀️?
What if you do <code>count += 2</code>?
Have fun with it!
</p>
</section>
<section id="lesson2" >
<h2>2: Light</h2>
<p>
Now let's control that LED light you have there! Connect the LED wires to the GPIO pins as follows:
</p>
<p>
Black -> GND Red -> #18<br/>Green -> #23 Blue -> #24
</p>
<img src="images/GPIO.leaf.LED.png" />
</section>
<section id="">
<h2>2: Light Prep</h2>
<p>
Create a new document by clicking the new <img src="images/new.button.png"/> button. Click
the save <img src="images/save.button.png" /> button and call it
<code>Lesson2.py</code> (be sure it's next to
<code>Lesson1.py</code> in <code>Documents</code>!)
</p>
<p>
To give this script more powers, we'll import libraries called
<code>gpiozero</code> and <code>time</code>. We'll also declare a variable
with the GPIOP pins we used above (18, 23 and 24) with <code>RGBLED(18, 23, 24)</code>.
Finally, we'll pause our
script for a moment using <code>sleep()</code>.
Go to the next slide to see how!
</p>
</section>
<section>
<h2>2: Light Code</h2>
<p>
Put this into your new document and run it <img src="images/run.button.png" />:
<pre><code class="hljs" data-trim data-line-numbers>
from gpiozero import *
import time
led = RGBLED(18, 23, 24)
led.on()
time.sleep(1)
led.off()
</code></pre>
</p>
<p>
Did your light turn on?! Awesome if yes!🤩
</p>
<p>
If not, no problem! Debug it or ask for help.
</p>
</section>
<section id="">
<h2>2: Light Two times</h2>
<p>
Let's pump up the jam with some more colors!
Try this:
<pre><code class="hljs" data-trim data-line-numbers>
from gpiozero import *
import time
led = RGBLED(18, 23, 24)
led.red = 1
time.sleep(1)
led.off()
led.blue= 1
time.sleep(1)
led.off()
</code></pre>
</p>
<p>
Did you see a two light disco party? Rock on! 🤘 Did your code crash? No problem,
debug away or ask for help!
</p>
</section>
<!-- <section id="">-->
<!-- <h2>2: Light Crazy times</h2>-->
<!-- <p>-->
<!-- You should now know how to turn your light on and off. You also know-->
<!-- how to wait for one second. If I tell you that there's another-->
<!-- <code>led.green</code> color, can you-->
<!-- use a <code>while</code> loop to make it blink 10 times using 4 different colors?-->
<!-- What about blinking in a forever loop?!-->
<!-- </p>-->
<!-- </section>-->
<section id="lesson3">
<h2>3: Button</h2>
<p>
Now we'll listen for a button press. Connect the two wires to the GPIO pins as follows:
</p>
<p>
One wire -> GND The other wire -> #25
</p>
<p>
It doesn't matter which wire goes to which pin. Like you did the past lesson,
create a new file called <code>Lesson3.py</code> and to the next slide to see the code.
</p>
</section>
<section id="">
<h2>3: Button Press</h2>
<pre><code class="hljs" data-trim data-line-numbers>
from gpiozero import *
button = Button(25)
def turn_on():
print("Hi!")
def turn_off():
print("Bye!")
while True:
button.when_pressed = turn_on
button.when_released = turn_off
</code></pre>
<p>
It'll say "Hi!" when pressed and "Bye!" when released. If not,
time to get good at debugging! Did you know the best coders are the best dubuggers?!
</p>
</section>
<section id="">
<h2>3: Button Review</h2>
<p>
<ol>
<li>infinite loops with <code>while True;</code> instead of just looping a few times.</li>
<li>creating a function with <code>def turn_off():</code> and <code>def turn_on():</code></li>
<li>with the new functions we created, we can have them called when pressed <code>button.when_pressed =
turn_on</code> and released <code>button.when_released = turn_off</code></li>
<li>creating a button object using GPIO pin 25 with <code>button = Button(25)</code></li>
</ol>
</p>
</section>
<section id="lesson4">
<h2>4: Light Button Game</h2>
<p>
We're now going to use all the concepts we learned, and two more, to write a game. This will be fun!
First hook up your 2nd button (again, it doesn't matter which is which):
</p>
<p>
One wire -> GND The other wire -> #12
</p>
<p>
Create a new file called <code>Lesson4.py</code> next to the other three files. Over the
next slides, you'll add each new section at the bottom of the <code>Lesson4.py</code>
file.
</p>
</section>
<section id="">
<h2>4: Imports </h2>
<p>
Let's import three libraries. Along with sleeping and talking to our buttons and LED,
<code>randrange</code>
will allow us to <code>sleep()</code> a random time - perfect for a game!
</p>
<p>
<pre><code class="hljs" data-trim data-line-numbers>
from gpiozero import *
from random import randrange
import time
</code></pre>
</p>
</section>
<section id="">
<h2>4: Variables</h2>
<p>
We're going to create a new variable type called a list. It's the <code>players</code> list!
As well, we'll ensure we have the other variables we used before:
</p>
<p>
<pre><code class="hljs" data-trim data-line-numbers>
players = [0, 0]
button1 = Button(25)
button2 = Button(12)
led = RGBLED(18, 23, 24)
</code></pre>
</p>
</section>
<section id="">
<h2>4: Function lightCheck()</h2>
<p>
This function checks if the light is on, checks which player pressed the button and gives
you a point or takes away a point:
</p>
<p>
<pre><code class="hljs" data-trim data-line-numbers>
def lightCheckPrintScore(player):
player = player - 1
if led.is_lit:
led.off()
players[player] += 1
else:
players[player] -= 1
print()
print("Player 1: " + str(players[0]))
print("Player 2: " + str(players[1]))
</code></pre>
</p>
</section>
<section id="">
<h2>4: Function buttonCheck()</h2>
<p>
This function simply checks if a button was pressed and then calls
<code>lightCheckPrintScore()</code> passing it the button that was pressed.
</p>
<p>
<pre><code class="hljs" data-trim data-line-numbers>
def buttonCheck(button_number):
if button_number == 1:
return lambda: lightCheckPrintScore(button_number)
if button_number == 2:
return lambda: lightCheckPrintScore(button_number)
</code></pre>
</p>
</section>
<section id="">
<h2>4: Endless Loop</h2>
<p>
We'll need to endlessly loop and wait a random amount time here:
</p>
<p>
<pre><code class="hljs" data-trim data-line-numbers>
while True:
button1.when_pressed = buttonCheck(1)
button2.when_pressed = buttonCheck(2)
led.on()
time.sleep(randrange(5))
</code></pre>
</p>
</section>
<section id="">
<h2>4: Light complete code</h2>
<p>
<pre><code class="hljs" data-trim data-line-numbers>
from gpiozero import *
from random import randrange
import time
players = [0, 0]
button1 = Button(25)
button2 = Button(12)
led = RGBLED(18, 23, 24)
def lightCheckPrintScore(player):
player = player - 1
if led.is_lit:
led.off()
players[player] += 1
else:
players[player] -= 1
print()
print("Player 1: " + str(players[0]))
print("Player 2: " + str(players[1]))
def buttonCheck(button_number):
if button_number == 1:
return lambda: lightCheckPrintScore(button_number)
if button_number == 2:
return lambda: lightCheckPrintScore(button_number)
while True:
button1.when_pressed = buttonCheck(1)
button2.when_pressed = buttonCheck(2)
led.on()
time.sleep(randrange(5))
</code></pre>
</p>
</section>
<section id="">
<h1>You started coding! You’re awesome!</h1>
Starting is the hardest part ;)
</section>
</div>
</div>
<script src="js/reveal.js"></script>
<style>
img { vertical-align: middle; }
.reveal section img { border:0; background: inherit; }
.parts-table img, .reduced_images img { width: 30%;}
.parts-table td { font-size: 22px;}
.reveal .parts-table th, .reveal .parts-table td { border-bottom: 0; }
.parts-table img:hover, .reduced_images img:hover { width:100%; }
.parts-table tr { padding:0; }
p code {background: #272822; color: #a6e22e;font-family: monospace;padding: 5px; font-size: .65em;}
p code, li code {background: #272822; color: #a6e22e;font-family: monospace;padding: 5px; font-size: .65em;}
p { text-align: left; }
</style>
<script>
// More info https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
center: true,
hash: true,
controlsTutorial: false,
transition: 'none', // none/fade/slide/convex/concave/zoom
// More info https://github.com/hakimel/reveal.js#dependencies
dependencies: [
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js' },
{ src: 'plugin/search/search.js', async: true },
{ src: 'plugin/zoom-js/zoom.js', async: true },
{ src: 'plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>