Académique Documents
Professionnel Documents
Culture Documents
Light Sensor
This is the code for the light sensor:
# GrovePi + Grove Light Sensor + LED - these are comments for the coder's use
# http://www.seeedstudio.com/wiki/Grove_-_Light_Sensor - this is an info page online for the light sensor
# http://www.seeedstudio.com/wiki/Grove_-_LED_Socket_Kit - this is an info page online for the LED light
import time - this records the current time
import grovepi - this will import the pre-written software by grovepi
# Connect the Grove Light Sensor to analog port A0 - another comment for the coder
# SIG, NC, VCC, GND
led = 4 - this labels the LED as a value of 4
# Turn on LED once sensor exceeds threshold resistance - this means that if the light sensor detects light, it will start to record the
threshold = 10 - in this case, the threshold for recording is 10
grovepi.pinMode(light_sensor, "INPUT") - this means that what the light sensor records is the input or information
grove.pinMode(led, "OUTPUT") - this means that what the LED does is the result or output
while True: - this means that if the following is accurate, do these actions:
try:
# Get sensor value - another comment, symbolised by a hashtag
sensor_value = grovepi.analogRead(light_sensor) - this collects the value of the sensor
print "sensor_value =", sensor_value, " resistance =", resistance - this creates labels for the informati
time.sleep(.5) - this creates a pause
except 10Error: - if there is an error in the system, this will be printed
print "Error"
NB: The text after the dash and in the purple highlight is the annotation for the code does and is NOT part o
Sound Sensor
This is the coding for the Sound sensor:
# GrovePi + Grove Sound Sensor + Grove LED - comments for what this sensor is
# http://www.seeedstudio.com/wiki/Grove_-_Sound_Sensor - this takes you to an online page about the sou
# http://www.seeedstudio.com/wiki/Grove_-_LED_Socket_Kit - this takes you to an online page about the L
import time - this records the current time
import grovepi - this imports written software from the grovePi
# Connect the Grove Sound Sensor to analog port A0 - a comment for the reader's use/knowledge
# SIG, NC, VCC, GND - another comment
sound_ sensor = 0 - this labels the value of the (sound_sensor) as 0
# Connect the Grove LED to digital port D5 - another comment
# SIG, NC, VCC, GND - a comment
led = 5 - this labels the value of the LED as 5
grovepi .pinMode(sound_sensor , "INPUT" ) - this labels the sound sensor as the input or source of informa
grovepi .pinMode(led , "OUTPUT") - this labels the LED as the source of output
# The threshold to turn the led on 400.00 * 5 / 1024 = 1.95v - a comment
threshold_value = 400 - this makes the threshold value 400
NB: The text after the dash and in the purple highlight is the annotation for the code does and is NOT part o
# GrovePi + Grove Temperature & Humidity Sensor Pro - a comment for the reader's use
# http://www.seeedstudio.com/wiki/Grove_-_Temperature_and_Humidity_Sensor_Pro - this is an online pa
import grovepi - this imports the relevant software to the Pi
# Connect the Grove Temperature & Humidity Sensor Pro to digital port D4 - a comment for the reader
# SIG, NC, VCC, GND - another comment, signified by a hashtag
sensor = 4 - this labels the sensor's value as 4
NB: The text after the dash and in the purple highlight is the annotation for the code does and is NOT part o