Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uint8_t dataHeader = 0xff;
- uint8_t numberOfData;
- uint8_t rgb[6];
- uint8_t lRedPin = 9, lGreenPin = 10, lBluePin = 11, rRedPin = 3, rGreenPin = 5, rBluePin = 6;
- // the setup function runs once when you press reset or power the board
- void setup() {
- // initialize digital pin 13 as an output.
- pinMode(lRedPin, OUTPUT);
- pinMode(lGreenPin, OUTPUT);
- pinMode(lBluePin, OUTPUT);
- pinMode(rRedPin, OUTPUT);
- pinMode(rGreenPin, OUTPUT);
- pinMode(rBluePin, OUTPUT);
- Serial.begin(57600);
- }
- // the loop function runs over and over again forever
- void loop(){
- if (Serial.available() > 1) {
- uint8_t recievedByte = Serial.read();
- if (recievedByte == dataHeader) // read first byte and check if it is the beginning of the stream
- {
- for (uint8_t i = 0 ; i < 6 ; i++)
- {
- delay(10);
- rgb[i] = Serial.read();
- }
- }
- }
- //finally control led brightness through pulse-width modulation
- analogWrite (lRedPin, rgb[0]);
- analogWrite (lGreenPin, rgb[1]);
- analogWrite (lBluePin, rgb[2]);
- analogWrite (rRedPin, rgb[3]);
- analogWrite (rGreenPin, rgb[4]);
- analogWrite (rBluePin, rgb[5]);
- }
Advertisement
Add Comment
Please, Sign In to add comment