Helping teach in raspberry pi class

>helping teach in raspberry pi class
>teacher tells the 11 year olds to type this
while True:
b = pi.read(17)
if b == 1:
break

Attached: 1528897096405.jpg (684x546, 76K)

>python

Attached: shrek.jpg (610x368, 48K)

What's the issue?

Not a programmer. lemme try to figure this out.
>while True
While what is true? They didn't specify. All I know is there's a while loop.
>b = pi.read(17)
Ok this does one of two things. It could either be setting b to 17 in a complicated way, or maybe it's getting user input 17 times?
>if b == 1:
>break
Ok so if read is reading user input, this makes sense. if the user entered 1, break the loop. If it's setting b to 17, this is an infinite loop and the teacher is retarded.

that's acceptable for python devs.
I've seen scientific code(code that detects particles) that struggled to find if a number is a multiple of 2 by doing this
>divide number by 2
>take its integer part
>compare it with the result of the division.

a C or C++ dev would've checked only the last bit of the number.
if( ! (a & 0x1) ) { //code here }

Is it reading gpio pin 17?

fuck i guess it needs context

import pigpio
import time

pi = pigpio.pi()

pi.set_mode(17, pigpio.INPUT)
pi.set_mode(4, pigpio.OUTPUT)

while True:
b == pi.read(17)
if b == 1:
break

pi.write(4, 1)
time.sleep(1)
pi.write(4, 0)

But what is "pi"

Read() method in Python AFAIK is to read a file or something. Like that would read 17 lines in the pi file.

Unless this Pi is reserved on raspberry Pis for some input or something.

Also not a programmer, python is not programming.

> not starting the children with logic gates and assembly

congrats you’ve just created some more retards

>pigpio
>pig pio
>pig
HAAAAAAAAAAAAAAHAHAHAHAHAHAHAHAHAHAHAHAHAHAH

>implying this matters in a world where getting ahead means knowing the latest meme frameworks

I think that pi.read() is a blocking call, which means that the loop hangs until the next number is entered.
if he enters 17, it will consumed, in the next loop it will come back to pi.read, new value will be entered and then the condition will be checked again.

Don't know anything about python or raspberry pi, but It looks like it's busy waiting.

>logic gates
>assembly

Why do I need this in a world where embedded systems run node.js ontop of windows

Ok lemme try again.
So it imports some shit related to the pins and time. Then I think it's creating an object? On the next two lines it appears to be saying that input will come from pin 17, and output will be going out pin 4.
Then we do the loop, and it is indeed reading input from the 17th pin, and breaking when the input is 1. Still not sure what's supposed to be true.
Then after the loop is done it's supposed to write 1 to whatever's connected to pin 4, sleep for 1 second, and then write 0.

>b == pi.read(17)
error: variable referenced before assignment

who makes the node.js
who makes the windows

the retards who don't know how a calculator works will never make a calulator

and yet millions every day benefit from the use of a calculator without knowing how it works

because some idiots decided to learn how it worked so they could make calculators for people to benefit from.

"while true" is also sometime written as "while 1", it's just a programming convention to make an infinite loop. You pretty much nailed everything else.

Attached: 1508584238544.png (407x921, 274K)

Only error is no indent after the if check.

the code is supposed to turn on and off an LED when you press a button (pin 17)

Isn't there some kind of listener instead of an infinite loop taking up all the processing power, I dunno how raspberry pi works

Yeah, but you're waiting on input from a GPIO which likely doesn't have interrupts available on it, so all you can do is busy wait (if you want it to be quick response).
Depending what is attached to pin 17 you may not want to sleep during the loop as you could miss whatever the input is.

The only problem I really see is that it's run once. You run it, it'll wait until pin 17 goes high and then set pin 4 high for a second and then exit.

It'd still be bad general coding practice, but it's not terrible when learning.

Soooo... A busy-wait loop on pin 17, waiting until it is high, then breaking out?

You think something like
while pi.read(17)==0:
pass


would be better?

Honestly doesn't matter.
This is a group of 11-year-olds and probably their first class dealing with GPIO.

>pi gpio
>Raspberry Pi General Purpose I/O pind

OP feels superior to a bunch of prepubescent children... seems appropriate for Jow Forums.

what is the teacher going to do, teach these kids hardware interrupts in ANSI C? They're not Chinese FFS.

Attached: 1529965333565.png (900x729, 129K)

>write an interrupt routine
t-terry?

You have to go back

>checks date.
yep it's summer. Nice try.

This looks easy as fuck, even 11 should understand what is going on in here.

Step up your game you fake cringe faggot

Attached: le_cringe.gif (680x499, 1.64M)

Attached: 963247893278.jpg (800x800, 126K)