/*
Problem 1: writeRGB
An RGB LED is hooked up to the arduino. Use the analogWrite function,
create a function that takes 3 inputs from 0 -> 255 and writes them to the RGB LED.
Try to be ROBUST in your approach, what happens if someone enters something outside these bounds?
What arduino function would prevent this from causing an issue?
*/
const int red = 3;
const int green = 5;
const int blue = 6;
void setup() {
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
}
void loop() {
//The loop code is already set up for you, and cycles through each color
writeRGB(0,0,0);
delay(1000);
writeRGB(0,0,255);
delay(1000);
writeRGB(0,255,0);
delay(1000);
writeRGB(0,255,255);
delay(1000);
writeRGB(255,0,0);
delay(1000);
writeRGB(255,0,255);
delay(1000);
writeRGB(255,255,0);
delay(1000);
writeRGB(255,255,255);
delay(1000);
}
//Create your function here!
void writeRGB(byte r,byte g,byte b) { //defines function "writeRGB" and constrains r, g, and b to 0-255 as the data type is bytes, not ints
analogWrite(red,r);
analogWrite(green,g);
analogWrite(blue,b);
}