User Manual
69
For C language users:
Step 2: Open the code file
cd /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/C
Step 3: Compile the Code
make 08_4N35
Step 4: Run the executable file above.
sudo ./08_4N35
Code Explanation
digitalWrite(_4N35Pin, LOW); // set the I/O port as low level (0V), thus the optocoupler
is energized, and the pin connected to LED conducts to the 0V. Then the LED lights up.
delay(500); // optocoupler is a kind of electronic device and there is no limitation on
its on-off frequency.
digitalWrite(_4N35Pin, HIGH); // set I/O port as high level (3.3V), thus the optocoupler
is not energized ,and the pin connected to LED cannot conduct to the 0V. Then the LED
goes out.
For Python users:
Step 2: Open the code file
cd /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/Python
Step 3: Run
sudo python 08_4N35.py
Code Explanation
GPIO.output(Pin_4N35, GPIO.LOW) # set the pins of optocoupler as low level, thus the
optocoupler is energized, and the pin connected to LED conducts to the 0V.Then the LED
lights up.
time.sleep(0.5) #wait for 0.5 second. The on-off frequency of the
optocoupler can be changed by modifying this parameter.
GPIO.output(Pin_4N35, GPIO.HIGH) # set the pins of optocoupler as high level, thus the
optocoupler is disconnected, and the pin connected to LED break the connection to the
0V. Then the LED goes out.
time.sleep(0.5)
You will see the LED blinks.
SunFounder