Now it's time to write code using the Arduino IDE. Let’s break it down into steps:
Follow along with the code in the image below!
// Lesson 5
// Variables
// Serial monitor must be set to "NO LINE ENDING"
int redPin = 3;
int greenPin = 5;
int bluePin = 6;
int dtGreen = 500;
int dtBlue = 1000;
int dtRed = 1500;
void setup() {
// put your setup code here, to run once:
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
//put your main code here, to run repeatedly:
digitalWrite(greenPin, HIGH);
delay(dtGreen);
digitalWrite(greenPin, LOW);
delay(dtGreen);
digitalWrite(bluePin, HIGH);
delay(dtBlue);
digitalWrite(bluePin, LOW);
delay(dtBlue);
digitalWrite(redPin, HIGH);
delay(dtRed);
digitalWrite(redPin, LOW);
delay(dtRed);
}
Did it work as expected? If not, no worries! Check your code using the troubleshooting steps from Lesson 3.