#Limitations caused by this software mean we are unable to input our sensors as we had planned, so we just did different colored LED's
#red LED is LED, blue LED is IR Emitter, green LED is IR Receiver, yellow LED is Ambient Light Sensor
#Program to control the state of a red LED based off IR sensor output.
#import libraries
import machine # this library is to work with external components
import utime # this library is to introduce time delay
#Configure GP14 and GP15 pins as output
red_LED = machine.Pin(14, machine.Pin.OUT)
IR_emitter = machine.Pin(15, machine.Pin.OUT)
#configure GP26 pin as ADC input and use useful name
IR_receiver = machine.ADC(26)
#infinite loop to k=continue on forever
while True:
print(IR_receiver.read_u16()/20000)
utime.sleep(0.2)
#Determine threshold by reading ADC.
#When IR-receiever exposed to light, its output is lower than the threshold.
#LED withh turn off when threshold exceeded.
# IR_emitter.value(1) turns on LED
if((IR_receiver.read_u16()/20000)>3.25): #check if IR reciever output is lower than threshold.
red_LED.value(1) #if yes turn on LED
else:
red_LED.value(0) #if no, turn off LED
import machine #machine is used to interact with the GPIO pins
import utime #utime allows the code to wait for time
#We want to make that pin the output
led_onboard = machine.Pin(15, machine.Pin.OUT)
#This is a loop to turn the light on and off
#while True:
#This next line turns it on
led_onboard.value(1)
#This next line makes the light stay on for 2 seconds
# utime.sleep(2)
#This next line turns it off
# led_onboard.value(0)
#This next line makes the light stay off for 2 seconds
# utime.sleep(2)