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.
Dependencies: NeoStrip SerialDriver mbed-rtos mbed
Diff: main.cpp
- Revision:
- 4:cea8cd2c44e4
- Parent:
- 3:d331c534064f
- Child:
- 5:522612e4b18d
diff -r d331c534064f -r cea8cd2c44e4 main.cpp
--- a/main.cpp Sun Jan 31 01:26:23 2016 +0000
+++ b/main.cpp Sun Jan 31 02:50:56 2016 +0000
@@ -3,18 +3,31 @@
#include "NeoStrip.h"
#include "gt.h"
-#define N 64
+#define NUM_INDIVIDUALS 7
+#define NUM_RING 16
+#define NUM_GRID 40
+#define NUM_ROWS 5
+#define NUM_COLUMNS 8
SerialDriver rpi(p9, p10);
SerialDriver pc(USBTX, USBRX);
DigitalOut myled(LED1);
-NeoStrip strip(p18, N);
+NeoStrip strip(p18, NUM_INDIVIDUALS + NUM_RING + NUM_GRID);
+Ticker t;
+
+int ring_position = 0;
+int grid_col = 0;
int flash();
-void set_pattern(NeoStrip strip);
+void set_pattern(NeoStrip strip, uint8_t r, uint8_t g, uint8_t b);
+void update_pixels();
int main() {
- pc.printf("MBED: startup\n");
+ pc.printf("MBED: startup\r\n");
+
+ set_pattern(strip, 255, 255, 255);
+
+ t.attach(&update_pixels, 0.05);
// setup serial port
rpi.baud(115200);
@@ -25,19 +38,23 @@
int pos = 0;
while (c != '\n' && c != '\r') {
+ pc.printf("MBED: read %c\r\n", c);
line_buffer[pos] = c;
c = rpi.getc();
pos++;
}
line_buffer[pos] = '\0';
+ pc.printf("MBED: read newline\r\n");
rpi.printf("ack\n");
+ pc.printf("MBED: sent ack\r\n");
int result = strcmp(line_buffer, "hello");
if (result == 0) {
- set_pattern(strip);
+ pc.printf("MBED: matched, updating strip\r\n");
+ set_pattern(strip, 255, 0, 0);
} else {
pc.printf("Did not match.\n");
pc.printf(line_buffer);
@@ -54,8 +71,31 @@
}
}
-void set_pattern(NeoStrip strip) {
- strip.setBrightness(0.2);
- strip.setPixels(0, N, gt_img);
+void set_pattern(NeoStrip strip, uint8_t r, uint8_t g, uint8_t b) {
+ strip.setBrightness(0.05);
+ //strip.setPixels(0, N, gt_img);
+ for (int p = 0; p < 64; p++) {
+ strip.setPixel(p, r, g, b);
+ }
strip.write();
+}
+
+void update_pixels() {
+ strip.setBrightness(0.05);
+ // update ring
+ strip.setPixel(NUM_INDIVIDUALS + ring_position, 255, 255, 255);
+ ring_position = (ring_position + 1) % NUM_RING;
+ strip.setPixel(NUM_INDIVIDUALS + ring_position, 255, 0, 0);
+
+ // update grid
+ for (int i = grid_col; i < NUM_GRID; i += NUM_COLUMNS) {
+ strip.setPixel(NUM_INDIVIDUALS + NUM_RING + i, 255, 255, 255);
+ }
+ grid_col = (grid_col + 1) % NUM_COLUMNS;
+
+ for (int i = grid_col; i < NUM_GRID; i += NUM_COLUMNS) {
+ strip.setPixel(NUM_INDIVIDUALS + NUM_RING + i, 255, 0, 0);
+ }
+
+ strip.write();
}
\ No newline at end of file