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.
Fork of DotStar by
Diff: main.cpp
- Revision:
- 0:27f99fa5a413
- Child:
- 1:8ad764aed49f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Mar 17 03:08:32 2016 +0000
@@ -0,0 +1,53 @@
+/*
+ * APA102 (Adafruit DotStar LED Strip)
+ */
+
+#include "mbed.h"
+
+#define LED_NUM 100
+#define LED_GLOBAL 31 // brightness 0-31
+#define LED_FREQ 500000 // spi
+
+DigitalOut myled(LED1);
+SPI spi(P0_21, P0_22, P1_15);
+
+int led_buf[LED_NUM];
+
+void dotsStar () {
+ int i;
+
+ // start frame
+ for (i = 0; i < 4; i ++) {
+ spi.write(0);
+ }
+ // led frame
+ for (i = 0; i < LED_NUM; i ++) {
+ spi.write((7<<5) | LED_GLOBAL);
+ spi.write((led_buf[i] >> 16) & 0xff); // B
+ spi.write((led_buf[i] >> 8) & 0xff); // G
+ spi.write(led_buf[i] & 0xff); // R
+ }
+ // end frame
+ for (i = 0; i < 4; i ++) {
+ spi.write(1);
+ }
+}
+
+int main() {
+ int i, c;
+ int color = 1;
+
+ spi.frequency(LED_FREQ);
+
+ for (;;) {
+ for (i = 0; i < LED_NUM; i ++) {
+ c = ((color + i) % 7) + 1;
+ led_buf[i] = (c & 4 ? 0xff0000 : 0) | (c & 2 ? 0xff00 : 0) | (c & 1 ? 0xff : 0);
+ }
+ dotsStar();
+ myled = !myled;
+ color ++;
+ if (color > 7) color = 1;
+ wait(0.2);
+ }
+}
