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
main.cpp
- Committer:
- rossng
- Date:
- 2016-01-31
- Revision:
- 4:cea8cd2c44e4
- Parent:
- 3:d331c534064f
- Child:
- 5:522612e4b18d
File content as of revision 4:cea8cd2c44e4:
#include "mbed.h"
#include "SerialDriver.h"
#include "NeoStrip.h"
#include "gt.h"
#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, NUM_INDIVIDUALS + NUM_RING + NUM_GRID);
Ticker t;
int ring_position = 0;
int grid_col = 0;
int flash();
void set_pattern(NeoStrip strip, uint8_t r, uint8_t g, uint8_t b);
void update_pixels();
int main() {
pc.printf("MBED: startup\r\n");
set_pattern(strip, 255, 255, 255);
t.attach(&update_pixels, 0.05);
// setup serial port
rpi.baud(115200);
char* line_buffer = (char*) malloc(100*sizeof(char));
char c = rpi.getc();
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) {
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);
}
}
int flash() {
while(1) {
myled = 1;
wait(0.2);
myled = 0;
wait(0.2);
}
}
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();
}