Editing ShiftBrite

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
Test Code (Simplified Example)
Cycles Red/Green/Blue full on for 4 lights
<pre>
int datapin  = 11; // DI
int latchpin = 12; // LI
int enablepin = 13; // EI
int clockpin = 15; // CI
unsigned long SB_CommandPacket;
int SB_CommandMode;
int SB_BlueCommand;
int SB_RedCommand;
int SB_GreenCommand;
int shiftDelay = 250;
void setup() {
  pinMode(datapin, OUTPUT);
  pinMode(latchpin, OUTPUT);
  pinMode(enablepin, OUTPUT);
  pinMode(clockpin, OUTPUT);
  digitalWrite(latchpin, LOW);
  digitalWrite(enablepin, LOW);
 
  SB_CommandMode = B01; // Write to current control registers
  SB_RedCommand = 127; // Full current == 127
  SB_GreenCommand = 127;
  SB_BlueCommand = 127;
  SB_SendPacket();
}
void SB_SendPacket() {
  SB_CommandPacket = SB_CommandMode & B11;
  SB_CommandPacket = (SB_CommandPacket << 10)  | (SB_BlueCommand & 1023);
  SB_CommandPacket = (SB_CommandPacket << 10)  | (SB_RedCommand & 1023);
  SB_CommandPacket = (SB_CommandPacket << 10)  | (SB_GreenCommand & 1023);
  shiftOut(datapin, clockpin, MSBFIRST, SB_CommandPacket >> 24);
  shiftOut(datapin, clockpin, MSBFIRST, SB_CommandPacket >> 16);
  shiftOut(datapin, clockpin, MSBFIRST, SB_CommandPacket >> 8);
  shiftOut(datapin, clockpin, MSBFIRST, SB_CommandPacket);
  delay(5); // adjustment may be necessary depending on chain length
  digitalWrite(latchpin,HIGH); // latch data into registers
  delay(5); // adjustment may be necessary depending on chain length
  digitalWrite(latchpin,LOW);
}
void goRed() {
  for (int i = 0; i < 4; i++) {
  SB_CommandMode = B00; // Write to PWM control registers
  SB_RedCommand = 127;
  SB_GreenCommand = 0;
  SB_BlueCommand = 0;
  SB_SendPacket();
  } 
}
void goBlue() {
  for (int i = 0; i < 4; i++) {
    SB_CommandMode = B00; // Write to PWM control registers
    SB_RedCommand = 0;
    SB_GreenCommand = 127;
    SB_BlueCommand = 0;
    SB_SendPacket();
  } 
}
void goGreen() {
  for (int i = 0; i < 4; i++) {
    SB_CommandMode = B00; // Write to PWM control registers
    SB_RedCommand = 0;
    SB_GreenCommand = 0;
    SB_BlueCommand = 127;
    SB_SendPacket();
  } 
}
void loop() {
  goRed();
  delay(shiftDelay);
  goBlue();
  delay(shiftDelay);
  goGreen();
  delay(shiftDelay);
}
</pre>
Sample Code from macetech (http://macetech.com/blog/node/54)
Sample Code from macetech (http://macetech.com/blog/node/54)


Please note that all contributions to Noisebridge are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Noisebridge:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel Editing help (opens in new window)