User Manual
48
Code Explanation
void Led_on(int channel): This is a subfunction with a formal parameter int channel for
importing the numbers of the controlled pins. Its function body is digitalWrite(channel,
LOW); Set the I/O port of channel as low level(0V), the LED on this port lights up. void
led_off(int channel) is to turn off the LED. Setting function simplifies the input for
the repeated content.
for(i=0;i<8;i++){ //make 8 pins' mode is output
pinMode(i, OUTPUT);
}//The cathodes of the 8 LEDs connect to B17, B18, B27, B22, B23, B24, B25, and B4 of
the T-shape extension board respectively, corresponding to 0,1,2,3,4,5,6,7. It is to set
the 8 LEDs as output separately. Use for loop to make it more concise and efficient.
for(i=0;i<8;i++){ //make LED on from left to right
Led_on(i); // turn the LED i on
delay(100); // keep the LED i lighting for 100ms.
Led_off(i); // Turn the LED i off
} // Light up and turn off the LEDs in GPIO0~7 successively. i increases
progressively from 0 to 7, LED0 to LED7 changes accordingly, making it like a flowing
LED light from left to right.
for(i=;i>=0;i--){ //make LED off from right to left
led_on(i); // turn the LED i on
delay(100); // keep the LED i lighting for 100ms
led_off(i); //turn the LED i off
}/ In this for loop, light up and turn off the LED in GPIO7 to GPIO0 successively,
making a flowing LED light from left to right.
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 03_8Led.py
Code Explanation
LedPins = [17, 18, 27, 22, 23, 24, 25, 4] # The cathodes of the 8 LEDs connect to B17,
B18, B27, 22, 23, 24, 25, 4 of the T-shape extension board. In BCM, these pins are
corresponding to 17, 18, 27, 22, 23, 24, 25, and 4.
leds = ['-', '-', '-', '-', '-', '-', '-', '-'] # the array to print out the status of
the 8 LEDs
SunFounder