有点晚了,但我们走了):
/* Ambilight Clone Variation Using boblight and 1 Red, 1 Green, 1 Blue Strips.
Circuit is set up in a similar way to the image on this page.
http://www.jerome-bernard.com/images/rgb-led-strips-mosfets.png
Created 17 Feb 2014
By Chris O.
Ver. 0.50
*/
// constants won't change. Used here to set the PWM pin numbers / ONLY USE PWM~ PINS:
/* // Arduino Uno has 6 PWM pins.
const int Red_PWM_Pin = 3; // RED
const int Green_PWM_Pin = 5; // GREEN
const int Blue_PWM_Pin = 6; // BLUE
*/
const int Red_PWM_Pin = 9; // RED
const int Green_PWM_Pin = 10; // GREEN
const int Blue_PWM_Pin = 11; // BLUE
// Set Serial Baud Rate here and in boblight.conf file.
// Use one of these rates: 9600, 14400, 19200, 28800, 38400, 57600, or 115200.
#define Baud_Rate 57600
// Variables will change:
byte RedValue = 0x00; //HEX
byte GreenValue = 0;
byte BlueValue = 0;
// ***********************************************************************************************************
// *
// * Power Up Init.
// *
// *
// ***********************************************************************************************************
void setup() {
/* Test led strips on Power Up */
analogWrite(Red_PWM_Pin, 127); //DEC / Set the pin to 50% (0~255)
analogWrite(Green_PWM_Pin, 0x7F); //HEX
analogWrite(Blue_PWM_Pin, 127); //DEC
delay(1000); // wait for a second
analogWrite(Red_PWM_Pin, 0); //DEC
analogWrite(Green_PWM_Pin, 0x00); //HEX
analogWrite(Blue_PWM_Pin, 0); //DEC
Serial.begin(Baud_Rate); //Serial.begin(115200);
}
// ***********************************************************************************************************
// *
// * Main Loop
// *
// *
// ***********************************************************************************************************
void loop()
{
if (Serial.available()>=4){ // if Serial Hardware Buffer has 4 or more bytes
byte prefix1 = Serial.read(); // 1st prefix (HEX 0xFF) (DEC 255)
// byte prefix2 = Serial.read(); // 2nd prefix (HEX 0x8F) (DEC 143)
if (prefix1 == 0xFF){// && prefix2 == 0x8F){ // Do this only if we find the prefix
RedValue = Serial.read(); //read 2nd byte
analogWrite(Red_PWM_Pin, RedValue);
GreenValue = Serial.read(); //read 3rd byte
analogWrite(Green_PWM_Pin, GreenValue);
BlueValue = Serial.read(); //read 4th byte
analogWrite(Blue_PWM_Pin, BlueValue);
}
else { // if no prefix found lets dump 1 byte of serial HW Buffer.
byte dump = Serial.read();
/* debug led */
// Pin 13 has an LED connected on most Arduino boards, On Leonardo its PWM~ pin, on Uno it will go high if dump value is over 127
// Pin 11 has the LED on Teensy 2.0
// Pin 6 has the LED on Teensy++ 2.0
// Pin 13 has the LED on Teensy 3.0
analogWrite(13, dump); //debug led
//Serial.println(dump);
}
}
}
// ***********************************************************************************************************
// * Copy This in to boblight.conf file
// * for windows boblight 1.3 beta1
// *
// * for windows boblight 1.3 beta1 go to The LiveLight Project http://www.livelightproject.com/
// * http://www.livelightproject.com/downloads/Boblight/Boblight_for_V5.zip
// ***********************************************************************************************************
/*
[global]
timeout 20
#interface 127.0.0.1 not in use here
port 19333
# interpolation off # on or off
# proportional 7.0
# saturation 5.0
# value 10.0
# valuerange 0.0 1.0
# use no
# method average
# threshold 20
[device]
name arduino_ambilight
type momo
output "com11" # <-- set youre arduino port
rate 57600 # Use one of these rates: 9600, 14400, 19200, 28800, 38400, 57600, or 115200.
channels 3
prefix FF # NOTE: this FF 8F prefix will not work in Win Boblight beta1.3
# postfix not in use here, will not work in Win Boblight beta1.3
interval 40000
# allowsync on not in use here
debug off
delayafteropen 20000000
[color]
name red
rgb FE0000
[color]
name green
rgb 00FE00
[color]
name blue
rgb 0000FE
[light]
name main
color red arduino_ambilight 1
color green arduino_ambilight 2
color blue arduino_ambilight 3
hscan 0 100
vscan 0 100
*/