Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LED control value
- #define OFF 0
- #define RED 0x01
- #define GREEN 0x02
- #define BLUE 0x04
- int pin_GND = 11; // ground pin
- int pin_LED[3] = {8, 9, 10}; // red, green, blue LED pin
- void setup() {
- // put your setup code here, to run once:
- pinMode(pin_GND, OUTPUT); // ground pin Output setup
- pinMode(pin_LED[0], OUTPUT); // red LED pin Output setup
- pinMode(pin_LED[1], OUTPUT); // green LED pin Output setup
- pinMode(pin_LED[2], OUTPUT); // blue LED pin Output setup
- digitalWrite(pin_GND, LOW); // ground pin LOW Output
- }
- void loop() {
- // put your main code here, to run repeatedly:
- LED_control(RED); // red on
- delay(1000); // wait one second
- LED_control(GREEN); // green on
- delay(1000); // wait one second
- LED_control(BLUE); // blue on
- delay(1000); // wait one second
- }
- // RGB LED control function ('bxxxxxBGR' -> R-red control bit, G-greeb control bit, B-blue control bit)
- void LED_control(uint8_t da)
- {
- digitalWrite(pin_LED[0], da & 0x01); // red LED control
- da >>= 1; // 1bit shift to the right
- digitalWrite(pin_LED[1], da & 0x01); // green LED control
- da >>= 1; // 1bit shift to the right
- digitalWrite(pin_LED[2], da & 0x01); // blue LED control
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement