I’ve just started dabbling with getting my imp to control a string of three shiftbrite 2.0 LEDs and I’m having a bit of a problem understanding how to convert my arduino code into squirrel.
The Shiftbrite 2.0 documentation is here: http://docs.macetech.com/doku.php/shiftbrite_2.0
It shifts in the bits for each led using spi, on my arduino I used the same function as shown in the tutorial code to do this:
`
void SB_SendPacket() {
if (SB_CommandMode == B01) {
SB_RedCommand = 120;
SB_GreenCommand = 100;
SB_BlueCommand = 100;
}
SPDR = SB_CommandMode << 6 | SB_BlueCommand>>4;
while(!(SPSR & (1<<SPIF)));
SPDR = SB_BlueCommand<<4 | SB_RedCommand>>6;
while(!(SPSR & (1<<SPIF)));
SPDR = SB_RedCommand << 2 | SB_GreenCommand>>8;
while(!(SPSR & (1<<SPIF)));
SPDR = SB_GreenCommand;
while(!(SPSR & (1<<SPIF)));
}
`
However, i’m not sure how I can implement this on the imp. I started off by trying to something like this:
local tosend = blob(('B00' << 6) | (blue>>4)); tosend += blob((blue<<4)|(red>>6)); tosend += blob((red << 2 | (green >> 8)); tosend += blob(green); hardware.spi257.write(tosend );
But this did not work at all (Unsurprisingly I have very little experience with bit shifting and SPI in general!). I haven’t been able to find anything that helps me convert this type of bit shifting to squirrel so I was wondering if anyone has done something similar or knows of some imp functionality that could help me achieve this?
Thanks!