Advertisement
gabbyshimoni

rainbow RGB Led

Feb 3rd, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. /*
  2.    03.02.2019
  3.    Written by: Gabby Shimoni
  4.    Description:
  5.    This program makes and RGB led shine with rainbow colors
  6.  
  7.    Color Description RGB Values
  8.    Violet            148, 0, 211
  9.    Indigo             75, 0, 130
  10.    Blue                0, 0, 255
  11.    Green               0, 255, 0
  12.    Yellow            255, 255, 0
  13.    Orange            255, 127, 0
  14.    Red               255, 0 , 0
  15. */
  16.  
  17. const int rgbLedPins[3] = {9, 11, 10}; // The pin numbers are : R B G
  18. int rainbow[7][3] = {
  19.   148, 0, 211,
  20.   75, 0, 130,
  21.   0, 0, 255,
  22.   0, 255, 0,
  23.   255, 255, 0,
  24.   255, 127, 0,
  25.   255, 0 , 0
  26. };
  27. String colors[7] = {"Violet", "Indigo", "Blue", "Green", "Yellow", "Orange", "Red"};
  28. void setup() {
  29.   Serial.begin(9600);
  30.   for (int i = 0; i < 3; i++) pinMode(rgbLedPins[i], OUTPUT);
  31. }
  32.  
  33. void loop() {
  34.   for (int i = 0; i < 7; i++) {
  35.     for (int j = 0; j < 3; j++) {
  36.       analogWrite(rgbLedPins[j], rainbow[i][j]);
  37.     }
  38.     Serial.print(colors[i]);
  39.     Serial.println(" is on");
  40.     delay(3000);
  41.   }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement