Discuss Scratch

Mikeburton_2000
New to Scratch
2 posts

MagPi Alarm project - re script in Scratch

Hi good people of the forums;

I am VERY much a noob to all things, Pi, code and breadboard. My kids have just been introduced to Scratch at school and I just got a RasPi to us all to play with. We have all been reading through the back issues of TheMagPi magazine and have been building their small In Control projects.

We got to issue 4 where they showed how to build and script a small “intruder alarm” project. I gathered up all the parts required and we set about building the project. We copied the Python script directly from the magazines PDF file, being careful to preserve the indenting etc. However when we run the script, a whole raft of errors are produced. The first being a syntax error at the first print command. I used variations of the ‘ “ and (” to open and close and got a little further, but the whole thing was a bit too buggy for me to pick through with my very limited knowledge. I tried Python language references etc but couldn’t see anything that jumped out like incorrect indenting, missing ;'s etc.

I wonder if i could call upon the people herein for few things;
A) Could someone give me some pointers as to why the code below fails
B) I would like to try and translate the script into Scratch for the GPIO version to make the alarm. I have a question about Pin 11 which is used in the original Python script. In scratch although the extensions are installed etc, Pin 11 does not feature in the SENSOR list. Is this because it is identified as a button or something else?
C) In the Python code, can the pin numbers used be changed?

Sorry if any of this is gob smackingly obvious but please bear with me, I will get there in the end! Thanks in advance to any all who offer assistance.
Mike Burton

Python Code:

import RPi.GPIO as GPIO
import time
GPIO.setmode (GPIO.BOARD)
GPIO.setup (11, GPIO.IN)
GPIO.setup (12, GPIO.OUT)
GPIO.setup (13, GPIO.IN)
GPIO.setup (15, GPIO.OUT)
while True:
if not GPIO.input(11):
if GPIO.input(13):
print “The door is open please close the door and try again”
GPIO.output(15, True)
time.sleep(.3)
GPIO.output(15, False)
flash = 3
while flash > 0:
GPIO.output(12, True)
time.sleep(.3)
GPIO.output(12, False)
time.sleep(.3)
flash = 1
else:
active = “true”
activated = “false”
time.sleep(.1)
if GPIO.input(11):
print “Alarm Armed”
while active == “true”:
GPIO.output(12,False)
if not GPIO.input(11):
time.sleep(.1)
if GPIO.input(11):
Print (“disarmed”)
time.sleep(.1)
active = “false”
if GPIO.input(13):
print (“ALARM”)
activated = “true”
GPIO.output(15, True)
time.sleep(10)
GPIO.output(15, False)
while activated == ‘true’:
if not GPIO.input(11):
time.sleep(.1)
if GPIO.input(11):
print “Alarm Disarmed”
time.sleep(.1)
active = ‘false’
activated = ‘false’
else:
GPIO.output(12, True)
time.sleep(.3)
GPIO.output(12, False)
time.sleep(.3)
else:
GPIO.output(12,True)





drmcw
Scratcher
1000+ posts

MagPi Alarm project - re script in Scratch

This is a Scratch forum. You may get someone to help but would be better off in the raspberry pi python forum or a python one. For Scratch and GPIO try the connecting to the physical world forum.

10 !
ScratchVaders or Galaga?
Maybe Eliza can help you decide?

Powered by DjangoBB