Created
March 25, 2020 06:27
-
-
Save jpliew/b5684679f0fbb2b7ec6d885198526293 to your computer and use it in GitHub Desktop.
Tutorial 3 - 1D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int pinR = 10; | |
int pinG = 9; | |
int pinB = 11; | |
int btnPin = 2; | |
int isPressed =0; | |
void setup() { | |
pinMode(pinR, OUTPUT); | |
pinMode(pinG, OUTPUT); | |
pinMode(pinB, OUTPUT); | |
pinMode(btnPin, INPUT); | |
} | |
void RGBLed(int R, int G, int B) { | |
analogWrite(pinR, R); | |
analogWrite(pinG, G); | |
analogWrite(pinB, B); | |
} | |
void loop() { | |
RGBLed(255,0,0); // RED | |
delay(2000); | |
RGBLed(255,50,0); // YELLOW | |
delay(500); | |
RGBLed(0,255,0); // GREEN | |
delay(2000); | |
isPressed=digitalRead(btnPin); | |
while(isPressed) { | |
RGBLed(255,50,0); // Yellow ON | |
delay(1000); | |
RGBLed(0,0,0); // All LED OFF | |
delay(1000); | |
isPressed=digitalRead(btnPin); // Keep checking button until release | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment