User Manual
77
cd /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/C
Step 3: Compile
make 10_slideSwitch
Step 4: Run the executable file abov e.
sudo ./10_slideSwitch
Code Explanation
// When the slide is pulled to the left, the middle pin and left one are connected; the Raspberry
Pi reads a high level at the middle pin, so the LED1 is on and LED2 off
if(digitalRead(slidePin) == 1){
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
printf("LED1 on\n");
}
// When the slide is pulled to the right, the middle pin and right one are connected; the
Raspberry Pi reads a low, so the LED2 is on and LED1 off
if(digitalRead(slidePin) == 0){
digitalWrite(led2, LOW);
digitalWrite(led1, HIGH);
printf(".....LED2 on\n");
}
For Python users:
Step 2: Get into the folder of the code
cd /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/Python
Step 3: Run
sudo python 10_slideSwitch.py
Code Explanation
When the slide is pulled to the left, the middle pin and left one are connected; the
Raspberry Pi reads a high level at the middle pin, so the LED1 is on and LED2 off.
if GPIO.input(slidePin) == 1:
print 'LED1 ON (High Value)'
GPIO.output(led1Pin, GPIO.LOW)
GPIO.output(led2Pin, GPIO.HIGH)
When the slide is pulled to the right, the middle pin and right one are connected; the
Raspberry Pi reads a low, so the LED2 is on and LED1 off.
if GPIO.input(slidePin) == 0:
print 'LED2 ON (Low Value)'
SunFounder