Ross Gardiner / Mbed 2 deprecated PiballNeoController

Dependencies:   NeoStrip SerialDriver mbed-rtos mbed

Committer:
rossng
Date:
Sun Jan 31 01:26:23 2016 +0000
Revision:
3:d331c534064f
Parent:
2:868c8a43e4b7
Child:
4:cea8cd2c44e4
Remove extraneous set_pattern call

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rossng 0:0513e7187b87 1 #include "mbed.h"
rossng 0:0513e7187b87 2 #include "SerialDriver.h"
rossng 2:868c8a43e4b7 3 #include "NeoStrip.h"
rossng 2:868c8a43e4b7 4 #include "gt.h"
rossng 0:0513e7187b87 5
rossng 2:868c8a43e4b7 6 #define N 64
rossng 2:868c8a43e4b7 7
rossng 1:6feb61c0e4a1 8 SerialDriver rpi(p9, p10);
rossng 1:6feb61c0e4a1 9 SerialDriver pc(USBTX, USBRX);
rossng 0:0513e7187b87 10 DigitalOut myled(LED1);
rossng 2:868c8a43e4b7 11 NeoStrip strip(p18, N);
rossng 0:0513e7187b87 12
rossng 0:0513e7187b87 13 int flash();
rossng 2:868c8a43e4b7 14 void set_pattern(NeoStrip strip);
rossng 0:0513e7187b87 15
rossng 2:868c8a43e4b7 16 int main() {
rossng 2:868c8a43e4b7 17 pc.printf("MBED: startup\n");
rossng 2:868c8a43e4b7 18
rossng 0:0513e7187b87 19 // setup serial port
rossng 1:6feb61c0e4a1 20 rpi.baud(115200);
rossng 0:0513e7187b87 21
rossng 0:0513e7187b87 22 char* line_buffer = (char*) malloc(100*sizeof(char));
rossng 0:0513e7187b87 23
rossng 1:6feb61c0e4a1 24 char c = rpi.getc();
rossng 0:0513e7187b87 25 int pos = 0;
rossng 0:0513e7187b87 26
rossng 0:0513e7187b87 27 while (c != '\n' && c != '\r') {
rossng 0:0513e7187b87 28 line_buffer[pos] = c;
rossng 1:6feb61c0e4a1 29 c = rpi.getc();
rossng 1:6feb61c0e4a1 30 pos++;
rossng 0:0513e7187b87 31 }
rossng 0:0513e7187b87 32
rossng 1:6feb61c0e4a1 33 line_buffer[pos] = '\0';
rossng 1:6feb61c0e4a1 34
rossng 1:6feb61c0e4a1 35 rpi.printf("ack\n");
rossng 0:0513e7187b87 36
rossng 0:0513e7187b87 37 int result = strcmp(line_buffer, "hello");
rossng 0:0513e7187b87 38
rossng 0:0513e7187b87 39 if (result == 0) {
rossng 2:868c8a43e4b7 40 set_pattern(strip);
rossng 1:6feb61c0e4a1 41 } else {
rossng 1:6feb61c0e4a1 42 pc.printf("Did not match.\n");
rossng 1:6feb61c0e4a1 43 pc.printf(line_buffer);
rossng 0:0513e7187b87 44 }
rossng 0:0513e7187b87 45 }
rossng 0:0513e7187b87 46
rossng 0:0513e7187b87 47
rossng 0:0513e7187b87 48 int flash() {
rossng 0:0513e7187b87 49 while(1) {
rossng 0:0513e7187b87 50 myled = 1;
rossng 0:0513e7187b87 51 wait(0.2);
rossng 0:0513e7187b87 52 myled = 0;
rossng 0:0513e7187b87 53 wait(0.2);
rossng 0:0513e7187b87 54 }
rossng 2:868c8a43e4b7 55 }
rossng 2:868c8a43e4b7 56
rossng 2:868c8a43e4b7 57 void set_pattern(NeoStrip strip) {
rossng 2:868c8a43e4b7 58 strip.setBrightness(0.2);
rossng 2:868c8a43e4b7 59 strip.setPixels(0, N, gt_img);
rossng 2:868c8a43e4b7 60 strip.write();
rossng 0:0513e7187b87 61 }