jotto

Untitled

Jan 16th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. uint8_t dataHeader = 0xff;
  2. uint8_t numberOfData;
  3. uint8_t rgb[6];
  4. uint8_t lRedPin = 9, lGreenPin = 10, lBluePin = 11, rRedPin = 3, rGreenPin = 5, rBluePin = 6;
  5.  
  6. // the setup function runs once when you press reset or power the board
  7. void setup() {
  8.   // initialize digital pin 13 as an output.
  9.   pinMode(lRedPin, OUTPUT);
  10.   pinMode(lGreenPin, OUTPUT);
  11.   pinMode(lBluePin, OUTPUT);
  12.   pinMode(rRedPin, OUTPUT);
  13.   pinMode(rGreenPin, OUTPUT);
  14.   pinMode(rBluePin, OUTPUT);
  15.   Serial.begin(57600);
  16. }
  17.  
  18. // the loop function runs over and over again forever
  19. void loop(){
  20.     if (Serial.available() > 1) {
  21.  
  22.         uint8_t recievedByte = Serial.read();
  23.  
  24.         if (recievedByte  == dataHeader) // read first byte and check if it is the beginning of the stream
  25.         {
  26.            
  27.             for (uint8_t i = 0 ; i < 6 ; i++)
  28.             {
  29.                 delay(10);
  30.                 rgb[i] = Serial.read();
  31.             }
  32.         }
  33.     }
  34.      //finally control led brightness through pulse-width modulation
  35.     analogWrite (lRedPin, rgb[0]);
  36.     analogWrite (lGreenPin, rgb[1]);
  37.     analogWrite (lBluePin, rgb[2]);
  38.     analogWrite (rRedPin, rgb[3]);
  39.     analogWrite (rGreenPin, rgb[4]);
  40.     analogWrite (rBluePin, rgb[5]);
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment