Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 0:0992b23a3b05
- Child:
- 1:8e28c267ff1a
diff -r 000000000000 -r 0992b23a3b05 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Mar 17 11:22:39 2011 +0000
@@ -0,0 +1,136 @@
+// A simple program to cycle a chain of shiftbrites through RGB,MCY,W using mbed.
+
+// Shift register code from: http://mbed.org/users/ChriX/notebook/shift-register-function/
+// Shiftbrite Arduino code from: http://macetech.com/blog/node/54
+
+#include "mbed.h"
+
+DigitalOut datapin(p30);
+DigitalOut latchpin(p29);
+DigitalOut enablepin(p28);
+DigitalOut clockpin(p27);
+
+unsigned long SB_CommandPacket;
+int SB_CommandMode;
+int SB_BlueCommand;
+int SB_RedCommand;
+int SB_GreenCommand;
+int No_of_shiftbrites = 4;
+
+void shiftOut(DigitalOut data, DigitalOut clk, int sodata) {
+
+ int i;
+
+ for (i = 7; i >= 0; i--) {
+
+ clk = 0;
+
+ if(sodata & (1 << i)){
+ data = 1;
+ } else {
+ data = 0;
+ }
+
+ clk = 1;
+ data = 0;
+ }
+
+return;
+
+}
+
+
+void SB_SendPacket() {
+
+ for (int y = No_of_shiftbrites-1; y >= 0; y--) {
+ SB_CommandPacket = SB_CommandMode & 0xB11;
+ 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, SB_CommandPacket >> 24);
+ shiftOut(datapin, clockpin, SB_CommandPacket >> 16);
+ shiftOut(datapin, clockpin, SB_CommandPacket >> 8);
+ shiftOut(datapin, clockpin, SB_CommandPacket);
+
+
+ wait_us(500);
+ latchpin = 1;
+ wait_us(500);
+ latchpin = 0;
+ }
+
+}
+
+int main() {
+ while(1) {
+ SB_CommandMode = 0xB01;
+ SB_RedCommand = 127;
+ SB_GreenCommand = 127;
+ SB_BlueCommand = 127;
+ SB_SendPacket();
+
+ // Red
+ SB_CommandMode = 0xB00;
+ SB_RedCommand = 127; // max = 1023
+ SB_GreenCommand = 0;
+ SB_BlueCommand = 0;
+ SB_SendPacket();
+
+ wait_ms(500);
+
+ // Green
+ SB_CommandMode = 0xB00;
+ SB_RedCommand = 0;
+ SB_GreenCommand = 127;
+ SB_BlueCommand = 0;
+ SB_SendPacket();
+
+ wait_ms(500);
+
+ // Blue
+ SB_CommandMode = 0xB00;
+ SB_RedCommand = 0;
+ SB_GreenCommand = 0;
+ SB_BlueCommand = 127;
+ SB_SendPacket();
+
+ wait_ms(500);
+
+ // Magenta
+ SB_CommandMode = 0xB00;
+ SB_RedCommand = 127;
+ SB_GreenCommand = 0;
+ SB_BlueCommand = 127;
+ SB_SendPacket();
+
+ wait_ms(500);
+
+ // Cyan
+ SB_CommandMode = 0xB00;
+ SB_RedCommand = 0;
+ SB_GreenCommand = 127;
+ SB_BlueCommand = 127;
+ SB_SendPacket();
+
+ wait_ms(500);
+
+ // Yellow
+ SB_CommandMode = 0xB00;
+ SB_RedCommand = 127;
+ SB_GreenCommand = 127;
+ SB_BlueCommand = 0;
+ SB_SendPacket();
+
+ wait_ms(500);
+
+ // White
+ SB_CommandMode = 0xB00;
+ SB_RedCommand = 127;
+ SB_GreenCommand = 127;
+ SB_BlueCommand = 127;
+ SB_SendPacket();
+
+ wait_ms(500);
+ }
+}