Hi elco and others,
sorry about posting to the blog, I did'nt know about the support thread.
Ok so I have a problem using more than 7 registers and passing data on the fly trough serial. You can see a video of the thing working with 7 SR here:
When I take the serial option out I can go way over 7 SR but with the serial option I get very weird behavior from 8 and up. Including the servo.h didn't change anything.
Have anyone had this problem ? Where do I go wrong ? (see code below)
Also, there are concepts about the timer library that I still don't get, anyone knows a tutorial that "really takes you by the hand" on this ?
Thanks,
here is my arduino code:
//#include <Servo.h>
#include <SPI.h>
#include <Messenger.h>
//Data pin is MOSI (atmega168/328: pin 11. Mega: 51)
//Clock pin is SCK (atmega168/328: pin 13. Mega: 52)
const int ShiftPWM_latchPin=8;
const bool ShiftPWM_invertOutputs = 0;
#include <ShiftPWM.h> // include ShiftPWM.h after setting the pins!
unsigned char maxBrightness = 255;
unsigned char pwmFrequency = 75;
int numRegisters = 7;
Messenger message = Messenger();
int r = 0;
// Define messenger function
void messageCompleted() {
int pin = message.readInt();
int value = message.readInt();
ShiftPWM.SetOne(pin, value);
}
void setup() {
pinMode(ShiftPWM_latchPin, OUTPUT);
SPI.setBitOrder(LSBFIRST);
// SPI_CLOCK_DIV2 is only a tiny bit faster in sending out the last byte.
// SPI transfer and calculations overlap for the other bytes.
SPI.setClockDivider(SPI_CLOCK_DIV4);
SPI.begin();
Serial.begin(115200);
ShiftPWM.SetAmountOfRegisters(numRegisters);
ShiftPWM.Start(pwmFrequency,maxBrightness);
ShiftPWM.SetAll(r);
// ShiftPWM.PrintInterruptLoad();
message.attach(messageCompleted);
}
void loop() {
while ( Serial.available( ) ) message.process(Serial.read( ) );
}