This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
serial-parse-led [2014/09/03 12:43] zoza |
serial-parse-led [2014/09/03 19:42] (current) zoza |
||
---|---|---|---|
Line 15: | Line 15: | ||
visit the shop for boards. | visit the shop for boards. | ||
************************************************************************************************************************************/ | ************************************************************************************************************************************/ | ||
+ | |||
// Clock and data pins are pins from the hardware SPI, you cannot choose them yourself if you use the hardware SPI. | // Clock and data pins are pins from the hardware SPI, you cannot choose them yourself if you use the hardware SPI. | ||
// Data pin is MOSI (Uno and earlier: 11, Leonardo: ICSP 4, Mega: 51, Teensy 2.0: 2, Teensy 2.0++: 22) | // Data pin is MOSI (Uno and earlier: 11, Leonardo: ICSP 4, Mega: 51, Teensy 2.0: 2, Teensy 2.0++: 22) | ||
// Clock pin is SCK (Uno and earlier: 13, Leonardo: ICSP 3, Mega: 52, Teensy 2.0: 1, Teensy 2.0++: 21) | // Clock pin is SCK (Uno and earlier: 13, Leonardo: ICSP 3, Mega: 52, Teensy 2.0: 1, Teensy 2.0++: 21) | ||
- | + | ||
- | // You can choose the latch pin yourself. const int ShiftPWM_latchPin=8; | + | // You can choose the latch pin yourself. |
+ | const int ShiftPWM_latchPin=8; | ||
+ | |||
// If your LED's turn on if the pin is low, set this to true, otherwise set it to false. | // If your LED's turn on if the pin is low, set this to true, otherwise set it to false. | ||
const bool ShiftPWM_invertOutputs = false; | const bool ShiftPWM_invertOutputs = false; | ||
+ | |||
// You can enable the option below to shift the PWM phase of each shift register by 8 compared to the previous. | // You can enable the option below to shift the PWM phase of each shift register by 8 compared to the previous. | ||
// This will slightly increase the interrupt load, but will prevent all PWM signals from becoming high at the same time. | // This will slightly increase the interrupt load, but will prevent all PWM signals from becoming high at the same time. | ||
// This will be a bit easier on your power supply, because the current peaks are distributed. | // This will be a bit easier on your power supply, because the current peaks are distributed. | ||
const bool ShiftPWM_balanceLoad = false; | const bool ShiftPWM_balanceLoad = false; | ||
+ | |||
#include <ShiftPWM.h> // include ShiftPWM.h after setting the pins! | #include <ShiftPWM.h> // include ShiftPWM.h after setting the pins! | ||
+ | |||
unsigned char maxBrightness = 128; | unsigned char maxBrightness = 128; | ||
unsigned char pwmFrequency = 75; | unsigned char pwmFrequency = 75; | ||
int numRegisters = 3; | int numRegisters = 3; | ||
int numRGBleds = 4; | int numRGBleds = 4; | ||
+ | |||
void setup(){ | void setup(){ | ||
- | Serial.begin(115200); | + | Serial.begin(19200); |
+ | |||
// Sets the number of 8-bit registers that are used. | // Sets the number of 8-bit registers that are used. | ||
ShiftPWM.SetAmountOfRegisters(numRegisters); | ShiftPWM.SetAmountOfRegisters(numRegisters); | ||
+ | |||
// SetPinGrouping allows flexibility in LED setup. | // SetPinGrouping allows flexibility in LED setup. | ||
// If your LED's are connected like this: RRRRGGGGBBBBRRRRGGGGBBBB, use SetPinGrouping(4). | // If your LED's are connected like this: RRRRGGGGBBBBRRRRGGGGBBBB, use SetPinGrouping(4). | ||
ShiftPWM.SetPinGrouping(1); //This is the default, but I added here to demonstrate how to use the function | ShiftPWM.SetPinGrouping(1); //This is the default, but I added here to demonstrate how to use the function | ||
+ | |||
ShiftPWM.Start(pwmFrequency,maxBrightness); | ShiftPWM.Start(pwmFrequency,maxBrightness); | ||
+ | |||
} | } | ||
- | + | ||
- | + | ||
+ | |||
void loop() | void loop() | ||
{ | { | ||
+ | |||
/*for(int led=0;led<numRGBleds;led++){ // loop over all LED's | /*for(int led=0;led<numRGBleds;led++){ // loop over all LED's | ||
for(int intensity=0;intensity<255;intensity++){ // loop over all LED's | for(int intensity=0;intensity<255;intensity++){ // loop over all LED's | ||
Line 71: | Line 72: | ||
int green = Serial.parseInt(); | int green = Serial.parseInt(); | ||
int blue = Serial.parseInt(); | int blue = Serial.parseInt(); | ||
- | int white = Serial.parseInt(); | + | //int white = Serial.parseInt(); |
- | ShiftPWM.SetRGBW(led, red, green, blue, white); | + | if (Serial.read() == '\n') { |
+ | ShiftPWM.SetRGBW(led, red, green, blue, 0); | ||
+ | } | ||
} | } | ||
} | } | ||
- | |||
</code> | </code> |