46
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:
Содержание Super Kit 3.0
Страница 7: ...4 22 RGB LED 1 23 LED red 8 24 LED white 4 25 LED green 4 26 LED yellow 4 27 NPN Transistor S8050 2 ...
Страница 30: ...27 Also we have drawn a table of the corresponding BCM wiringPi and Name of each pins ...
Страница 78: ...75 Now pull the slide and you can see the two LEDs light up alternately ...